Beispiel #1
0
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")
Beispiel #2
0
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))
Beispiel #3
0
def wrap_u64(vt, val):
    if vt == ValTypeI32:
        return int32(val)
    elif vt == ValTypeI64:
        return int64(val)
    elif vt == ValTypeF32:
        cov_val = struct.unpack('>f', struct.pack('>l', int64(val)))[0]
        if math.isnan(cov_val):
            return float32(val)
        else:
            return float32(cov_val)
    elif vt == ValTypeF64:
        cov_val = struct.unpack('>d', struct.pack('>q', int64(val)))[0]
        if math.isnan(cov_val):
            return float64(val)
        else:
            return float64(cov_val)
    else:
        raise Exception("unreachable")
Beispiel #4
0
def i64_load_32s(vm, mem_arg):
    val = read_u32(vm, mem_arg)
    vm.push_s64(int64(int32(val)))
Beispiel #5
0
def i32_load_16s(vm, mem_arg):
    val = read_u16(vm, mem_arg)
    vm.push_s32(int32(int16(val)))
Beispiel #6
0
def i32_load_8s(vm, mem_arg):
    val = read_u8(vm, mem_arg)
    vm.push_u32(int32(int8(val)))
Beispiel #7
0
def i32_const(vm, args):
    vm.push_s32(int32(args))
Beispiel #8
0
def i64_extend_32s(vm, _):
    vm.push_s64(int64(int32(vm.pop_s64())))
Beispiel #9
0
def i32_extend_16s(vm, _):
    vm.push_s32(int32(int16(vm.pop_s32())))
Beispiel #10
0
def i32_extend_8s(vm, _):
    vm.push_s32(int32(int8(vm.pop_s32())))
Beispiel #11
0
 def pop_s32(self):
     return int32(self.pop_numeric())