diff options
author | Damien <damien.p.george@gmail.com> | 2013-12-10 17:27:24 +0000 |
---|---|---|
committer | Damien <damien.p.george@gmail.com> | 2013-12-10 17:27:24 +0000 |
commit | db4c361f1cb805dca8e4c2d6c6a9ac61ae0c9c36 (patch) | |
tree | 41e4ca510fbfd590aa7341b23d62eff4d3c42399 /py/compile.c | |
parent | 261dbf8ce55e7237d5fa8cb65c1f33fc922db34d (diff) | |
download | micropython-db4c361f1cb805dca8e4c2d6c6a9ac61ae0c9c36.tar.gz micropython-db4c361f1cb805dca8e4c2d6c6a9ac61ae0c9c36.zip |
py: add skeletal import functionality.
Diffstat (limited to 'py/compile.c')
-rw-r--r-- | py/compile.c | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/py/compile.c b/py/compile.c index f157af49f5..5e86b408c8 100644 --- a/py/compile.c +++ b/py/compile.c @@ -1168,18 +1168,30 @@ void compile_import_name(compiler_t *comp, py_parse_node_struct_t *pns) { void compile_import_from(compiler_t *comp, py_parse_node_struct_t *pns) { if (PY_PARSE_NODE_IS_TOKEN_KIND(pns->nodes[1], PY_TOKEN_OP_STAR)) { - EMIT(load_const_small_int, 0); // what's this for?? + EMIT(load_const_small_int, 0); // level 0 for __import__ + + // build the "fromlist" tuple +#if MICROPY_EMIT_CPYTHON EMIT(load_const_verbatim_start); EMIT(load_const_verbatim_str, "('*',)"); EMIT(load_const_verbatim_end); +#else + EMIT(load_const_str, qstr_from_str_static("*"), false); + EMIT(build_tuple, 1); +#endif + + // do the import qstr dummy_q, id1; do_import_name(comp, pns->nodes[0], &dummy_q, &id1); EMIT(import_star); + } else { + EMIT(load_const_small_int, 0); // level 0 for __import__ + + // build the "fromlist" tuple py_parse_node_t *pn_nodes; int n = list_get(&pns->nodes[1], PN_import_as_names, &pn_nodes); - - EMIT(load_const_small_int, 0); // what's this for?? +#if MICROPY_EMIT_CPYTHON EMIT(load_const_verbatim_start); EMIT(load_const_verbatim_str, "("); for (int i = 0; i < n; i++) { @@ -1198,6 +1210,17 @@ void compile_import_from(compiler_t *comp, py_parse_node_struct_t *pns) { } EMIT(load_const_verbatim_str, ")"); EMIT(load_const_verbatim_end); +#else + for (int i = 0; i < n; i++) { + assert(PY_PARSE_NODE_IS_STRUCT_KIND(pn_nodes[i], PN_import_as_name)); + py_parse_node_struct_t *pns3 = (py_parse_node_struct_t*)pn_nodes[i]; + qstr id2 = PY_PARSE_NODE_LEAF_ARG(pns3->nodes[0]); // should be id + EMIT(load_const_str, id2, false); + } + EMIT(build_tuple, n); +#endif + + // do the import qstr dummy_q, id1; do_import_name(comp, pns->nodes[0], &dummy_q, &id1); for (int i = 0; i < n; i++) { |