py/scope: Factor common code to find locals and close over them.

Saves 50-100 bytes of code.
This commit is contained in:
Damien George
2016-09-30 13:53:00 +10:00
parent d5495966ce
commit 0d10517a45
4 changed files with 35 additions and 39 deletions

View File

@@ -35,13 +35,7 @@ void mp_emit_common_get_id_for_load(scope_t *scope, qstr qst) {
bool added;
id_info_t *id = scope_find_or_add_id(scope, qst, &added);
if (added) {
id_info_t *id2 = scope_find_local_in_parent(scope, qst);
if (id2 != NULL && (id2->kind == ID_INFO_KIND_LOCAL || id2->kind == ID_INFO_KIND_CELL || id2->kind == ID_INFO_KIND_FREE)) {
id->kind = ID_INFO_KIND_FREE;
scope_close_over_in_parents(scope, qst);
} else {
id->kind = ID_INFO_KIND_GLOBAL_IMPLICIT;
}
scope_find_local_and_close_over(scope, id, qst);
}
}