Skip to content
Browse files

it is more useful to provide scope iterables than to provide methods …

…for checking if a name is in scope
  • Loading branch information...
1 parent 544ced0 commit e8f753c0a538279a94df9304cede19463f755e16 @thenewguy committed Feb 19, 2012
Showing with 17 additions and 10 deletions.
  1. +17 −10 pyjaco/compiler/__init__.py
View
27 pyjaco/compiler/__init__.py
@@ -61,6 +61,8 @@ def __init__(self, opts, **kwargs):
self._exceptions_stack = []
self._funcs_stack = []
+ self._scope_level = 0
+
self.opts = opts
self.shared_state = kwargs["shared_state"]
@@ -73,25 +75,30 @@ def push_scope(self):
self._classes = {}
self._exceptions_stack.append(self._exceptions)
self._exceptions = []
+ self._scope_level += 1
def pop_scope(self):
self._vars = self._vars_stack.pop()
self._funcs = self._funcs_stack.pop()
self._classes = self._classes_stack.pop()
self._exceptions = self._exceptions_stack.pop()
+ self._scope_level -= 1
+
+ @property
+ def scope_is_global(self):
+ return not self._scope_level
- def in_local_scope(self, name):
- if name in chain(self._vars, self._funcs, self._classes, self._exceptions):
- return True
- return False
+ @property
+ def local_scope(self):
+ return chain(self._vars, self._funcs, self._classes, self._exceptions)
- def in_global_scope(self, name):
- if name in chain(*chain(self._vars_stack, self._classes_stack, self._exceptions_stack, self._funcs_stack)):
- return True
- return False
+ @property
+ def global_scope(self):
+ return chain(*chain(self._vars_stack, self._classes_stack, self._exceptions_stack, self._funcs_stack))
- def in_scope(self, name):
- return self.in_local_scope(name) or self.in_global_scope(name)
+ @property
+ def scope(self, name):
+ return chain(self.local_scope, self.global_scope)
@property
def module(self):

0 comments on commit e8f753c

Please sign in to comment.
Something went wrong with that request. Please try again.