def wrap_u64(vt, val): if vt == ValTypeI32: return int32(val) elif vt == ValTypeI64: return int64(val) elif vt == ValTypeF32: val = struct.unpack('>f', struct.pack('>l', int64(val)))[0] return float32(val) elif vt == ValTypeF64: val = struct.unpack('>d', struct.pack('>q', int64(val)))[0] return float64(val) else: raise Exception("unreachable")
def __trunc_sat_s(z, n): if math.isnan(z): return 0 min_value = -(int64(1) << (n - 1)) max_value = (int64(1) << (n - 1)) - 1 if z == -math.inf: return min_value if math.isinf(z): return max_value x = math.trunc(z) if x < float64(min_value): return min_value elif x >= float64(max_value): return max_value else: return int64(x)
def i64_trunc_f64s(vm, _): f = math.trunc(vm.pop_f64()) if f >= __MaxInt64 or f < __MinInt64: raise ErrIntOverflow if math.isnan(f): raise ErrConvertToInt vm.push_s64(int64(f))
def i64_const(vm, args): vm.push_s64(int64(args))
def i64_extend_32s(vm, _): vm.push_s64(int64(int32(vm.pop_s64())))
def i64_extend_16s(vm, _): vm.push_s64(int64(int16(vm.pop_s64())))
def i64_extend_8s(vm, _): vm.push_s64(int64(int8(vm.pop_s64())))
def i64_extend_i32s(vm, _): vm.push_s64(int64(vm.pop_s32()))
def pop_s64(self) -> int64: return int64(self.pop_numeric())
def i64_load_32s(vm, mem_arg): val = read_u32(vm, mem_arg) vm.push_s64(int64(int32(val)))
def i64_load_16s(vm, mem_arg): val = read_u16(vm, mem_arg) vm.push_s64(int64(int16(val)))
def i64_load_8s(vm, mem_arg): val = read_u8(vm, mem_arg) vm.push_s64(int64(int8(val)))