Skip to content

Commit 708c073

Browse files
committed
py: Add '*' qstr for 'import *'; use blank qstr for comprehension arg.
1 parent 968bf34 commit 708c073

3 files changed

Lines changed: 13 additions & 1 deletion

File tree

py/compile.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1416,7 +1416,7 @@ void compile_import_from(compiler_t *comp, mp_parse_node_struct_t *pns) {
14161416
#if MICROPY_EMIT_CPYTHON
14171417
EMIT_ARG(load_const_verbatim_str, "('*',)");
14181418
#else
1419-
EMIT_ARG(load_const_str, QSTR_FROM_STR_STATIC("*"), false);
1419+
EMIT_ARG(load_const_str, MP_QSTR__star_, false);
14201420
EMIT_ARG(build_tuple, 1);
14211421
#endif
14221422

@@ -3040,7 +3040,15 @@ STATIC void compile_scope(compiler_t *comp, scope_t *scope, pass_kind_t pass) {
30403040
assert(MP_PARSE_NODE_IS_STRUCT_KIND(pns->nodes[1], PN_comp_for));
30413041
mp_parse_node_struct_t *pns_comp_for = (mp_parse_node_struct_t*)pns->nodes[1];
30423042

3043+
// We need a unique name for the comprehension argument (the iterator).
3044+
// CPython uses .0, but we should be able to use anything that won't
3045+
// clash with a user defined variable. Best to use an existing qstr,
3046+
// so we use the blank qstr.
3047+
#if MICROPY_EMIT_CPYTHON
30433048
qstr qstr_arg = QSTR_FROM_STR_STATIC(".0");
3049+
#else
3050+
qstr qstr_arg = MP_QSTR_;
3051+
#endif
30443052
if (comp->pass == PASS_1) {
30453053
bool added;
30463054
id_info_t *id_info = scope_find_or_add_id(comp->scope_cur, qstr_arg, &added);

py/makeqstrdata.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
codepoint2name[ord('#')] = 'hash'
2121
codepoint2name[ord('{')] = 'brace_open'
2222
codepoint2name[ord('}')] = 'brace_close'
23+
codepoint2name[ord('*')] = 'star'
2324

2425
# this must match the equivalent function in qstr.c
2526
def compute_hash(qstr):

py/qstrdefs.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
// All the qstr definitions in this file are available as constants.
33
// That is, they are in ROM and you can reference them simply as MP_QSTR_xxxx.
44

5+
// TODO probably should add Python keywords, eg if, def, etc
6+
7+
Q(*)
58
Q(__build_class__)
69
Q(__class__)
710
Q(__doc__)

0 commit comments

Comments
 (0)