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.
travis
Damien George 2014-04-02 15:56:31 +01:00
parent 929a675a3d
commit 882b363564
7 changed files with 7 additions and 35 deletions

View File

@ -26,7 +26,7 @@ STATIC mp_obj_t mp_builtin___build_class__(uint n_args, const mp_obj_t *args) {
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);

View File

@ -2957,15 +2957,8 @@ void compile_scope(compiler_t *comp, scope_t *scope, pass_kind_t pass) {
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 @@ void compile_scope_compute_things(compiler_t *comp, scope_t *scope) {
}
// 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 @@ void compile_scope_compute_things(compiler_t *comp, scope_t *scope) {
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];

View File

@ -54,7 +54,6 @@ typedef struct _emit_method_table_t {
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);

View File

@ -486,12 +486,6 @@ STATIC void emit_bc_store_subscr(emit_t *emit) {
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 @@ const emit_method_table_t emit_bc_method_table = {
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,

View File

@ -325,13 +325,6 @@ STATIC void emit_cpy_store_subscr(emit_t *emit) {
}
}
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 @@ const emit_method_table_t emit_cpython_method_table = {
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,

View File

@ -818,13 +818,6 @@ STATIC void emit_native_store_subscr(emit_t *emit) {
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 @@ const emit_method_table_t EXPORT_FUN(method_table) = {
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,

View File

@ -182,5 +182,4 @@ const emit_method_table_t emit_pass1_method_table = {
(void*)emit_pass1_dummy,
(void*)emit_pass1_dummy,
(void*)emit_pass1_dummy,
(void*)emit_pass1_dummy,
};