diff options
author | Damien George <damien.p.george@gmail.com> | 2014-04-08 17:51:47 +0100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-04-08 17:51:47 +0100 |
commit | 495d781a36381927bcf0c1d03a055a2e3a3284bf (patch) | |
tree | a0531fb4725c016c235a9d9b7d07c576c518508a /py/compile.c | |
parent | e753d916c01a8297011d7bb9a16e1947c33fe08d (diff) | |
download | micropython-495d781a36381927bcf0c1d03a055a2e3a3284bf.tar.gz micropython-495d781a36381927bcf0c1d03a055a2e3a3284bf.zip |
py: implement UNPACK_EX byte code (for: a, *b, c = d)
Diffstat (limited to 'py/compile.c')
-rw-r--r-- | py/compile.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/py/compile.c b/py/compile.c index 1fc5f07227..95fe1d759f 100644 --- a/py/compile.c +++ b/py/compile.c @@ -1933,6 +1933,11 @@ void compile_expr_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { // optimisation for a, b = c, d; to match CPython's optimisation mp_parse_node_struct_t* pns10 = (mp_parse_node_struct_t*)pns1->nodes[0]; mp_parse_node_struct_t* pns0 = (mp_parse_node_struct_t*)pns->nodes[0]; + if (MP_PARSE_NODE_IS_STRUCT_KIND(pns0->nodes[0], PN_star_expr) + || MP_PARSE_NODE_IS_STRUCT_KIND(pns0->nodes[1], PN_star_expr)) { + // can't optimise when it's a star expression on the lhs + goto no_optimisation; + } compile_node(comp, pns10->nodes[0]); // rhs compile_node(comp, pns10->nodes[1]); // rhs EMIT(rot_two); @@ -1945,6 +1950,12 @@ void compile_expr_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { // optimisation for a, b, c = d, e, f; to match CPython's optimisation mp_parse_node_struct_t* pns10 = (mp_parse_node_struct_t*)pns1->nodes[0]; mp_parse_node_struct_t* pns0 = (mp_parse_node_struct_t*)pns->nodes[0]; + if (MP_PARSE_NODE_IS_STRUCT_KIND(pns0->nodes[0], PN_star_expr) + || MP_PARSE_NODE_IS_STRUCT_KIND(pns0->nodes[1], PN_star_expr) + || MP_PARSE_NODE_IS_STRUCT_KIND(pns0->nodes[2], PN_star_expr)) { + // can't optimise when it's a star expression on the lhs + goto no_optimisation; + } compile_node(comp, pns10->nodes[0]); // rhs compile_node(comp, pns10->nodes[1]); // rhs compile_node(comp, pns10->nodes[2]); // rhs @@ -1954,6 +1965,7 @@ void compile_expr_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { c_assign(comp, pns0->nodes[1], ASSIGN_STORE); // lhs store c_assign(comp, pns0->nodes[2], ASSIGN_STORE); // lhs store } else { + no_optimisation: compile_node(comp, pns1->nodes[0]); // rhs c_assign(comp, pns->nodes[0], ASSIGN_STORE); // lhs store } |