Esempio n. 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")
Esempio n. 2
0
def i32_trunc_f64u(vm, _):
    f = math.trunc(vm.pop_f64())
    if f > __MaxUint32 or f < 0:
        raise ErrIntOverflow
    if math.isnan(f):
        raise ErrConvertToInt
    vm.push_u32(uint32(f))
Esempio n. 3
0
def call(vm, args):
    idx = uint32(args)
    name = vm.module.import_sec[idx].name
    if name == 'assert_true':
        __assert_equal(vm.pop_bool(), True)
    elif name == 'assert_false':
        __assert_equal(vm.pop_bool(), False)
    elif name == 'assert_eq_i32':
        __assert_equal(vm.pop_u32(), vm.pop_u32())
    elif name == 'assert_eq_i64':
        __assert_equal(vm.pop_u64(), vm.pop_u64())
    elif name == 'assert_eq_f32':
        __assert_equal(vm.pop_f32(), vm.pop_f32())
    elif name == 'assert_eq_f64':
        __assert_equal(vm.pop_f64(), vm.pop_f64())
    else:
        raise Exception("TODO")
Esempio n. 4
0
 def push_s32(self, val):
     self.push_u64(uint32(val))
Esempio n. 5
0
 def pop_u32(self) -> uint32:
     return uint32(self.pop_u64())
Esempio n. 6
0
def i32_pop_cnt(vm, _):
    """统计1比特数"""
    vm.push_u32(uint32(__ones_count32(vm.pop_u32())))
Esempio n. 7
0
def i32_ctz(vm, _):
    """统计后置0比特数"""
    vm.push_u32(uint32(__trailing_zeros32(vm.pop_u32())))
Esempio n. 8
0
def i32_clz(vm, _):
    """统计前置0比特数"""
    vm.push_u32(uint32(__leading_zeros32(vm.pop_u32())))
Esempio n. 9
0
def i32_wrap_i64(vm, _):
    vm.push_u32(uint32(vm.pop_u64()))