Skip to content

Commit

Permalink
Added 'globals' to the context
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitrii-eremin committed Dec 28, 2016
1 parent 992d91a commit 792b266
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions pythonlua/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ def __init__(self, values=None):
"token_end_mode": TokenEndMode.LINE_FEED,
"class_name": "",
"locals": SymbolsStack(),
"globals": SymbolsStack(), # Not working yet
}

self.ctx_stack = [values]
Expand Down
6 changes: 6 additions & 0 deletions pythonlua/nodevisitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,12 @@ def visit_For(self, node):
self.emit(line.format(**values))
self.visit_all(node.body)
self.emit("end")

def visit_Global(self, node):
"""Visit globals"""
last_ctx = self.context.last()
for name in node.names:
last_ctx["globals"].add_symbol(name)

def visit_If(self, node):
"""Visit if"""
Expand Down
9 changes: 9 additions & 0 deletions tests/global.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
foo = 42

def bar():
global foo
foo = 34

print("foo = ", foo)
bar()
print("foo = ", foo)
Empty file added tests/global.py.expected
Empty file.

0 comments on commit 792b266

Please sign in to comment.