1.1 --- a/simplified.py Fri Jul 28 00:20:57 2006 +0200
1.2 +++ b/simplified.py Sun Jul 30 02:00:33 2006 +0200
1.3 @@ -75,6 +75,7 @@
1.4 else_ Any conditional code depending on the failure of a test.
1.5 finally_ Any code which will be executed regardless.
1.6 code Any unconditional code.
1.7 + choices Any choices which may be included in the final program.
1.8 """
1.9
1.10 def __init__(self, original=None, **kw):
1.11 @@ -122,7 +123,7 @@
1.12 self._pprint(indent + 2, "( ", "structure '%s'" % self.structure.name)
1.13 if hasattr(self, "test"):
1.14 self.test.pprint(indent + 2, "? ")
1.15 - for attr in "code", "body", "else_", "finally_":
1.16 + for attr in "code", "body", "else_", "finally_", "choices":
1.17 if hasattr(self, attr) and getattr(self, attr):
1.18 self._pprint(indent, "", "{ (%s)" % attr)
1.19 for node in getattr(self, attr):
1.20 @@ -169,6 +170,7 @@
1.21 class Try(Node): "A try...except...else...finally grouping node."
1.22 class Raise(Node): "An exception raising node."
1.23 class Not(Node): "A negation of an expression."
1.24 +class Choice(Node): "A special node which indicates a choice of expressions."
1.25
1.26 # Special non-program nodes.
1.27
1.28 @@ -190,61 +192,4 @@
1.29 class Instance(Structure): "An instance."
1.30 class Constant(Instance): "A constant."
1.31
1.32 -class Namespace:
1.33 -
1.34 - """
1.35 - A local namespace which may either relate to a genuine set of function
1.36 - locals or the initialisation of a structure.
1.37 - """
1.38 -
1.39 - def __init__(self, structure=None):
1.40 - self.structure = structure
1.41 - if structure is not None:
1.42 - self.local = "structure"
1.43 - else:
1.44 - self.local = "local"
1.45 - self.names = {}
1.46 - self.not_local = []
1.47 -
1.48 - def make_global(self, name):
1.49 - if name not in self.not_local:
1.50 - self.not_local.append(name)
1.51 -
1.52 - def find_for_store(self, name):
1.53 - if name not in self.not_local:
1.54 - return self.local
1.55 - else:
1.56 - return "global"
1.57 -
1.58 - def find_for_load(self, name):
1.59 - if name not in self.not_local and self.names.has_key(name):
1.60 - return self.local
1.61 - else:
1.62 - return "global"
1.63 -
1.64 - def store(self, name, types=None):
1.65 - if name not in self.not_local:
1.66 - self.names[name] = types
1.67 - else:
1.68 - raise KeyError, name
1.69 -
1.70 - def load(self, name):
1.71 - if name in self.not_local or not self.names.has_key(name):
1.72 - raise KeyError, name
1.73 - else:
1.74 - return self.names[name]
1.75 -
1.76 - def merge(self, namespace):
1.77 - self.merge_items(namespace.names.items())
1.78 -
1.79 - def merge_items(self, items):
1.80 - for name, types in items:
1.81 - if not self.names.has_key(name):
1.82 - self.names[name] = types
1.83 - else:
1.84 - existing = self.names[name]
1.85 - for type in types:
1.86 - if type not in existing:
1.87 - existing.append(type)
1.88 -
1.89 # vim: tabstop=4 expandtab shiftwidth=4