# HG changeset patch # User paulb@localhost.localdomain # Date 1186871536 -7200 # Node ID a158544a692364b3b58cde7830619aa0aa5cc2ac # Parent feb9c0c7aa199c00668f82cad6440689ddfc9119 Made a Constant simplified node to replace previously generated invocations and the existing Constant class. Added consumed_args to the Raise simplified node. diff -r feb9c0c7aa19 -r a158544a6923 simplify/annotate.py --- a/simplify/annotate.py Mon Aug 06 00:54:45 2007 +0200 +++ b/simplify/annotate.py Sun Aug 12 00:32:16 2007 +0200 @@ -121,9 +121,9 @@ types possible when the means of constructing the namespace may depend on run-time behaviour. - Covered: Assign, CheckType, Conditional, Global, Import, InvokeRef, - InvokeFunction, LoadAttr, LoadExc, LoadName, LoadRef, LoadTemp, - Module, Not, Pass, Raise, ReleaseTemp, ReturnFromBlock, + Covered: Assign, CheckType, Conditional, Constant, Global, Import, + InvokeRef, InvokeFunction, LoadAttr, LoadExc, LoadName, LoadRef, + LoadTemp, Module, Not, Pass, Raise, ReleaseTemp, ReturnFromBlock, ReturnFromFunction, StoreAttr, StoreName, StoreTemp, Subprogram, Try. """ @@ -425,6 +425,17 @@ if exc_type not in body_namespace.raises: self.namespace.revoke_exception_type(exc_type) + def visitConstant(self, const): + + """ + Process the 'const' node, producing the appropriate type information + for the value represented. + """ + + attrs = self.get_builtin_instances(const, const.typename) + self.namespace.set_types(attrs) + self.annotate(const) + def visitGlobal(self, global_): """ @@ -1308,16 +1319,13 @@ # NOTE: Constant not added to table. - constant = Constant(name=repr(arg), value=arg) code += [ StoreTemp( instance=instance, - expr=InvokeFunction( + expr=Constant( instance=instance, - expr=LoadName( - instance=instance, - name=constant.typename - ) + name=repr(arg), + value=arg ), index="const" ), diff -r feb9c0c7aa19 -r a158544a6923 simplify/ast.py --- a/simplify/ast.py Mon Aug 06 00:54:45 2007 +0200 +++ b/simplify/ast.py Sun Aug 12 00:32:16 2007 +0200 @@ -775,12 +775,12 @@ def _visitConst(self, node, value): key = "%s-%s" % (value.__class__.__name__, value) + if node is not None: + result = Constant(node, 1, name=repr(value), value=value) + else: + result = Constant(name=repr(value), value=value) if not self.constants.has_key(key): - self.constants[key] = Constant(name=repr(value), value=value) - if node is not None: - result = InvokeFunction(node, 1, expr=LoadName(name=self.constants[key].typename)) - else: - result = InvokeFunction(expr=LoadName(name=self.constants[key].typename)) + self.constants[key] = result return result def visitContinue(self, continue_): diff -r feb9c0c7aa19 -r a158544a6923 simplify/simplified/data.py --- a/simplify/simplified/data.py Mon Aug 06 00:54:45 2007 +0200 +++ b/simplify/simplified/data.py Sun Aug 12 00:32:16 2007 +0200 @@ -261,15 +261,6 @@ else: raise ValueError, "__class__" -class Constant: - - "A constant initialised with a type name for future processing." - - def __init__(self, name, value): - self.name = name - self.value = value - self.typename = self.value.__class__.__name__ - class Attribute: """ diff -r feb9c0c7aa19 -r a158544a6923 simplify/simplified/program.py --- a/simplify/simplified/program.py Mon Aug 06 00:54:45 2007 +0200 +++ b/simplify/simplified/program.py Sun Aug 12 00:32:16 2007 +0200 @@ -332,6 +332,16 @@ class Invoke(Node): "An invocation." class MakeTuple(Node): "Make a tuple object." +class Constant(Node): + + "A constant initialised with a type name for future processing." + + def __init__(self, original=None, defining=0, name=None, value=None, *args, **kw): + Node.__init__(self, original, defining, *args, **kw) + self.name = name + self.value = value + self.typename = self.value.__class__.__name__ + # There are two types of return node: return from function and return from # block. @@ -378,6 +388,7 @@ Invoke.__init__(self, original, defining, expr=expr, traceback=traceback, **kw) self.share_locals = 0 + self.consumed_args = {} self.raises = set() class InvokeFunction(Invoke):