1.1 --- a/annotate.py Sun Apr 01 01:24:50 2007 +0200
1.2 +++ b/annotate.py Sun Apr 01 17:43:20 2007 +0200
1.3 @@ -70,19 +70,19 @@
1.4 def __init__(self):
1.5 self.count = 0
1.6
1.7 - def init(self, node):
1.8 + def init(self, node, attr="types"):
1.9
1.10 "Initialise a 'node' for annotation."
1.11
1.12 - if not hasattr(node, "types"):
1.13 - node.types = []
1.14 + if not hasattr(node, attr):
1.15 + setattr(node, attr, [])
1.16
1.17 - def annotate(self, node, types):
1.18 + def annotate(self, node, types, attr="types"):
1.19
1.20 "Annotate the given 'node' with the given 'types'."
1.21
1.22 - self.init(node)
1.23 - self.combine(node.types, types)
1.24 + self.init(node, attr)
1.25 + self.combine(getattr(node, attr), types)
1.26
1.27 def combine(self, target, types):
1.28
1.29 @@ -164,11 +164,6 @@
1.30 self.namespace = None
1.31 self.module = module
1.32
1.33 - # Give constants their own namespace.
1.34 -
1.35 - for value, constant in module.simplifier.constants.items():
1.36 - constant.namespace = Namespace()
1.37 -
1.38 # Process the module, supplying builtins if possible.
1.39
1.40 self.builtins = builtins
1.41 @@ -276,10 +271,8 @@
1.42 "Extract results from the namespace."
1.43
1.44 result.namespace = self.namespace
1.45 - if hasattr(result, "raises"):
1.46 - combine(result.raises, self.namespace.raises)
1.47 - if hasattr(result, "returns"):
1.48 - combine(result.returns, self.namespace.returns)
1.49 + self.system.annotate(result, self.namespace.raises, "raises")
1.50 + self.system.annotate(result, self.namespace.returns, "returns")
1.51 if hasattr(result, "return_locals"):
1.52 combine(result.return_locals, self.namespace.return_locals)
1.53
1.54 @@ -1333,37 +1326,19 @@
1.55
1.56 # NOTE: Constant not added to table.
1.57
1.58 - constant = Constant(
1.59 - instance=instance,
1.60 - name=repr(arg), value=arg, namespace=Namespace()
1.61 - )
1.62 - #constant.namespace.store("__class__", self.get_builtin_instances(invocation, constant.typename))
1.63 + constant = Constant(name=repr(arg), value=arg)
1.64 code += [
1.65 StoreTemp(
1.66 instance=instance,
1.67 - expr=LoadRef(
1.68 + expr=InvokeFunction(
1.69 instance=instance,
1.70 - ref=constant
1.71 + expr=LoadName(
1.72 + instance=instance,
1.73 + name=constant.typename
1.74 + )
1.75 ),
1.76 index="const"
1.77 ),
1.78 - StoreAttr(
1.79 - instance=instance,
1.80 - lvalue=LoadTemp(
1.81 - instance=instance,
1.82 - index="const"
1.83 - ),
1.84 - name="__class__",
1.85 - expr=LoadAttr(
1.86 - instance=instance,
1.87 - expr=LoadRef(
1.88 - instance=instance,
1.89 - ref=self.builtins
1.90 - ),
1.91 - name=constant.typename,
1.92 - nstype="module",
1.93 - )
1.94 - ),
1.95 InvokeFunction(
1.96 invocation.original,
1.97 instance=instance,
2.1 --- a/lib/builtins.py Sun Apr 01 01:24:50 2007 +0200
2.2 +++ b/lib/builtins.py Sun Apr 01 17:43:20 2007 +0200
2.3 @@ -31,7 +31,7 @@
2.4 return self.__add__(other)
2.5
2.6 class bool:
2.7 - __atomic__ = 1
2.8 + __atomic__ = object
2.9
2.10 def __bool__(self):
2.11 return self
2.12 @@ -72,7 +72,7 @@
2.13 pass
2.14
2.15 class float:
2.16 - __atomic__ = 1
2.17 + __atomic__ = object
2.18
2.19 def __init__(self, number_or_string=None):
2.20 pass
2.21 @@ -290,7 +290,7 @@
2.22 return self != 0
2.23
2.24 class int:
2.25 - __atomic__ = 1
2.26 + __atomic__ = object
2.27
2.28 def __init__(self, number_or_string=None):
2.29 pass
2.30 @@ -526,7 +526,7 @@
2.31 return bool()
2.32
2.33 class long:
2.34 - __atomic__ = 1
2.35 + __atomic__ = object
2.36
2.37 def __init__(self, number_or_string=None):
2.38 pass
2.39 @@ -688,7 +688,7 @@
2.40 return self != 0
2.41
2.42 class none:
2.43 - __atomic__ = 1
2.44 + __atomic__ = object
2.45
2.46 def __bool__(self):
2.47 return False
2.48 @@ -707,7 +707,7 @@
2.49 self.step = step
2.50
2.51 class str:
2.52 - __atomic__ = 1
2.53 + __atomic__ = object
2.54
2.55 def __init__(self, x=None):
2.56 x.__str__()
2.57 @@ -887,22 +887,22 @@
2.58 pass
2.59
2.60 class AssertionError(Exception):
2.61 - __atomic__ = 1
2.62 + __atomic__ = object
2.63
2.64 class AttributeError(Exception):
2.65 - __atomic__ = 1
2.66 + __atomic__ = object
2.67
2.68 class IndexError(Exception):
2.69 - __atomic__ = 1
2.70 + __atomic__ = object
2.71
2.72 class StopIteration(Exception):
2.73 - __atomic__ = 1
2.74 + __atomic__ = object
2.75
2.76 class TypeError(Exception):
2.77 - __atomic__ = 1
2.78 + __atomic__ = object
2.79
2.80 class NotImplementedType:
2.81 - __atomic__ = 1
2.82 + __atomic__ = object
2.83
2.84 # General functions.
2.85
3.1 --- a/simplified.py Sun Apr 01 01:24:50 2007 +0200
3.2 +++ b/simplified.py Sun Apr 01 17:43:20 2007 +0200
3.3 @@ -639,7 +639,9 @@
3.4 A Python class which provides multiple instances for different versions of
3.5 methods. In order to avoid unbounded instance production (since new
3.6 instances cause new copies of methods which in turn would cause new
3.7 - instances),
3.8 + instances), a relations dictionary is maintained which attempts to map
3.9 + "requesting instances" to existing instances, suggesting such instances in
3.10 + preference to new ones.
3.11 """
3.12
3.13 def __init__(self, *args, **kw):
4.1 --- a/simplify.py Sun Apr 01 01:24:50 2007 +0200
4.2 +++ b/simplify.py Sun Apr 01 17:43:20 2007 +0200
4.3 @@ -107,27 +107,7 @@
4.4 """
4.5
4.6 result = self.module = Module(module, 1, name=name)
4.7 - module_code = self.dispatch(module.node)
4.8 -
4.9 - # NOTE: Constant initialisation necessary for annotation but perhaps
4.10 - # NOTE: redundant in the program.
4.11 -
4.12 - init_code = []
4.13 - for value, constant in self.constants.items():
4.14 - init_code.append(
4.15 - StoreAttr(
4.16 - lvalue=LoadRef(ref=constant),
4.17 - name="__class__",
4.18 - expr=LoadName(name=constant.typename)
4.19 - )
4.20 - )
4.21 -
4.22 - # NOTE: Hack to ensure correct initialisation of constants.
4.23 -
4.24 - if self.builtins:
4.25 - result.code = module_code + init_code
4.26 - else:
4.27 - result.code = init_code + module_code
4.28 + result.code = self.dispatch(module.node)
4.29 return result
4.30
4.31 # Node transformations.
4.32 @@ -760,7 +740,7 @@
4.33 key = "%s-%s" % (const.value.__class__.__name__, const.value)
4.34 if not self.constants.has_key(key):
4.35 self.constants[key] = Constant(name=repr(const.value), value=const.value)
4.36 - result = LoadRef(const, 1, ref=self.constants[key])
4.37 + result = InvokeFunction(const, 1, expr=LoadName(name=self.constants[key].typename))
4.38 return result
4.39
4.40 def visitContinue(self, continue_):
4.41 @@ -768,10 +748,10 @@
4.42 return result
4.43
4.44 def visitDict(self, dict):
4.45 - result = InvokeFunction(dict, 1, expr=LoadName(name="dict"), star=None, dstar=None)
4.46 + result = InvokeFunction(dict, 1, expr=LoadName(name="dict"))
4.47 args = []
4.48 for key, value in dict.items:
4.49 - tuple = InvokeFunction(dict, expr=LoadName(name="tuple"), star=None, dstar=None)
4.50 + tuple = InvokeFunction(dict, expr=LoadName(name="tuple"))
4.51 tuple.set_args([self.dispatch(key), self.dispatch(value)])
4.52 args.append(tuple)
4.53 result.set_args(args)
4.54 @@ -810,7 +790,7 @@
4.55
4.56 def _visitFor(self, node, body_stmt, else_=None):
4.57
4.58 - subprogram = Subprogram(name=None, module=self.module, internal=1, returns_value=0, params=[], star=None, dstar=None)
4.59 + subprogram = Subprogram(name=None, module=self.module, internal=1, returns_value=0, params=[])
4.60 self.current_subprograms.append(subprogram)
4.61
4.62 # Always return from conditional sections/subprograms.
4.63 @@ -1912,7 +1892,7 @@
4.64 return result
4.65
4.66 def _visitBuiltin(self, builtin, name):
4.67 - result = InvokeFunction(builtin, 1, expr=LoadName(name=name), args=self.dispatches(builtin.nodes), star=None, dstar=None)
4.68 + result = InvokeFunction(builtin, 1, expr=LoadName(name=name), args=self.dispatches(builtin.nodes))
4.69 return result
4.70
4.71 def _visitUnary(self, unary, name):