1.1 --- a/simplify/annotate.py Mon Aug 06 00:54:45 2007 +0200
1.2 +++ b/simplify/annotate.py Sun Aug 12 00:32:16 2007 +0200
1.3 @@ -121,9 +121,9 @@
1.4 types possible when the means of constructing the namespace may depend on
1.5 run-time behaviour.
1.6
1.7 - Covered: Assign, CheckType, Conditional, Global, Import, InvokeRef,
1.8 - InvokeFunction, LoadAttr, LoadExc, LoadName, LoadRef, LoadTemp,
1.9 - Module, Not, Pass, Raise, ReleaseTemp, ReturnFromBlock,
1.10 + Covered: Assign, CheckType, Conditional, Constant, Global, Import,
1.11 + InvokeRef, InvokeFunction, LoadAttr, LoadExc, LoadName, LoadRef,
1.12 + LoadTemp, Module, Not, Pass, Raise, ReleaseTemp, ReturnFromBlock,
1.13 ReturnFromFunction, StoreAttr, StoreName, StoreTemp, Subprogram,
1.14 Try.
1.15 """
1.16 @@ -425,6 +425,17 @@
1.17 if exc_type not in body_namespace.raises:
1.18 self.namespace.revoke_exception_type(exc_type)
1.19
1.20 + def visitConstant(self, const):
1.21 +
1.22 + """
1.23 + Process the 'const' node, producing the appropriate type information
1.24 + for the value represented.
1.25 + """
1.26 +
1.27 + attrs = self.get_builtin_instances(const, const.typename)
1.28 + self.namespace.set_types(attrs)
1.29 + self.annotate(const)
1.30 +
1.31 def visitGlobal(self, global_):
1.32
1.33 """
1.34 @@ -1308,16 +1319,13 @@
1.35
1.36 # NOTE: Constant not added to table.
1.37
1.38 - constant = Constant(name=repr(arg), value=arg)
1.39 code += [
1.40 StoreTemp(
1.41 instance=instance,
1.42 - expr=InvokeFunction(
1.43 + expr=Constant(
1.44 instance=instance,
1.45 - expr=LoadName(
1.46 - instance=instance,
1.47 - name=constant.typename
1.48 - )
1.49 + name=repr(arg),
1.50 + value=arg
1.51 ),
1.52 index="const"
1.53 ),
2.1 --- a/simplify/ast.py Mon Aug 06 00:54:45 2007 +0200
2.2 +++ b/simplify/ast.py Sun Aug 12 00:32:16 2007 +0200
2.3 @@ -775,12 +775,12 @@
2.4
2.5 def _visitConst(self, node, value):
2.6 key = "%s-%s" % (value.__class__.__name__, value)
2.7 + if node is not None:
2.8 + result = Constant(node, 1, name=repr(value), value=value)
2.9 + else:
2.10 + result = Constant(name=repr(value), value=value)
2.11 if not self.constants.has_key(key):
2.12 - self.constants[key] = Constant(name=repr(value), value=value)
2.13 - if node is not None:
2.14 - result = InvokeFunction(node, 1, expr=LoadName(name=self.constants[key].typename))
2.15 - else:
2.16 - result = InvokeFunction(expr=LoadName(name=self.constants[key].typename))
2.17 + self.constants[key] = result
2.18 return result
2.19
2.20 def visitContinue(self, continue_):
3.1 --- a/simplify/simplified/data.py Mon Aug 06 00:54:45 2007 +0200
3.2 +++ b/simplify/simplified/data.py Sun Aug 12 00:32:16 2007 +0200
3.3 @@ -261,15 +261,6 @@
3.4 else:
3.5 raise ValueError, "__class__"
3.6
3.7 -class Constant:
3.8 -
3.9 - "A constant initialised with a type name for future processing."
3.10 -
3.11 - def __init__(self, name, value):
3.12 - self.name = name
3.13 - self.value = value
3.14 - self.typename = self.value.__class__.__name__
3.15 -
3.16 class Attribute:
3.17
3.18 """
4.1 --- a/simplify/simplified/program.py Mon Aug 06 00:54:45 2007 +0200
4.2 +++ b/simplify/simplified/program.py Sun Aug 12 00:32:16 2007 +0200
4.3 @@ -332,6 +332,16 @@
4.4 class Invoke(Node): "An invocation."
4.5 class MakeTuple(Node): "Make a tuple object."
4.6
4.7 +class Constant(Node):
4.8 +
4.9 + "A constant initialised with a type name for future processing."
4.10 +
4.11 + def __init__(self, original=None, defining=0, name=None, value=None, *args, **kw):
4.12 + Node.__init__(self, original, defining, *args, **kw)
4.13 + self.name = name
4.14 + self.value = value
4.15 + self.typename = self.value.__class__.__name__
4.16 +
4.17 # There are two types of return node: return from function and return from
4.18 # block.
4.19
4.20 @@ -378,6 +388,7 @@
4.21
4.22 Invoke.__init__(self, original, defining, expr=expr, traceback=traceback, **kw)
4.23 self.share_locals = 0
4.24 + self.consumed_args = {}
4.25 self.raises = set()
4.26
4.27 class InvokeFunction(Invoke):