Commit 11d8cd54 authored by Damien George's avatar Damien George
Browse files

py, compiler: Turn id_info_t.param into a set of flags.

So we can add more flags.
parent b140bff8
......@@ -2208,7 +2208,7 @@ STATIC void compile_trailer_paren_helper(compiler_t *comp, mp_parse_node_t pn_ar
// get first argument to function
bool found = false;
for (int i = 0; i < comp->scope_cur->id_info_len; i++) {
if (comp->scope_cur->id_info[i].param) {
if (comp->scope_cur->id_info[i].flags && ID_FLAG_IS_PARAM) {
EMIT_ARG(load_fast, MP_QSTR_, comp->scope_cur->id_info[i].local_num);
found = true;
break;
......@@ -2761,8 +2761,8 @@ void compile_scope_func_lambda_param(compiler_t *comp, mp_parse_node_t pn, pn_ki
compile_syntax_error(comp, pn, "same name used for parameter");
return;
}
id_info->param = true;
id_info->kind = ID_INFO_KIND_LOCAL;
id_info->flags |= ID_FLAG_IS_PARAM;
}
}
......@@ -3097,7 +3097,7 @@ void compile_scope_compute_things(compiler_t *comp, scope_t *scope) {
id->kind = ID_INFO_KIND_GLOBAL_EXPLICIT;
}
// note: params always count for 1 local, even if they are a cell
if (id->param || id->kind == ID_INFO_KIND_LOCAL) {
if (id->kind == ID_INFO_KIND_LOCAL || (id->flags & ID_FLAG_IS_PARAM)) {
id->local_num = scope->num_locals;
scope->num_locals += 1;
}
......@@ -3119,7 +3119,7 @@ void compile_scope_compute_things(compiler_t *comp, scope_t *scope) {
// in Micro Python the cells come right after the fast locals
// parameters are not counted here, since they remain at the start
// of the locals, even if they are cell vars
if (!id->param && id->kind == ID_INFO_KIND_CELL) {
if (id->kind == ID_INFO_KIND_CELL && !(id->flags & ID_FLAG_IS_PARAM)) {
id->local_num = scope->num_locals;
scope->num_locals += 1;
}
......@@ -3136,7 +3136,7 @@ void compile_scope_compute_things(compiler_t *comp, scope_t *scope) {
for (int j = 0; j < scope->id_info_len; j++) {
id_info_t *id2 = &scope->id_info[j];
if (id2->kind == ID_INFO_KIND_FREE && id->qstr == id2->qstr) {
assert(!id2->param); // free vars should not be params
assert(!(id2->flags & ID_FLAG_IS_PARAM)); // free vars should not be params
#if MICROPY_EMIT_CPYTHON
// in CPython the frees are numbered after the cells
id2->local_num = num_cell + num_free;
......@@ -3154,7 +3154,7 @@ void compile_scope_compute_things(compiler_t *comp, scope_t *scope) {
if (num_free > 0) {
for (int i = 0; i < scope->id_info_len; i++) {
id_info_t *id = &scope->id_info[i];
if (id->param || id->kind != ID_INFO_KIND_FREE) {
if (id->kind != ID_INFO_KIND_FREE || (id->flags && ID_FLAG_IS_PARAM)) {
id->local_num += num_free;
}
}
......
......@@ -73,10 +73,10 @@ id_info_t *scope_find_or_add_id(scope_t *scope, qstr qstr, bool *added) {
// handled by the compiler because it adds arguments before compiling the body
id_info_t *id_info = &scope->id_info[scope->id_info_len++];
id_info->param = false;
id_info->kind = 0;
id_info->qstr = qstr;
id_info->flags = 0;
id_info->local_num = 0;
id_info->qstr = qstr;
*added = true;
return id_info;
}
......
......@@ -6,9 +6,13 @@ enum {
ID_INFO_KIND_FREE, // in a function f, belongs to the parent of f
};
enum {
ID_FLAG_IS_PARAM = 0x01,
};
typedef struct _id_info_t {
uint8_t param;
uint8_t kind;
uint8_t flags;
// when it's an ID_INFO_KIND_LOCAL this is the unique number of the local
// whet it's an ID_INFO_KIND_CELL/FREE this is the unique number of the closed over variable
uint16_t local_num;
......
Supports Markdown
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