diff options
Diffstat (limited to 'src/front/scope.py')
-rw-r--r-- | src/front/scope.py | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/src/front/scope.py b/src/front/scope.py index 533497d..6559a26 100644 --- a/src/front/scope.py +++ b/src/front/scope.py @@ -6,22 +6,39 @@ class Scope(object): def __init__(self): self.__dict__ = self.__shared_state + def set_function(self, name): + self.__current_function = name + def new(self, name, symbols = []): if getattr(self.__functions, name, None): raise ScopeError("multiple definitions of %s" % name) - self.__functions[name] = [] - self.__current_function = name - self.add(symbols) + self.__functions[name] = ([], []) + self.set_function(name) - def add(self, symbols): + def add(self, symbols, i): if type(symbols) != type([]): symbols = [symbols] for symbol in symbols: - if symbol not in self.__functions[self.__current_function]: - self.__functions[self.__current_function].append(symbol) + if symbol not in self.__functions[self.__current_function][i]: + self.__functions[self.__current_function][i].append(symbol) + + def add_params(self, symbols): + self.add(symbols, 0) + + def add_locals(self, symbols): + self.add(symbols, 1) def contains(self, name): - return name in self.__functions[self.__current_function] + return name in reduce(lambda x,y: x+y, self.__functions[self.__current_function]) + + def get_variable_offset(self, name): + try: + return self.__functions[self.__current_function][0].index(name) + 2 + except: + return -self.__functions[self.__current_function][1].index(name) - 1 + + def get_variables(self): + return self.__functions[self.__current_function] def __str__(self): return "<Scope: %s>" % str(self.__functions) |