diff options
| author | Craig Forbes <cpforbes@starlake.org> | 2019-02-20 21:37:29 -0600 |
|---|---|---|
| committer | Craig Forbes <cpforbes@starlake.org> | 2019-02-20 21:37:29 -0600 |
| commit | 1532863d8341ba0240da903533f5eb9d08987662 (patch) | |
| tree | 9ffe3467940b2122d1fc74fa1643056d1bdc93dc /lib | |
| parent | 0dc2600587f1ee75ee20da0d24219d415ab0f1ac (diff) | |
Set __file__ for the main source file (e.g. code.py, main.py)
Diffstat (limited to 'lib')
| -rwxr-xr-x | lib/utils/pyexec.c | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/lib/utils/pyexec.c b/lib/utils/pyexec.c index e637fe544..e8a1983b0 100755 --- a/lib/utils/pyexec.c +++ b/lib/utils/pyexec.c @@ -89,6 +89,9 @@ STATIC int parse_compile_execute(const void *source, mp_parse_input_kind_t input } // source is a lexer, parse and compile the script qstr source_name = lex->source_name; + if (input_kind == MP_PARSE_FILE_INPUT) { + mp_store_global(MP_QSTR___file__, MP_OBJ_NEW_QSTR(source_name)); + } mp_parse_tree_t parse_tree = mp_parse(lex, input_kind); module_fun = mp_compile(&parse_tree, source_name, MP_EMIT_OPT_NONE, exec_flags & EXEC_FLAG_IS_REPL); // Clear the parse tree because it has a heap pointer we don't need anymore. |
