def decode_var_int(data, size): """ LEB128有符号整数解码 :param data: 解码后的整数 :param size: 实际消耗的字节数 :return: """ result = 0 for i, b in enumerate(data): if i == int(size / 7): if b & 0x80 != 0: raise ErrIntTooLong if b & 0x40 == 0 and b >> (size - i * 7 - 1) != 0 or \ b & 0x40 != 0 and int8(b | 0x80) >> (size - i * 7 - 1) != -1: raise ErrIntTooLarge result |= (b & 0x7f) << (i * 7) if b & 0x80 == 0: if (i * 7 < size) and (b & 0x40 != 0): result |= -1 << ((i + 1) * 7) return result, i + 1 raise ErrUnexpectedEnd
def i64_load_8s(vm, mem_arg): val = read_u8(vm, mem_arg) vm.push_s64(int64(int8(val)))
def i32_load_8s(vm, mem_arg): val = read_u8(vm, mem_arg) vm.push_u32(int32(int8(val)))
def i64_extend_8s(vm, _): vm.push_s64(int64(int8(vm.pop_s64())))
def i32_extend_8s(vm, _): vm.push_s32(int32(int8(vm.pop_s32())))