py: Fix bug with LOAD_METHOD; fix int->machine_int_t for small int.

LOAD_METHOD bug was: emitbc did not correctly calculate the amount of
stack usage for a LOAD_METHOD operation.

small int bug was: int was being used to pass small ints, when it should
have been machine_int_t.
pull/237/merge
Damien George 2014-01-29 18:58:52 +00:00
rodzic 1ba1facaaa
commit 08d075592f
9 zmienionych plików z 19 dodań i 23 usunięć

Wyświetl plik

@ -2501,7 +2501,7 @@ void compile_node(compiler_t *comp, mp_parse_node_t pn) {
if (MP_PARSE_NODE_IS_NULL(pn)) {
// pass
} else if (MP_PARSE_NODE_IS_LEAF(pn)) {
int arg = MP_PARSE_NODE_LEAF_ARG(pn);
machine_int_t arg = MP_PARSE_NODE_LEAF_ARG(pn);
switch (MP_PARSE_NODE_LEAF_KIND(pn)) {
case MP_PARSE_NODE_ID: EMIT_ARG(load_id, arg); break;
case MP_PARSE_NODE_SMALL_INT: EMIT_ARG(load_const_small_int, arg); break;
@ -3030,7 +3030,8 @@ void compile_scope_compute_things(compiler_t *comp, scope_t *scope) {
scope->flags |= SCOPE_FLAG_OPTIMISED;
// TODO possibly other ways it can be nested
if (scope->parent->kind == SCOPE_FUNCTION || (scope->parent->kind == SCOPE_CLASS && scope->parent->parent->kind == SCOPE_FUNCTION)) {
// Note that we don't actually use this information at the moment (for CPython compat only)
if ((SCOPE_FUNCTION <= scope->parent->kind && scope->parent->kind <= SCOPE_SET_COMP) || (scope->parent->kind == SCOPE_CLASS && scope->parent->parent->kind == SCOPE_FUNCTION)) {
scope->flags |= SCOPE_FLAG_NESTED;
}
}

Wyświetl plik

@ -34,7 +34,7 @@ typedef struct _emit_method_table_t {
void (*import_from)(emit_t *emit, qstr qstr);
void (*import_star)(emit_t *emit);
void (*load_const_tok)(emit_t *emit, mp_token_kind_t tok);
void (*load_const_small_int)(emit_t *emit, int arg);
void (*load_const_small_int)(emit_t *emit, machine_int_t arg);
void (*load_const_int)(emit_t *emit, qstr qstr);
void (*load_const_dec)(emit_t *emit, qstr qstr);
void (*load_const_id)(emit_t *emit, qstr qstr);

Wyświetl plik

@ -108,7 +108,7 @@ static void emit_write_byte_code_byte_byte(emit_t* emit, byte b1, uint b2) {
}
// integers (for small ints) are stored as 24 bits, in excess
static void emit_write_byte_code_byte_int(emit_t* emit, byte b1, int num) {
static void emit_write_byte_code_byte_int(emit_t* emit, byte b1, machine_int_t num) {
num += 0x800000;
assert(0 <= num && num <= 0xffffff);
byte* c = emit_get_cur_to_write_byte_code(emit, 4);
@ -319,7 +319,7 @@ static void emit_bc_load_const_tok(emit_t *emit, mp_token_kind_t tok) {
}
}
static void emit_bc_load_const_small_int(emit_t *emit, int arg) {
static void emit_bc_load_const_small_int(emit_t *emit, machine_int_t arg) {
emit_pre(emit, 1);
emit_write_byte_code_byte_int(emit, MP_BC_LOAD_CONST_SMALL_INT, arg);
}
@ -390,7 +390,7 @@ static void emit_bc_load_attr(emit_t *emit, qstr qstr) {
}
static void emit_bc_load_method(emit_t *emit, qstr qstr) {
emit_pre(emit, 0);
emit_pre(emit, 1);
emit_write_byte_code_byte_qstr(emit, MP_BC_LOAD_METHOD, qstr);
}
@ -707,7 +707,7 @@ static void emit_bc_call_method(emit_t *emit, int n_positional, int n_keyword, b
if (have_dbl_star_arg) {
s += 1;
}
emit_pre(emit, -n_positional - 2 * n_keyword - s);
emit_pre(emit, -1 - n_positional - 2 * n_keyword - s);
int op;
if (have_star_arg) {
if (have_dbl_star_arg) {

Wyświetl plik

@ -149,10 +149,10 @@ static void emit_cpy_load_const_tok(emit_t *emit, mp_token_kind_t tok) {
}
}
static void emit_cpy_load_const_small_int(emit_t *emit, int arg) {
static void emit_cpy_load_const_small_int(emit_t *emit, machine_int_t arg) {
emit_pre(emit, 1, 3);
if (emit->pass == PASS_3) {
printf("LOAD_CONST %d\n", arg);
printf("LOAD_CONST " INT_FMT "\n", arg);
}
}

Wyświetl plik

@ -599,7 +599,7 @@ static void emit_native_load_const_tok(emit_t *emit, mp_token_kind_t tok) {
emit_post_push_imm(emit, vtype, val);
}
static void emit_native_load_const_small_int(emit_t *emit, int arg) {
static void emit_native_load_const_small_int(emit_t *emit, machine_int_t arg) {
emit_pre(emit);
if (emit->do_viper_types) {
emit_post_push_imm(emit, VTYPE_INT, arg);

Wyświetl plik

@ -172,15 +172,15 @@ void mp_parse_node_print(mp_parse_node_t pn, int indent) {
if (MP_PARSE_NODE_IS_NULL(pn)) {
printf("NULL\n");
} else if (MP_PARSE_NODE_IS_LEAF(pn)) {
int arg = MP_PARSE_NODE_LEAF_ARG(pn);
machine_int_t arg = MP_PARSE_NODE_LEAF_ARG(pn);
switch (MP_PARSE_NODE_LEAF_KIND(pn)) {
case MP_PARSE_NODE_ID: printf("id(%s)\n", qstr_str(arg)); break;
case MP_PARSE_NODE_SMALL_INT: printf("int(%d)\n", arg); break;
case MP_PARSE_NODE_SMALL_INT: printf("int(" INT_FMT ")\n", arg); break;
case MP_PARSE_NODE_INTEGER: printf("int(%s)\n", qstr_str(arg)); break;
case MP_PARSE_NODE_DECIMAL: printf("dec(%s)\n", qstr_str(arg)); break;
case MP_PARSE_NODE_STRING: printf("str(%s)\n", qstr_str(arg)); break;
case MP_PARSE_NODE_BYTES: printf("bytes(%s)\n", qstr_str(arg)); break;
case MP_PARSE_NODE_TOKEN: printf("tok(%d)\n", arg); break;
case MP_PARSE_NODE_TOKEN: printf("tok(" INT_FMT ")\n", arg); break;
default: assert(0);
}
} else {

Wyświetl plik

@ -217,7 +217,7 @@ void rt_assign_byte_code(int unique_code_id, byte *code, uint len, int n_args, i
//printf("byte code: %d bytes\n", len);
#ifdef DEBUG_PRINT
DEBUG_printf("assign byte code: id=%d code=%p len=%u n_args=%d\n", unique_code_id, code, len, n_args);
DEBUG_printf("assign byte code: id=%d code=%p len=%u n_args=%d n_locals=%d n_stack=%d\n", unique_code_id, code, len, n_args, n_locals, n_stack);
for (int i = 0; i < 128 && i < len; i++) {
if (i > 0 && i % 16 == 0) {
DEBUG_printf("\n");

Wyświetl plik

@ -68,12 +68,10 @@ void mp_byte_code_print(const byte *ip, int len) {
printf("LOAD_CONST_INT %s", qstr_str(qstr));
break;
/*
case MP_BC_LOAD_CONST_DEC:
DECODE_QSTR;
PUSH(rt_load_const_dec(qstr));
printf("LOAD_CONST_DEC %s", qstr_str(qstr));
break;
*/
case MP_BC_LOAD_CONST_ID:
DECODE_QSTR;
@ -351,12 +349,12 @@ void mp_byte_code_print(const byte *ip, int len) {
case MP_BC_IMPORT_NAME:
DECODE_QSTR;
printf("IMPORT NAME %s", qstr_str(qstr));
printf("IMPORT_NAME %s", qstr_str(qstr));
break;
case MP_BC_IMPORT_FROM:
DECODE_QSTR;
printf("IMPORT NAME %s", qstr_str(qstr));
printf("IMPORT_FROM %s", qstr_str(qstr));
break;
default:

Wyświetl plik

@ -26,8 +26,6 @@
#define SET_TOP(val) *sp = (val)
mp_obj_t mp_execute_byte_code(const byte *code, const mp_obj_t *args, uint n_args, uint n_state) {
n_state += 1; // XXX there is a bug somewhere which doesn't count enough state... (conwaylife and mandel have the bug)
// allocate state for locals and stack
mp_obj_t temp_state[10];
mp_obj_t *state = &temp_state[0];
@ -479,8 +477,7 @@ bool mp_execute_byte_code_2(const byte *code_info, const byte **ip_in_out, mp_ob
case MP_BC_MAKE_CLOSURE:
DECODE_UINT;
obj1 = POP();
PUSH(rt_make_closure_from_id(unum, obj1));
SET_TOP(rt_make_closure_from_id(unum, TOP()));
break;
case MP_BC_CALL_FUNCTION: