compare_i32

This commit is contained in:
Svyatoslav Nikolsky 2017-05-02 10:10:42 +03:00
parent 712b52f1dd
commit 1c37f78aa7

View File

@ -1381,4 +1381,294 @@ fn cast() {
assert_eq!(module.execute(1, vec![]).unwrap().unwrap(), RuntimeValue::I32(-1067450368)); // 3227516928
assert_eq!(module.execute(2, vec![]).unwrap().unwrap(), RuntimeValue::F64(125.125000));
assert_eq!(module.execute(3, vec![]).unwrap().unwrap(), RuntimeValue::I64(4758506566875873280));
}
/// https://github.com/WebAssembly/wabt/blob/8e1f6031e9889ba770c7be4a9b084da5f14456a0/test/interp/compare.txt#L3
#[test]
fn compare_i32() {
let module = module()
.function()
.signature().return_type().i32().build()
.body().with_opcodes(Opcodes::new(vec![
Opcode::I32Const(-1),
Opcode::I32Const(-1),
Opcode::I32Eq,
Opcode::End,
])).build()
.build()
.function()
.signature().return_type().i32().build()
.body().with_opcodes(Opcodes::new(vec![
Opcode::I32Const(1),
Opcode::I32Const(-1),
Opcode::I32Eq,
Opcode::End,
])).build()
.build()
.function()
.signature().return_type().i32().build()
.body().with_opcodes(Opcodes::new(vec![
Opcode::I32Const(1),
Opcode::I32Const(-1),
Opcode::I32Ne,
Opcode::End,
])).build()
.build()
.function()
.signature().return_type().i32().build()
.body().with_opcodes(Opcodes::new(vec![
Opcode::I32Const(-1),
Opcode::I32Const(-1),
Opcode::I32Ne,
Opcode::End,
])).build()
.build()
.function()
.signature().return_type().i32().build()
.body().with_opcodes(Opcodes::new(vec![
Opcode::I32Const(-1),
Opcode::I32Const(1),
Opcode::I32LtS,
Opcode::End,
])).build()
.build()
.function()
.signature().return_type().i32().build()
.body().with_opcodes(Opcodes::new(vec![
Opcode::I32Const(-1),
Opcode::I32Const(-1),
Opcode::I32LtS,
Opcode::End,
])).build()
.build()
.function()
.signature().return_type().i32().build()
.body().with_opcodes(Opcodes::new(vec![
Opcode::I32Const(1),
Opcode::I32Const(-1),
Opcode::I32LtS,
Opcode::End,
])).build()
.build()
.function()
.signature().return_type().i32().build()
.body().with_opcodes(Opcodes::new(vec![
Opcode::I32Const(1),
Opcode::I32Const(-1),
Opcode::I32LtU,
Opcode::End,
])).build()
.build()
.function()
.signature().return_type().i32().build()
.body().with_opcodes(Opcodes::new(vec![
Opcode::I32Const(1),
Opcode::I32Const(1),
Opcode::I32LtU,
Opcode::End,
])).build()
.build()
.function()
.signature().return_type().i32().build()
.body().with_opcodes(Opcodes::new(vec![
Opcode::I32Const(-1),
Opcode::I32Const(1),
Opcode::I32LtU,
Opcode::End,
])).build()
.build()
.function()
.signature().return_type().i32().build()
.body().with_opcodes(Opcodes::new(vec![
Opcode::I32Const(-1),
Opcode::I32Const(1),
Opcode::I32LeS,
Opcode::End,
])).build()
.build()
.function()
.signature().return_type().i32().build()
.body().with_opcodes(Opcodes::new(vec![
Opcode::I32Const(-1),
Opcode::I32Const(-1),
Opcode::I32LeS,
Opcode::End,
])).build()
.build()
.function()
.signature().return_type().i32().build()
.body().with_opcodes(Opcodes::new(vec![
Opcode::I32Const(1),
Opcode::I32Const(-1),
Opcode::I32LeS,
Opcode::End,
])).build()
.build()
.function()
.signature().return_type().i32().build()
.body().with_opcodes(Opcodes::new(vec![
Opcode::I32Const(1),
Opcode::I32Const(-1),
Opcode::I32LeU,
Opcode::End,
])).build()
.build()
.function()
.signature().return_type().i32().build()
.body().with_opcodes(Opcodes::new(vec![
Opcode::I32Const(1),
Opcode::I32Const(1),
Opcode::I32LeU,
Opcode::End,
])).build()
.build()
.function()
.signature().return_type().i32().build()
.body().with_opcodes(Opcodes::new(vec![
Opcode::I32Const(-1),
Opcode::I32Const(1),
Opcode::I32LeU,
Opcode::End,
])).build()
.build()
.function()
.signature().return_type().i32().build()
.body().with_opcodes(Opcodes::new(vec![
Opcode::I32Const(-1),
Opcode::I32Const(1),
Opcode::I32GtS,
Opcode::End,
])).build()
.build()
.function()
.signature().return_type().i32().build()
.body().with_opcodes(Opcodes::new(vec![
Opcode::I32Const(-1),
Opcode::I32Const(-1),
Opcode::I32GtS,
Opcode::End,
])).build()
.build()
.function()
.signature().return_type().i32().build()
.body().with_opcodes(Opcodes::new(vec![
Opcode::I32Const(1),
Opcode::I32Const(-1),
Opcode::I32GtS,
Opcode::End,
])).build()
.build()
.function()
.signature().return_type().i32().build()
.body().with_opcodes(Opcodes::new(vec![
Opcode::I32Const(1),
Opcode::I32Const(-1),
Opcode::I32GtU,
Opcode::End,
])).build()
.build()
.function()
.signature().return_type().i32().build()
.body().with_opcodes(Opcodes::new(vec![
Opcode::I32Const(1),
Opcode::I32Const(1),
Opcode::I32GtU,
Opcode::End,
])).build()
.build()
.function()
.signature().return_type().i32().build()
.body().with_opcodes(Opcodes::new(vec![
Opcode::I32Const(-1),
Opcode::I32Const(1),
Opcode::I32GtU,
Opcode::End,
])).build()
.build()
.function()
.signature().return_type().i32().build()
.body().with_opcodes(Opcodes::new(vec![
Opcode::I32Const(-1),
Opcode::I32Const(1),
Opcode::I32GeS,
Opcode::End,
])).build()
.build()
.function()
.signature().return_type().i32().build()
.body().with_opcodes(Opcodes::new(vec![
Opcode::I32Const(-1),
Opcode::I32Const(-1),
Opcode::I32GeS,
Opcode::End,
])).build()
.build()
.function()
.signature().return_type().i32().build()
.body().with_opcodes(Opcodes::new(vec![
Opcode::I32Const(1),
Opcode::I32Const(-1),
Opcode::I32GeS,
Opcode::End,
])).build()
.build()
.function()
.signature().return_type().i32().build()
.body().with_opcodes(Opcodes::new(vec![
Opcode::I32Const(1),
Opcode::I32Const(-1),
Opcode::I32GeU,
Opcode::End,
])).build()
.build()
.function()
.signature().return_type().i32().build()
.body().with_opcodes(Opcodes::new(vec![
Opcode::I32Const(1),
Opcode::I32Const(1),
Opcode::I32GeU,
Opcode::End,
])).build()
.build()
.function()
.signature().return_type().i32().build()
.body().with_opcodes(Opcodes::new(vec![
Opcode::I32Const(-1),
Opcode::I32Const(1),
Opcode::I32GeU,
Opcode::End,
])).build()
.build()
.build();
let program = ProgramInstance::new();
let module = program.add_module("main", module).unwrap();
assert_eq!(module.execute(0, vec![]).unwrap().unwrap(), RuntimeValue::I32(1));
assert_eq!(module.execute(1, vec![]).unwrap().unwrap(), RuntimeValue::I32(0));
assert_eq!(module.execute(2, vec![]).unwrap().unwrap(), RuntimeValue::I32(1));
assert_eq!(module.execute(3, vec![]).unwrap().unwrap(), RuntimeValue::I32(0));
assert_eq!(module.execute(4, vec![]).unwrap().unwrap(), RuntimeValue::I32(1));
assert_eq!(module.execute(5, vec![]).unwrap().unwrap(), RuntimeValue::I32(0));
assert_eq!(module.execute(6, vec![]).unwrap().unwrap(), RuntimeValue::I32(0));
assert_eq!(module.execute(7, vec![]).unwrap().unwrap(), RuntimeValue::I32(1));
assert_eq!(module.execute(8, vec![]).unwrap().unwrap(), RuntimeValue::I32(0));
assert_eq!(module.execute(9, vec![]).unwrap().unwrap(), RuntimeValue::I32(0));
assert_eq!(module.execute(10, vec![]).unwrap().unwrap(), RuntimeValue::I32(1));
assert_eq!(module.execute(11, vec![]).unwrap().unwrap(), RuntimeValue::I32(1));
assert_eq!(module.execute(12, vec![]).unwrap().unwrap(), RuntimeValue::I32(0));
assert_eq!(module.execute(13, vec![]).unwrap().unwrap(), RuntimeValue::I32(1));
assert_eq!(module.execute(14, vec![]).unwrap().unwrap(), RuntimeValue::I32(1));
assert_eq!(module.execute(15, vec![]).unwrap().unwrap(), RuntimeValue::I32(0));
assert_eq!(module.execute(16, vec![]).unwrap().unwrap(), RuntimeValue::I32(0));
assert_eq!(module.execute(17, vec![]).unwrap().unwrap(), RuntimeValue::I32(0));
assert_eq!(module.execute(18, vec![]).unwrap().unwrap(), RuntimeValue::I32(1));
assert_eq!(module.execute(19, vec![]).unwrap().unwrap(), RuntimeValue::I32(0));
assert_eq!(module.execute(20, vec![]).unwrap().unwrap(), RuntimeValue::I32(0));
assert_eq!(module.execute(21, vec![]).unwrap().unwrap(), RuntimeValue::I32(1));
assert_eq!(module.execute(22, vec![]).unwrap().unwrap(), RuntimeValue::I32(0));
assert_eq!(module.execute(23, vec![]).unwrap().unwrap(), RuntimeValue::I32(1));
assert_eq!(module.execute(24, vec![]).unwrap().unwrap(), RuntimeValue::I32(1));
assert_eq!(module.execute(25, vec![]).unwrap().unwrap(), RuntimeValue::I32(0));
assert_eq!(module.execute(26, vec![]).unwrap().unwrap(), RuntimeValue::I32(1));
assert_eq!(module.execute(27, vec![]).unwrap().unwrap(), RuntimeValue::I32(1));
}