Commit 77a4a0e7 authored by Vitja Makarov's avatar Vitja Makarov

Add LocalsExprNode

parent cf7f1e1a
...@@ -5454,6 +5454,16 @@ class GlobalsExprNode(AtomicExprNode): ...@@ -5454,6 +5454,16 @@ class GlobalsExprNode(AtomicExprNode):
code.error_goto_if_null(self.result(), self.pos))) code.error_goto_if_null(self.result(), self.pos)))
code.put_gotref(self.result()) code.put_gotref(self.result())
class LocalsExprNode(DictNode):
def __init__(self, pos, env):
local_vars = [var.name for var in env.entries.values() if var.name]
items = [DictItemNode(pos, key=IdentifierStringNode(pos, value=var),
value=NameNode(pos, name=var, allow_null=True))
for var in local_vars]
DictNode.__init__(self, pos, key_value_pairs=items,
exclude_null_values=True)
#------------------------------------------------------------------- #-------------------------------------------------------------------
# #
# Unary operator nodes # Unary operator nodes
......
...@@ -2258,7 +2258,6 @@ class TransformBuiltinMethods(EnvTransform): ...@@ -2258,7 +2258,6 @@ class TransformBuiltinMethods(EnvTransform):
# not the builtin # not the builtin
return node return node
pos = node.pos pos = node.pos
local_names = [ var.name for var in lenv.entries.values() if var.name ]
if func_name in ('locals', 'vars'): if func_name in ('locals', 'vars'):
if func_name == 'locals' and len(node.args) > 0: if func_name == 'locals' and len(node.args) > 0:
error(self.pos, "Builtin 'locals()' called with wrong number of args, expected 0, got %d" error(self.pos, "Builtin 'locals()' called with wrong number of args, expected 0, got %d"
...@@ -2270,11 +2269,7 @@ class TransformBuiltinMethods(EnvTransform): ...@@ -2270,11 +2269,7 @@ class TransformBuiltinMethods(EnvTransform):
% len(node.args)) % len(node.args))
if len(node.args) > 0: if len(node.args) > 0:
return node # nothing to do return node # nothing to do
items = [ ExprNodes.DictItemNode(pos, return ExprNodes.LocalsExprNode(pos, lenv)
key=ExprNodes.IdentifierStringNode(pos, value=var),
value=ExprNodes.NameNode(pos, name=var, allow_null=True))
for var in local_names ]
return ExprNodes.DictNode(pos, key_value_pairs=items, exclude_null_values=True)
else: # dir() else: # dir()
if len(node.args) > 1: if len(node.args) > 1:
error(self.pos, "Builtin 'dir()' called with wrong number of args, expected 0-1, got %d" error(self.pos, "Builtin 'dir()' called with wrong number of args, expected 0-1, got %d"
...@@ -2282,6 +2277,7 @@ class TransformBuiltinMethods(EnvTransform): ...@@ -2282,6 +2277,7 @@ class TransformBuiltinMethods(EnvTransform):
if len(node.args) > 0: if len(node.args) > 0:
# optimised in Builtin.py # optimised in Builtin.py
return node return node
local_names = [ var.name for var in lenv.entries.values() if var.name ]
items = [ ExprNodes.IdentifierStringNode(pos, value=var) items = [ ExprNodes.IdentifierStringNode(pos, value=var)
for var in local_names ] for var in local_names ]
return ExprNodes.ListNode(pos, args=items) return ExprNodes.ListNode(pos, args=items)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment