diff options
Diffstat (limited to 'py/scope.c')
| -rw-r--r-- | py/scope.c | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/py/scope.c b/py/scope.c index 57a7e6875..640d4f742 100644 --- a/py/scope.c +++ b/py/scope.c @@ -8,7 +8,7 @@ #include "parse.h" #include "scope.h" -scope_t *scope_new(scope_kind_t kind, py_parse_node_t pn, uint unique_code_id) { +scope_t *scope_new(scope_kind_t kind, py_parse_node_t pn, uint unique_code_id, uint emit_options) { scope_t *scope = m_new(scope_t, 1); scope->kind = kind; scope->parent = NULL; @@ -53,6 +53,7 @@ scope_t *scope_new(scope_kind_t kind, py_parse_node_t pn, uint unique_code_id) { */ scope->num_locals = 0; scope->unique_code_id = unique_code_id; + scope->emit_options = emit_options; return scope; } @@ -80,17 +81,23 @@ id_info_t *scope_find_or_add_id(scope_t *scope, qstr qstr, bool *added) { */ } - { - // sort insert into id_info array, so we are equivalent to CPython (no other reason to do it) - scope->id_info_len += 1; - for (int i = scope->id_info_len - 1;; i--) { - if (i == 0 || strcmp(qstr_str(scope->id_info[i - 1].qstr), qstr_str(qstr)) < 0) { - id_info = &scope->id_info[i]; - break; - } else { - scope->id_info[i] = scope->id_info[i - 1]; + if (0) { + // sort insert into id_info array, so we are equivalent to CPython (no other reason to do it) + // actually, seems that this is not what CPython does... + scope->id_info_len += 1; + for (int i = scope->id_info_len - 1;; i--) { + if (i == 0 || strcmp(qstr_str(scope->id_info[i - 1].qstr), qstr_str(qstr)) < 0) { + id_info = &scope->id_info[i]; + break; + } else { + scope->id_info[i] = scope->id_info[i - 1]; + } } - } + } else { + // just add new id to end of array of all ids; this seems to match CPython + // important thing is that function arguments are first, but that is + // handled by the compiler because it adds arguments before compiling the body + id_info = &scope->id_info[scope->id_info_len++]; } id_info->param = false; |
