Example #1
0
 def test_const_ops(self):
     vm = VM()
     i32_const(vm, int32(100))
     i64_const(vm, int64(200))
     f32_const(vm, float32(1.5))
     f64_const(vm, 2.5)
     self.assertEqual(2.5, vm.pop_f64())
     self.assertEqual(float32(1.5), vm.pop_f32())
     self.assertEqual(int64(200), vm.pop_s64())
     self.assertEqual(int32(100), vm.pop_s32())
Example #2
0
 def f32_bin_op(self, opcode, a, b, c):
     self.bin_op(opcode, float32(a), float32(b), float32(c))
Example #3
0
 def f32_un_op(self, opcode, b, c):
     self.f32_bin_op(opcode, 0, float32(b), float32(c))
Example #4
0
 def test_conversions(self):
     self.un_op(I32WrapI64, int64(0x7F7F_7F7F_7F7F_7F7F),
                int32(0x7F7F_7F7F))
     self.un_op(I32TruncF32S, float32(-1.5), int32(-1))
     self.un_op(I32TruncF32U, float32(1.5), int32(1))  # TODO
     self.un_op(I32TruncF64S, -1.5, int32(-1))
     self.un_op(I32TruncF64U, 1.5, int32(1))  # TODO
     self.un_op(I64ExtendI32S, int32(-1), int64(-1))
     self.un_op(I64ExtendI32U, int32(-1), int64(0xFFFF_FFFF))
     self.un_op(I64TruncF32S, float32(-1.5), int64(-1))
     self.un_op(I64TruncF32U, float32(1.5), int64(1))  # TODO
     self.un_op(I64TruncF64S, -1.5, int64(-1))
     self.un_op(I64TruncF64U, 1.5, int64(1))  # TODO
     self.un_op(F32ConvertI32S, int32(-1), float32(-1.0))
     self.un_op(F32ConvertI32U, int32(-1), float32(4.2949673e+09))
     self.un_op(F32ConvertI64S, int64(-1), float32(-1.0))
     self.un_op(F32ConvertI64U, int64(-1), float32(1.8446744e+19))
     self.un_op(F32DemoteF64, 1.5, float32(1.5))
     self.un_op(F64ConvertI32S, int32(-1), -1.0)
     self.un_op(F64ConvertI32U, int32(-1), 4.294967295e+09)
     self.un_op(F64ConvertI64S, int64(-1), -1.0)
     self.un_op(F64ConvertI64U, int64(-1), 1.8446744073709552e+19)
     self.un_op(F64PromoteF32, float32(1.5), 1.5)
     self.un_op(I32ReinterpretF32, float32(1.5), int32(0x3FC0_0000))
     self.un_op(I64ReinterpretF64, 1.5, int64(0x3FF8_0000_0000_0000))
     self.un_op(F32ReinterpretI32, int32(0x3FC0_0000), float32(1.5))
     self.un_op(F64ReinterpretI64, int64(0x3FF8_0000_0000_0000), 1.5)