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.
This commit is contained in:
Damien George
2018-09-15 22:37:07 +10:00
parent f12e039c2b
commit 93d71c5436
4 changed files with 62 additions and 28 deletions

View File

@@ -0,0 +1,19 @@
# test that viper functions capture their globals context
gl = {}
exec("""
@micropython.viper
def f():
return x
""", gl)
# x is not yet in the globals, f should not see it
try:
print(gl['f']())
except NameError:
print('NameError')
# x is in globals, f should now see it
gl['x'] = 123
print(gl['f']())

View File

@@ -0,0 +1,2 @@
NameError
123