py: Move to Python 3.4.0 compatibility.
Very little has changed. In Python 3.4 they removed the opcode
STORE_LOCALS, but in Micro Python we only ever used this for CPython
compatibility, so it was a trivial thing to remove. It also allowed to
clean up some dead code (eg the 0xdeadbeef in class construction), and
now class builders use 1 less stack word.
Python 3.4.0 introduced the LOAD_CLASSDEREF opcode, which I have not
yet understood. Still, all tests (apart from bytecode test) still pass.
Bytecode tests needs some more attention, but they are not that
important anymore.
diff --git a/py/builtin.c b/py/builtin.c
index 678b3c7..67b0e46 100644
--- a/py/builtin.c
+++ b/py/builtin.c
@@ -26,7 +26,7 @@
mp_locals_set(mp_obj_dict_get_map(class_locals));
// call the class code
- mp_obj_t cell = mp_call_function_1(args[0], (mp_obj_t)0xdeadbeef);
+ mp_obj_t cell = mp_call_function_0(args[0]);
// restore old __locals__ object
mp_locals_set(old_locals);
diff --git a/py/compile.c b/py/compile.c
index 25830eb..a275613 100644
--- a/py/compile.c
+++ b/py/compile.c
@@ -2957,15 +2957,8 @@
id_info_t *id_info = scope_find_or_add_id(scope, MP_QSTR___class__, &added);
assert(added);
id_info->kind = ID_INFO_KIND_LOCAL;
- id_info = scope_find_or_add_id(scope, MP_QSTR___locals__, &added);
- assert(added);
- id_info->kind = ID_INFO_KIND_LOCAL;
- id_info->param = true;
- scope->num_params = 1; // __locals__ is the parameter
}
- EMIT_ARG(load_id, MP_QSTR___locals__);
- EMIT(store_locals);
EMIT_ARG(load_id, MP_QSTR___name__);
EMIT_ARG(store_id, MP_QSTR___module__);
EMIT_ARG(load_const_id, MP_PARSE_NODE_LEAF_ARG(pns->nodes[0])); // 0 is class name
@@ -3155,8 +3148,10 @@
}
// compute scope_flags
- //scope->scope_flags = 0; since we set some things in parameters
- if (scope->kind != SCOPE_MODULE) {
+
+#if MICROPY_EMIT_CPYTHON
+ // these flags computed here are for CPython compatibility only
+ if (scope->kind == SCOPE_FUNCTION) {
scope->scope_flags |= MP_SCOPE_FLAG_NEWLOCALS;
}
if (scope->kind == SCOPE_FUNCTION || scope->kind == SCOPE_LAMBDA || scope->kind == SCOPE_LIST_COMP || scope->kind == SCOPE_DICT_COMP || scope->kind == SCOPE_SET_COMP || scope->kind == SCOPE_GEN_EXPR) {
@@ -3169,6 +3164,8 @@
scope->scope_flags |= MP_SCOPE_FLAG_NESTED;
}
}
+#endif
+
int num_free = 0;
for (int i = 0; i < scope->id_info_len; i++) {
id_info_t *id = &scope->id_info[i];
diff --git a/py/emit.h b/py/emit.h
index 0d95b69..20128fc 100644
--- a/py/emit.h
+++ b/py/emit.h
@@ -54,7 +54,6 @@
void (*store_global)(emit_t *emit, qstr qstr);
void (*store_attr)(emit_t *emit, qstr qstr);
void (*store_subscr)(emit_t *emit);
- void (*store_locals)(emit_t *emit);
void (*delete_fast)(emit_t *emit, qstr qstr, int local_num);
void (*delete_deref)(emit_t *emit, qstr qstr, int local_num);
void (*delete_name)(emit_t *emit, qstr qstr);
diff --git a/py/emitbc.c b/py/emitbc.c
index 0a83448..11519fd 100644
--- a/py/emitbc.c
+++ b/py/emitbc.c
@@ -486,12 +486,6 @@
emit_write_byte_code_byte(emit, MP_BC_STORE_SUBSCR);
}
-STATIC void emit_bc_store_locals(emit_t *emit) {
- // not needed
- emit_bc_pre(emit, -1);
- emit_write_byte_code_byte(emit, MP_BC_POP_TOP);
-}
-
STATIC void emit_bc_delete_fast(emit_t *emit, qstr qstr, int local_num) {
assert(local_num >= 0);
emit_bc_pre(emit, 0);
@@ -860,7 +854,6 @@
emit_bc_store_global,
emit_bc_store_attr,
emit_bc_store_subscr,
- emit_bc_store_locals,
emit_bc_delete_fast,
emit_bc_delete_deref,
emit_bc_delete_name,
diff --git a/py/emitcpy.c b/py/emitcpy.c
index 4f5a96f..8345c12 100644
--- a/py/emitcpy.c
+++ b/py/emitcpy.c
@@ -325,13 +325,6 @@
}
}
-STATIC void emit_cpy_store_locals(emit_t *emit) {
- emit_pre(emit, -1, 1);
- if (emit->pass == PASS_3) {
- printf("STORE_LOCALS\n");
- }
-}
-
STATIC void emit_cpy_delete_fast(emit_t *emit, qstr qstr, int local_num) {
emit_pre(emit, 0, 3);
if (emit->pass == PASS_3) {
@@ -833,7 +826,6 @@
emit_cpy_store_global,
emit_cpy_store_attr,
emit_cpy_store_subscr,
- emit_cpy_store_locals,
emit_cpy_delete_fast,
emit_cpy_delete_deref,
emit_cpy_delete_name,
diff --git a/py/emitnative.c b/py/emitnative.c
index da0aa60..524c5ca 100644
--- a/py/emitnative.c
+++ b/py/emitnative.c
@@ -818,13 +818,6 @@
emit_call(emit, MP_F_STORE_SUBSCR, mp_store_subscr);
}
-STATIC void emit_native_store_locals(emit_t *emit) {
- // not needed
- vtype_kind_t vtype;
- emit_pre_pop_reg(emit, &vtype, REG_TEMP0);
- emit_post(emit);
-}
-
STATIC void emit_native_delete_fast(emit_t *emit, qstr qstr, int local_num) {
// not implemented
// could support for Python types, just set to None (so GC can reclaim it)
@@ -1290,7 +1283,6 @@
emit_native_store_global,
emit_native_store_attr,
emit_native_store_subscr,
- emit_native_store_locals,
emit_native_delete_fast,
emit_native_delete_deref,
emit_native_delete_name,
diff --git a/py/emitpass1.c b/py/emitpass1.c
index e4dbf14..d2f7aaa 100644
--- a/py/emitpass1.c
+++ b/py/emitpass1.c
@@ -182,5 +182,4 @@
(void*)emit_pass1_dummy,
(void*)emit_pass1_dummy,
(void*)emit_pass1_dummy,
- (void*)emit_pass1_dummy,
};