mirror of
https://github.com/fluencelabs/parity-wasm
synced 2025-06-27 13:41:58 +00:00
plain instruction set draft
This commit is contained in:
@ -82,7 +82,6 @@ fn wrong_import() {
|
||||
fn global_get_set() {
|
||||
let module = module()
|
||||
.with_global(GlobalEntry::new(GlobalType::new(ValueType::I32, true), InitExpr::new(vec![Opcode::I32Const(42)])))
|
||||
.with_global(GlobalEntry::new(GlobalType::new(ValueType::I32, false), InitExpr::new(vec![Opcode::I32Const(777)])))
|
||||
.function()
|
||||
.signature().return_type().i32().build()
|
||||
.body().with_opcodes(Opcodes::new(vec![
|
||||
@ -94,33 +93,11 @@ fn global_get_set() {
|
||||
Opcode::End,
|
||||
])).build()
|
||||
.build()
|
||||
.function()
|
||||
.signature().return_type().i32().build()
|
||||
.body().with_opcodes(Opcodes::new(vec![
|
||||
Opcode::GetGlobal(1),
|
||||
Opcode::I32Const(8),
|
||||
Opcode::I32Add,
|
||||
Opcode::SetGlobal(1),
|
||||
Opcode::GetGlobal(1),
|
||||
Opcode::End,
|
||||
])).build()
|
||||
.build()
|
||||
.function()
|
||||
.signature().return_type().i32().build()
|
||||
.body().with_opcodes(Opcodes::new(vec![
|
||||
Opcode::I64Const(8),
|
||||
Opcode::SetGlobal(0),
|
||||
Opcode::GetGlobal(0),
|
||||
Opcode::End,
|
||||
])).build()
|
||||
.build()
|
||||
.build();
|
||||
|
||||
let program = ProgramInstance::new().unwrap();
|
||||
let module = program.add_module_without_validation("main", module, None).unwrap(); // validation is failing (accessing immutable global)
|
||||
let module = program.add_module("main", module, None).unwrap();
|
||||
assert_eq!(module.execute_index(0, vec![].into()).unwrap().unwrap(), RuntimeValue::I32(50));
|
||||
assert_eq!(module.execute_index(1, vec![].into()).unwrap_err(), Error::Variable("trying to update immutable variable".into()));
|
||||
assert_eq!(module.execute_index(2, vec![].into()).unwrap_err(), Error::Variable("trying to update variable of type I32 with value of type Some(I64)".into()));
|
||||
}
|
||||
|
||||
const SIGNATURE_I32: &'static [ValueType] = &[ValueType::I32];
|
||||
@ -255,17 +232,15 @@ fn if_else_with_return_type_validation() {
|
||||
|
||||
Validator::validate_function(&mut context, BlockType::NoResult, &[
|
||||
Opcode::I32Const(1),
|
||||
Opcode::If(BlockType::NoResult, Opcodes::new(vec![
|
||||
Opcode::If(BlockType::NoResult),
|
||||
Opcode::I32Const(1),
|
||||
Opcode::If(BlockType::Value(ValueType::I32), Opcodes::new(vec![
|
||||
Opcode::If(BlockType::Value(ValueType::I32)),
|
||||
Opcode::I32Const(1),
|
||||
Opcode::Else,
|
||||
Opcode::Else,
|
||||
Opcode::I32Const(2),
|
||||
Opcode::End,
|
||||
])),
|
||||
Opcode::Drop,
|
||||
Opcode::End,
|
||||
])),
|
||||
Opcode::Drop,
|
||||
Opcode::End,
|
||||
Opcode::End,
|
||||
]).unwrap();
|
||||
}
|
||||
|
Reference in New Issue
Block a user