mirror of
https://github.com/fluencelabs/wasmer
synced 2025-06-28 08:01:33 +00:00
feat(interface-types) string.size
pops the string.
Previously, `string.size` was just peeking the string.
This commit is contained in:
@ -78,7 +78,11 @@ executable_instruction!(
|
|||||||
)
|
)
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let string: String = to_native(&inputs[0], instruction)?;
|
let string_pointer: usize = to_native::<i32>(&inputs[0], instruction)?
|
||||||
|
.try_into()
|
||||||
|
.map_err(|e| (e, "pointer").into())
|
||||||
|
.map_err(|k| InstructionError::new(instruction, k))?;
|
||||||
|
let string: String = to_native(&inputs[1], instruction)?;
|
||||||
let string_bytes = string.as_bytes();
|
let string_bytes = string.as_bytes();
|
||||||
let string_length: i32 = string_bytes.len().try_into().map_err(|_| {
|
let string_length: i32 = string_bytes.len().try_into().map_err(|_| {
|
||||||
InstructionError::new(
|
InstructionError::new(
|
||||||
@ -86,10 +90,6 @@ executable_instruction!(
|
|||||||
InstructionErrorKind::NegativeValue { subject: "string_length" },
|
InstructionErrorKind::NegativeValue { subject: "string_length" },
|
||||||
)
|
)
|
||||||
})?;
|
})?;
|
||||||
let string_pointer: usize = to_native::<i32>(&inputs[1], instruction)?
|
|
||||||
.try_into()
|
|
||||||
.map_err(|e| (e, "pointer").into())
|
|
||||||
.map_err(|k| InstructionError::new(instruction, k))?;
|
|
||||||
|
|
||||||
let instance = &mut runtime.wasm_instance;
|
let instance = &mut runtime.wasm_instance;
|
||||||
let memory_index: u32 = 0;
|
let memory_index: u32 = 0;
|
||||||
@ -118,7 +118,7 @@ executable_instruction!(
|
|||||||
executable_instruction!(
|
executable_instruction!(
|
||||||
string_size(instruction: Instruction) -> _ {
|
string_size(instruction: Instruction) -> _ {
|
||||||
move |runtime| -> _ {
|
move |runtime| -> _ {
|
||||||
match runtime.stack.peek1() {
|
match runtime.stack.pop1() {
|
||||||
Some(InterfaceValue::String(string)) => {
|
Some(InterfaceValue::String(string)) => {
|
||||||
let length = string.len() as i32;
|
let length = string.len() as i32;
|
||||||
runtime.stack.push(InterfaceValue::I32(length));
|
runtime.stack.push(InterfaceValue::I32(length));
|
||||||
@ -130,7 +130,7 @@ executable_instruction!(
|
|||||||
instruction,
|
instruction,
|
||||||
InstructionErrorKind::InvalidValueOnTheStack {
|
InstructionErrorKind::InvalidValueOnTheStack {
|
||||||
expected_type: InterfaceType::String,
|
expected_type: InterfaceType::String,
|
||||||
received_type: value.into(),
|
received_type: (&value).into(),
|
||||||
},
|
},
|
||||||
)),
|
)),
|
||||||
|
|
||||||
@ -280,6 +280,7 @@ mod tests {
|
|||||||
Instruction::ArgumentGet { index: 0 },
|
Instruction::ArgumentGet { index: 0 },
|
||||||
Instruction::StringSize,
|
Instruction::StringSize,
|
||||||
Instruction::CallCore { function_index: 43 },
|
Instruction::CallCore { function_index: 43 },
|
||||||
|
Instruction::ArgumentGet { index: 0 },
|
||||||
Instruction::StringLowerMemory,
|
Instruction::StringLowerMemory,
|
||||||
|
|
||||||
],
|
],
|
||||||
@ -299,6 +300,7 @@ mod tests {
|
|||||||
Instruction::ArgumentGet { index: 0 },
|
Instruction::ArgumentGet { index: 0 },
|
||||||
Instruction::StringSize,
|
Instruction::StringSize,
|
||||||
Instruction::CallCore { function_index: 43 },
|
Instruction::CallCore { function_index: 43 },
|
||||||
|
Instruction::ArgumentGet { index: 0 },
|
||||||
Instruction::StringLowerMemory,
|
Instruction::StringLowerMemory,
|
||||||
Instruction::StringLiftMemory,
|
Instruction::StringLiftMemory,
|
||||||
],
|
],
|
||||||
@ -325,7 +327,7 @@ mod tests {
|
|||||||
],
|
],
|
||||||
invocation_inputs: [InterfaceValue::String("Hello, World!".into())],
|
invocation_inputs: [InterfaceValue::String("Hello, World!".into())],
|
||||||
instance: Instance::new(),
|
instance: Instance::new(),
|
||||||
stack: [InterfaceValue::String("Hello, World!".into()), InterfaceValue::I32(13)],
|
stack: [InterfaceValue::I32(13)],
|
||||||
);
|
);
|
||||||
|
|
||||||
test_executable_instruction!(
|
test_executable_instruction!(
|
||||||
|
Reference in New Issue
Block a user