summaryrefslogtreecommitdiff
path: root/py/compile.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2018-09-15 22:37:07 +1000
committerDamien George <damien.p.george@gmail.com>2018-09-15 22:39:27 +1000
commit93d71c5436488d52d47d165dd020217415e79a64 (patch)
treef00d9f11c16d8ea52d3574603a834bf912cddfab /py/compile.c
parentf12e039c2bb805364f55b1fb81b92c1b03c9104a (diff)
py/emitnative: Make viper funcs run with their correct globals context.
Viper functions will now capture the globals at the point they were defined and use these globals when executing.
Diffstat (limited to 'py/compile.c')
-rw-r--r--py/compile.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/py/compile.c b/py/compile.c
index ec6b463c0..5748256f2 100644
--- a/py/compile.c
+++ b/py/compile.c
@@ -3287,7 +3287,12 @@ STATIC void scope_compute_things(scope_t *scope) {
#if MICROPY_EMIT_NATIVE
if (id->kind == ID_INFO_KIND_GLOBAL_EXPLICIT) {
// This function makes a reference to a global variable
- scope->scope_flags |= MP_SCOPE_FLAG_REFGLOBALS;
+ if (scope->emit_options == MP_EMIT_OPT_VIPER
+ && mp_native_type_from_qstr(id->qst) >= MP_NATIVE_TYPE_INT) {
+ // A casting operator in viper mode, not a real global reference
+ } else {
+ scope->scope_flags |= MP_SCOPE_FLAG_REFGLOBALS;
+ }
}
#endif
// params always count for 1 local, even if they are a cell