Byte code for SMALL_INT uses 3 bytes for integer.
This commit is contained in:
parent
0c70f88734
commit
6addc89e55
@ -106,11 +106,12 @@ static void emit_write_byte_1_byte(emit_t* emit, byte b1, uint b2) {
|
||||
}
|
||||
|
||||
static void emit_write_byte_1_int(emit_t* emit, byte b1, int num) {
|
||||
assert((num & (~0x7fff)) == 0 || (num & (~0x7fff)) == (~0x7fff));
|
||||
byte* c = emit_get_cur_to_write_bytes(emit, 3);
|
||||
assert((num & (~0x7fffff)) == 0 || (num & (~0x7fffff)) == (~0x7fffff));
|
||||
byte* c = emit_get_cur_to_write_bytes(emit, 4);
|
||||
c[0] = b1;
|
||||
c[1] = num;
|
||||
c[2] = num >> 8;
|
||||
c[3] = num >> 16;
|
||||
}
|
||||
|
||||
static void emit_write_byte_1_uint(emit_t* emit, byte b1, uint num) {
|
||||
@ -186,8 +187,8 @@ static void emit_bc_label_assign(emit_t *emit, int l) {
|
||||
emit->label_offsets[l] = emit->code_offset;
|
||||
} else if (emit->pass == PASS_3) {
|
||||
// ensure label offset has not changed from PASS_2 to PASS_3
|
||||
//printf("l%d: (at %d vs %d)\n", l, emit->code_offset, emit->label_offsets[l]);
|
||||
assert(emit->label_offsets[l] == emit->code_offset);
|
||||
//printf("l%d: (at %d)\n", l, emit->code_offset);
|
||||
}
|
||||
}
|
||||
|
||||
|
9
py/vm.c
9
py/vm.c
@ -75,11 +75,11 @@ bool py_execute_byte_code_2(const byte *code, const byte **ip_in_out, py_obj_t *
|
||||
break;
|
||||
|
||||
case PYBC_LOAD_CONST_SMALL_INT:
|
||||
snum = ip[0] | (ip[1] << 8);
|
||||
snum = ip[0] | (ip[1] << 8) | (ip[2] << 16);
|
||||
if (snum & 0x8000) {
|
||||
snum |= ~0xffff;
|
||||
}
|
||||
ip += 2;
|
||||
ip += 3;
|
||||
PUSH((py_obj_t)(snum << 1 | 1));
|
||||
break;
|
||||
|
||||
@ -162,6 +162,11 @@ bool py_execute_byte_code_2(const byte *code, const byte **ip_in_out, py_obj_t *
|
||||
rt_store_name(qstr, POP());
|
||||
break;
|
||||
|
||||
case PYBC_STORE_GLOBAL:
|
||||
DECODE_QSTR;
|
||||
rt_store_global(qstr, POP());
|
||||
break;
|
||||
|
||||
case PYBC_STORE_ATTR:
|
||||
DECODE_QSTR;
|
||||
rt_store_attr(sp[0], qstr, sp[1]);
|
||||
|
Loading…
Reference in New Issue
Block a user