def trunc_sat(vm, args): if args == 0: # i32.trunc_sat_f32_s v = __trunc_sat_s(vm.pop_f32(), 32) vm.push_s32(int32(v)) elif args == 1: # i32.trunc_sat_f32_u v = __trunc_sat_u(vm.pop_f32(), 32) vm.push_u32(uint32(v)) elif args == 2: # i32.trunc_sat_f64_s v = __trunc_sat_s(vm.pop_f64(), 32) vm.push_s32(int32(v)) elif args == 3: # i32.trunc_sat_f64_u v = __trunc_sat_u(vm.pop_f64(), 32) vm.push_u32(uint32(v)) elif args == 4: # i64.trunc_sat_f32_s v = __trunc_sat_s(vm.pop_f32(), 64) vm.push_s64(v) elif args == 5: # i64.trunc_sat_f32_u v = __trunc_sat_u(vm.pop_f32(), 64) vm.push_u64(v) elif args == 6: # i64.trunc_sat_f64_s v = __trunc_sat_s(vm.pop_f64(), 64) vm.push_s64(v) elif args == 7: # i64.trunc_sat_f64_u v = __trunc_sat_u(vm.pop_f64(), 64) vm.push_u64(v) else: raise Exception("unreachable")
def i32_trunc_f64s(vm, _): f = math.trunc(vm.pop_f64()) if f > __MaxInt32 or f < __MinInt32: raise ErrIntOverflow if math.isnan(f): raise ErrConvertToInt vm.push_s32(int32(f))
def i64_load_32s(vm, mem_arg): val = read_u32(vm, mem_arg) vm.push_s64(int64(int32(val)))
def i32_load_16s(vm, mem_arg): val = read_u16(vm, mem_arg) vm.push_s32(int32(int16(val)))
def i32_load_8s(vm, mem_arg): val = read_u8(vm, mem_arg) vm.push_u32(int32(int8(val)))
def i32_const(vm, args): vm.push_s32(int32(args))
def i64_extend_32s(vm, _): vm.push_s64(int64(int32(vm.pop_s64())))
def i32_extend_16s(vm, _): vm.push_s32(int32(int16(vm.pop_s32())))
def i32_extend_8s(vm, _): vm.push_s32(int32(int8(vm.pop_s32())))
def pop_s32(self): return int32(self.pop_numeric())