summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenedikt Böhm <bb@xnull.de>2009-06-09 08:44:42 +0200
committerBenedikt Böhm <bb@xnull.de>2009-06-09 08:44:42 +0200
commitd3b74248d53f19bc8f10510d3d44b68aa4883ab6 (patch)
tree4d7eb3a0acbffe59c8d774af38ae95c5b6b9de9f
parent91ae46d9f2087272d4bd27a2b12f52fd1d782caa (diff)
downloadswppy-d3b74248d53f19bc8f10510d3d44b68aa4883ab6.tar.gz
swppy-d3b74248d53f19bc8f10510d3d44b68aa4883ab6.tar.xz
swppy-d3b74248d53f19bc8f10510d3d44b68aa4883ab6.zip
simplify scope, symbol and types
-rw-r--r--src/front/scope.py24
-rw-r--r--src/front/symbol.py32
-rw-r--r--src/front/type.py12
3 files changed, 20 insertions, 48 deletions
diff --git a/src/front/scope.py b/src/front/scope.py
index 2cc3018..0df8729 100644
--- a/src/front/scope.py
+++ b/src/front/scope.py
@@ -1,20 +1,6 @@
-class Scope(object, DictMixin):
- def __init__(self, parent):
- self.parent = parent
- self.__symbols = {}
+class Scope(object):
+ __shared_state = {}
+ functions = {}
- def __getitem__(self, key):
- try:
- return self.__symbols[key]
- except KeyError:
- return self.parent[key]
-
- def __setitem__(self, key, item):
- self.__symbols[key] = item
-
- def keys(self):
- keys = self.__symbols.keys()
- for key in self.parent.keys():
- if key not in keys:
- keys.append(key)
- return keys
+ def __init__(self):
+ self.__dict__ = self.__shared_state
diff --git a/src/front/symbol.py b/src/front/symbol.py
index 879403f..b93b778 100644
--- a/src/front/symbol.py
+++ b/src/front/symbol.py
@@ -1,34 +1,8 @@
-class SymbolClass(object):
- def __init__(self, name):
- self.name = name
-
- def __str__(self):
- return self.name
-
- def __repr__(self):
- return "<SymbolClass: %s>" % self
-
-SymbolClass.CONST = SymbolClass("CONST")
-SymbolClass.VAR = SymbolClass("VAR")
-SymbolClass.FUNC = SymbolClass("FUNC")
-
-class SymbolType(object):
- def __init__(self, name):
- self.name = name
-
- def __str__(self):
- return self.name
-
- def __repr__(self):
- return "<SymbolType: %s>" % self
-
-SymbolType.INT = SymbolType("INT")
-SymbolType.BOOL = SymbolType("BOOL")
+from type import DataType
class Symbol(object):
- __slots__ = ['cls', 'type', 'value']
+ __slots__ = ['type', 'value']
- def __init__(self, value, type = SymbolType.INT, cls = SymbolClass.VAR):
+ def __init__(self, value, type = DataType.INT):
self.value = value
self.type = type
- self.cls = cls
diff --git a/src/front/type.py b/src/front/type.py
new file mode 100644
index 0000000..a8bd8c7
--- /dev/null
+++ b/src/front/type.py
@@ -0,0 +1,12 @@
+class DataType(object):
+ def __init__(self, name):
+ self.name = name
+
+ def __str__(self):
+ return self.name
+
+ def __repr__(self):
+ return "<DataType: %s>" % self
+
+DataType.INT = DataType("INT")
+DataType.BOOL = DataType("BOOL")