Commit 27fb45eb authored by Damien's avatar Damien
Browse files

Add local_num skeleton framework to deref/closure emit calls.

parent a5185f4b
...@@ -721,7 +721,7 @@ void close_over_variables_etc(compiler_t *comp, scope_t *this_scope, int n_dict_ ...@@ -721,7 +721,7 @@ void close_over_variables_etc(compiler_t *comp, scope_t *this_scope, int n_dict_
for (int i = 0; i < this_scope->id_info_len; i++) { for (int i = 0; i < this_scope->id_info_len; i++) {
id_info_t *id_info = &this_scope->id_info[i]; id_info_t *id_info = &this_scope->id_info[i];
if (id_info->kind == ID_INFO_KIND_FREE) { if (id_info->kind == ID_INFO_KIND_FREE) {
EMIT(load_closure, id_info->qstr); EMIT(load_closure, id_info->qstr, id_info->local_num);
nfree += 1; nfree += 1;
} }
} }
...@@ -2624,7 +2624,7 @@ void compile_scope(compiler_t *comp, scope_t *scope, pass_kind_t pass) { ...@@ -2624,7 +2624,7 @@ void compile_scope(compiler_t *comp, scope_t *scope, pass_kind_t pass) {
if (id->kind == ID_INFO_KIND_LOCAL) { if (id->kind == ID_INFO_KIND_LOCAL) {
EMIT(load_const_tok, PY_TOKEN_KW_NONE); EMIT(load_const_tok, PY_TOKEN_KW_NONE);
} else { } else {
EMIT(load_closure, comp->qstr___class__); EMIT(load_closure, comp->qstr___class__, 0); // XXX check this is the correct local num
} }
EMIT(return_value); EMIT(return_value);
} }
...@@ -2729,6 +2729,8 @@ void compile_scope_compute_things(compiler_t *comp, scope_t *scope) { ...@@ -2729,6 +2729,8 @@ void compile_scope_compute_things(compiler_t *comp, scope_t *scope) {
} }
} }
// TODO compute the index of free and cell vars (freevars[idx] in CPython)
// compute flags // compute flags
//scope->flags = 0; since we set some things in parameters //scope->flags = 0; since we set some things in parameters
if (scope->kind != SCOPE_MODULE) { if (scope->kind != SCOPE_MODULE) {
......
...@@ -47,22 +47,22 @@ typedef struct _emit_method_table_t { ...@@ -47,22 +47,22 @@ typedef struct _emit_method_table_t {
void (*load_fast)(emit_t *emit, qstr qstr, int local_num); void (*load_fast)(emit_t *emit, qstr qstr, int local_num);
void (*load_name)(emit_t *emit, qstr qstr); void (*load_name)(emit_t *emit, qstr qstr);
void (*load_global)(emit_t *emit, qstr qstr); void (*load_global)(emit_t *emit, qstr qstr);
void (*load_deref)(emit_t *emit, qstr qstr); void (*load_deref)(emit_t *emit, qstr qstr, int local_num);
void (*load_closure)(emit_t *emit, qstr qstr); void (*load_closure)(emit_t *emit, qstr qstr, int local_num);
void (*load_attr)(emit_t *emit, qstr qstr); void (*load_attr)(emit_t *emit, qstr qstr);
void (*load_method)(emit_t *emit, qstr qstr); void (*load_method)(emit_t *emit, qstr qstr);
void (*load_build_class)(emit_t *emit); void (*load_build_class)(emit_t *emit);
void (*store_fast)(emit_t *emit, qstr qstr, int local_num); void (*store_fast)(emit_t *emit, qstr qstr, int local_num);
void (*store_name)(emit_t *emit, qstr qstr); void (*store_name)(emit_t *emit, qstr qstr);
void (*store_global)(emit_t *emit, qstr qstr); void (*store_global)(emit_t *emit, qstr qstr);
void (*store_deref)(emit_t *emit, qstr qstr); void (*store_deref)(emit_t *emit, qstr qstr, int local_num);
void (*store_attr)(emit_t *emit, qstr qstr); void (*store_attr)(emit_t *emit, qstr qstr);
void (*store_subscr)(emit_t *emit); void (*store_subscr)(emit_t *emit);
void (*store_locals)(emit_t *emit); void (*store_locals)(emit_t *emit);
void (*delete_fast)(emit_t *emit, qstr qstr, int local_num); void (*delete_fast)(emit_t *emit, qstr qstr, int local_num);
void (*delete_name)(emit_t *emit, qstr qstr); void (*delete_name)(emit_t *emit, qstr qstr);
void (*delete_global)(emit_t *emit, qstr qstr); void (*delete_global)(emit_t *emit, qstr qstr);
void (*delete_deref)(emit_t *emit, qstr qstr); void (*delete_deref)(emit_t *emit, qstr qstr, int local_num);
void (*delete_attr)(emit_t *emit, qstr qstr); void (*delete_attr)(emit_t *emit, qstr qstr);
void (*delete_subscr)(emit_t *emit); void (*delete_subscr)(emit_t *emit);
void (*dup_top)(emit_t *emit); void (*dup_top)(emit_t *emit);
......
...@@ -291,12 +291,12 @@ static void emit_bc_load_global(emit_t *emit, qstr qstr) { ...@@ -291,12 +291,12 @@ static void emit_bc_load_global(emit_t *emit, qstr qstr) {
emit_write_byte_1_qstr(emit, PYBC_LOAD_GLOBAL, qstr); emit_write_byte_1_qstr(emit, PYBC_LOAD_GLOBAL, qstr);
} }
static void emit_bc_load_deref(emit_t *emit, qstr qstr) { static void emit_bc_load_deref(emit_t *emit, qstr qstr, int local_num) {
emit_pre(emit, 1); emit_pre(emit, 1);
assert(0); assert(0);
} }
static void emit_bc_load_closure(emit_t *emit, qstr qstr) { static void emit_bc_load_closure(emit_t *emit, qstr qstr, int local_num) {
emit_pre(emit, 1); emit_pre(emit, 1);
assert(0); assert(0);
} }
...@@ -337,7 +337,7 @@ static void emit_bc_store_global(emit_t *emit, qstr qstr) { ...@@ -337,7 +337,7 @@ static void emit_bc_store_global(emit_t *emit, qstr qstr) {
emit_write_byte_1_qstr(emit, PYBC_STORE_GLOBAL, qstr); emit_write_byte_1_qstr(emit, PYBC_STORE_GLOBAL, qstr);
} }
static void emit_bc_store_deref(emit_t *emit, qstr qstr) { static void emit_bc_store_deref(emit_t *emit, qstr qstr, int local_num) {
emit_pre(emit, -1); emit_pre(emit, -1);
assert(0); assert(0);
} }
...@@ -374,9 +374,10 @@ static void emit_bc_delete_global(emit_t *emit, qstr qstr) { ...@@ -374,9 +374,10 @@ static void emit_bc_delete_global(emit_t *emit, qstr qstr) {
emit_write_byte_1_qstr(emit, PYBC_DELETE_GLOBAL, qstr); emit_write_byte_1_qstr(emit, PYBC_DELETE_GLOBAL, qstr);
} }
static void emit_bc_delete_deref(emit_t *emit, qstr qstr) { static void emit_bc_delete_deref(emit_t *emit, qstr qstr, int local_num) {
emit_pre(emit, 0); emit_pre(emit, 0);
emit_write_byte_1_qstr(emit, PYBC_DELETE_DEREF, qstr); assert(0);
//emit_write_byte_1_qstr(emit, PYBC_DELETE_DEREF, qstr);
} }
static void emit_bc_delete_attr(emit_t *emit, qstr qstr) { static void emit_bc_delete_attr(emit_t *emit, qstr qstr) {
......
...@@ -28,7 +28,7 @@ void emit_common_load_id(emit_t *emit, const emit_method_table_t *emit_method_ta ...@@ -28,7 +28,7 @@ void emit_common_load_id(emit_t *emit, const emit_method_table_t *emit_method_ta
} else if (id->kind == ID_INFO_KIND_LOCAL) { } else if (id->kind == ID_INFO_KIND_LOCAL) {
EMIT(load_fast, qstr, id->local_num); EMIT(load_fast, qstr, id->local_num);
} else if (id->kind == ID_INFO_KIND_CELL || id->kind == ID_INFO_KIND_FREE) { } else if (id->kind == ID_INFO_KIND_CELL || id->kind == ID_INFO_KIND_FREE) {
EMIT(load_deref, qstr); EMIT(load_deref, qstr, id->local_num);
} else { } else {
assert(0); assert(0);
} }
...@@ -48,7 +48,7 @@ void emit_common_store_id(emit_t *emit, const emit_method_table_t *emit_method_t ...@@ -48,7 +48,7 @@ void emit_common_store_id(emit_t *emit, const emit_method_table_t *emit_method_t
} else if (id->kind == ID_INFO_KIND_LOCAL) { } else if (id->kind == ID_INFO_KIND_LOCAL) {
EMIT(store_fast, qstr, id->local_num); EMIT(store_fast, qstr, id->local_num);
} else if (id->kind == ID_INFO_KIND_CELL || id->kind == ID_INFO_KIND_FREE) { } else if (id->kind == ID_INFO_KIND_CELL || id->kind == ID_INFO_KIND_FREE) {
EMIT(store_deref, qstr); EMIT(store_deref, qstr, id->local_num);
} else { } else {
assert(0); assert(0);
} }
...@@ -68,7 +68,7 @@ void emit_common_delete_id(emit_t *emit, const emit_method_table_t *emit_method_ ...@@ -68,7 +68,7 @@ void emit_common_delete_id(emit_t *emit, const emit_method_table_t *emit_method_
} else if (id->kind == ID_INFO_KIND_LOCAL) { } else if (id->kind == ID_INFO_KIND_LOCAL) {
EMIT(delete_fast, qstr, id->local_num); EMIT(delete_fast, qstr, id->local_num);
} else if (id->kind == ID_INFO_KIND_CELL || id->kind == ID_INFO_KIND_FREE) { } else if (id->kind == ID_INFO_KIND_CELL || id->kind == ID_INFO_KIND_FREE) {
EMIT(delete_deref, qstr); EMIT(delete_deref, qstr, id->local_num);
} else { } else {
assert(0); assert(0);
} }
......
...@@ -279,17 +279,17 @@ static void emit_cpy_load_global(emit_t *emit, qstr qstr) { ...@@ -279,17 +279,17 @@ static void emit_cpy_load_global(emit_t *emit, qstr qstr) {
} }
} }
static void emit_cpy_load_deref(emit_t *emit, qstr qstr) { static void emit_cpy_load_deref(emit_t *emit, qstr qstr, int local_num) {
emit_pre(emit, 1, 3); emit_pre(emit, 1, 3);
if (emit->pass == PASS_3) { if (emit->pass == PASS_3) {
printf("LOAD_DEREF %s\n", qstr_str(qstr)); printf("LOAD_DEREF %d %s\n", local_num, qstr_str(qstr));
} }
} }
static void emit_cpy_load_closure(emit_t *emit, qstr qstr) { static void emit_cpy_load_closure(emit_t *emit, qstr qstr, int local_num) {
emit_pre(emit, 1, 3); emit_pre(emit, 1, 3);
if (emit->pass == PASS_3) { if (emit->pass == PASS_3) {
printf("LOAD_CLOSURE %s\n", qstr_str(qstr)); printf("LOAD_CLOSURE %d %s\n", local_num, qstr_str(qstr));
} }
} }
...@@ -332,10 +332,10 @@ static void emit_cpy_store_global(emit_t *emit, qstr qstr) { ...@@ -332,10 +332,10 @@ static void emit_cpy_store_global(emit_t *emit, qstr qstr) {
} }
} }
static void emit_cpy_store_deref(emit_t *emit, qstr qstr) { static void emit_cpy_store_deref(emit_t *emit, qstr qstr, int local_num) {
emit_pre(emit, -1, 3); emit_pre(emit, -1, 3);
if (emit->pass == PASS_3) { if (emit->pass == PASS_3) {
printf("STORE_DEREF %s\n", qstr_str(qstr)); printf("STORE_DEREF %d %s\n", local_num, qstr_str(qstr));
} }
} }
...@@ -381,10 +381,10 @@ static void emit_cpy_delete_global(emit_t *emit, qstr qstr) { ...@@ -381,10 +381,10 @@ static void emit_cpy_delete_global(emit_t *emit, qstr qstr) {
} }
} }
static void emit_cpy_delete_deref(emit_t *emit, qstr qstr) { static void emit_cpy_delete_deref(emit_t *emit, qstr qstr, int local_num) {
emit_pre(emit, 0, 3); emit_pre(emit, 0, 3);
if (emit->pass == PASS_3) { if (emit->pass == PASS_3) {
printf("DELETE_DEREF %s\n", qstr_str(qstr)); printf("DELETE_DEREF %d %s\n", local_num, qstr_str(qstr));
} }
} }
......
...@@ -675,13 +675,13 @@ static void emit_native_load_global(emit_t *emit, qstr qstr) { ...@@ -675,13 +675,13 @@ static void emit_native_load_global(emit_t *emit, qstr qstr) {
emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET);
} }
static void emit_native_load_deref(emit_t *emit, qstr qstr) { static void emit_native_load_deref(emit_t *emit, qstr qstr, int local_num) {
// not implemented // not implemented
// in principle could support this quite easily (ldr r0, [r0, #0]) and then get closed over variables! // in principle could support this quite easily (ldr r0, [r0, #0]) and then get closed over variables!
assert(0); assert(0);
} }
static void emit_native_load_closure(emit_t *emit, qstr qstr) { static void emit_native_load_closure(emit_t *emit, qstr qstr, int local_num) {
// not implemented // not implemented
assert(0); assert(0);
} }
...@@ -760,7 +760,7 @@ static void emit_native_store_global(emit_t *emit, qstr qstr) { ...@@ -760,7 +760,7 @@ static void emit_native_store_global(emit_t *emit, qstr qstr) {
assert(0); assert(0);
} }
static void emit_native_store_deref(emit_t *emit, qstr qstr) { static void emit_native_store_deref(emit_t *emit, qstr qstr, int local_num) {
// not implemented // not implemented
assert(0); assert(0);
} }
...@@ -812,7 +812,7 @@ static void emit_native_delete_global(emit_t *emit, qstr qstr) { ...@@ -812,7 +812,7 @@ static void emit_native_delete_global(emit_t *emit, qstr qstr) {
assert(0); assert(0);
} }
static void emit_native_delete_deref(emit_t *emit, qstr qstr) { static void emit_native_delete_deref(emit_t *emit, qstr qstr, int local_num) {
// not supported // not supported
assert(0); assert(0);
} }
......
...@@ -103,6 +103,7 @@ id_info_t *scope_find_or_add_id(scope_t *scope, qstr qstr, bool *added) { ...@@ -103,6 +103,7 @@ id_info_t *scope_find_or_add_id(scope_t *scope, qstr qstr, bool *added) {
id_info->param = false; id_info->param = false;
id_info->kind = 0; id_info->kind = 0;
id_info->qstr = qstr; id_info->qstr = qstr;
id_info->local_num = 0;
*added = true; *added = true;
return id_info; return id_info;
} }
......
...@@ -7,6 +7,7 @@ enum { ...@@ -7,6 +7,7 @@ enum {
}; };
typedef struct _id_info_t { typedef struct _id_info_t {
// TODO compress this info to make structure smaller in memory
bool param; bool param;
int kind; int kind;
qstr qstr; qstr qstr;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment