1.1 --- a/simplify/ast.py Sun Jun 24 21:55:51 2007 +0200
1.2 +++ b/simplify/ast.py Mon Jun 25 00:32:56 2007 +0200
1.3 @@ -125,7 +125,21 @@
1.4 """
1.5
1.6 result = self.module = Module(module, 1, name=name)
1.7 - result.code = self.dispatch(module.node)
1.8 + result.code = []
1.9 +
1.10 + # Add an initialiser for the module name first for non-builtins.
1.11 +
1.12 + if self.builtins:
1.13 + result.code += self.dispatch(module.node)
1.14 +
1.15 + result.code += [
1.16 + StoreName(name="__name__", expr=self._visitConst(None, name))
1.17 + ]
1.18 +
1.19 + # Add an initialiser for the module name last for builtins.
1.20 +
1.21 + if not self.builtins:
1.22 + result.code += self.dispatch(module.node)
1.23 return result
1.24
1.25 # Node transformations.
1.26 @@ -767,10 +781,16 @@
1.27 return result
1.28
1.29 def visitConst(self, const):
1.30 - key = "%s-%s" % (const.value.__class__.__name__, const.value)
1.31 + return self._visitConst(const, const.value)
1.32 +
1.33 + def _visitConst(self, node, value):
1.34 + key = "%s-%s" % (value.__class__.__name__, value)
1.35 if not self.constants.has_key(key):
1.36 - self.constants[key] = Constant(name=repr(const.value), value=const.value)
1.37 - result = InvokeFunction(const, 1, expr=LoadName(name=self.constants[key].typename))
1.38 + self.constants[key] = Constant(name=repr(value), value=value)
1.39 + if node is not None:
1.40 + result = InvokeFunction(node, 1, expr=LoadName(name=self.constants[key].typename))
1.41 + else:
1.42 + result = InvokeFunction(expr=LoadName(name=self.constants[key].typename))
1.43 return result
1.44
1.45 def visitContinue(self, continue_):