Ejemplo n.º 1
0
def unwrap_u64(vt, val):
    if vt == ValTypeI32:
        return uint64(val)
    elif vt == ValTypeI64:
        return uint64(val)
    elif vt == ValTypeF32:
        return uint64(val)
    elif vt == ValTypeF64:
        return uint64(val)
    else:
        raise Exception("unreachable")
Ejemplo n.º 2
0
def __trunc_sat_u(z, n):
    if math.isnan(z):
        return 0
    if z == -math.inf:
        return 0
    max_value = (uint64(1) << n) - 1
    if math.isinf(z):
        return max_value
    x = math.trunc(z)
    if x < 0:
        return 0
    elif x >= float64(max_value):
        return max_value
    else:
        return uint64(x)
Ejemplo n.º 3
0
def i64_trunc_f64u(vm, _):
    f = math.trunc(vm.pop_f64())
    if f >= __MaxUint64 or f < 0:
        raise ErrIntOverflow
    if math.isnan(f):
        raise ErrConvertToInt
    vm.push_u64(uint64(f))
Ejemplo n.º 4
0
def i64_clz(vm, _):
    vm.push_u64(uint64(__leading_zeros64(vm.pop_u64())))
Ejemplo n.º 5
0
def i64_pop_cnt(vm, _):
    vm.push_u64(uint64(__ones_count64(vm.pop_u64())))
Ejemplo n.º 6
0
def i64_extend_i32u(vm, _):
    vm.push_u64(uint64(vm.pop_u32()))
Ejemplo n.º 7
0
 def push_u32(self, val):
     self.push_numeric(uint64(val))
Ejemplo n.º 8
0
def i64_ctz(vm, _):
    vm.push_u64(uint64(__trailing_zeros64(vm.pop_u64())))
Ejemplo n.º 9
0
 def push_u64(self, val):
     self.slots.append(uint64(val))
Ejemplo n.º 10
0
 def pop_u64(self) -> uint64:
     return uint64(self.slots.pop())
Ejemplo n.º 11
0
def i64_load_32u(vm, mem_arg):
    val = read_u32(vm, mem_arg)
    vm.push_u64(uint64(val))
Ejemplo n.º 12
0
def i64_load_16u(vm, mem_arg):
    val = read_u16(vm, mem_arg)
    vm.push_u64(uint64(val))
Ejemplo n.º 13
0
def i64_load_8u(vm, mem_arg):
    val = read_u8(vm, mem_arg)
    vm.push_u64(uint64(val))
Ejemplo n.º 14
0
def get_offset(vm, mem_arg):
    offset = mem_arg.offset
    return uint64(vm.pop_u32()) + uint64(offset)
Ejemplo n.º 15
0
def read_u64(vm, mem_arg):
    buf = [0x00] * 8
    offset = get_offset(vm, mem_arg)
    buf = vm.memory.read(offset, buf)
    return uint64(int.from_bytes(bytearray(buf), byteorder='little'))