1.1 --- a/micropython/ast.py Mon Sep 01 01:32:32 2008 +0200
1.2 +++ b/micropython/ast.py Thu Sep 04 19:44:39 2008 +0200
1.3 @@ -159,12 +159,12 @@
1.4
1.5 # Make an object.
1.6
1.7 - self.new_op(MakeObject(len(cls.instance_attributes())))
1.8 + self.make_object(cls, len(cls.instance_attributes()))
1.9 self.new_op(StoreFrame(0))
1.10
1.11 # Invoke the appropriate initialiser.
1.12
1.13 - self.new_op(LoadAddress(init_method))
1.14 + self.new_op(LoadConst(init_method))
1.15 self.new_op(LoadCallable())
1.16 self.new_op(JumpWithFrame())
1.17
1.18 @@ -176,6 +176,19 @@
1.19
1.20 return self.code
1.21
1.22 + # Allocation-related methods.
1.23 +
1.24 + def make_object(self, cls, n):
1.25 +
1.26 + """
1.27 + Request a new object with the given class 'cls' and with 'n' attributes.
1.28 + """
1.29 +
1.30 + # NOTE: Object headers are one location.
1.31 +
1.32 + self.new_op(LoadConst(cls))
1.33 + self.new_op(MakeObject(n + 1))
1.34 +
1.35 # Name-related methods.
1.36
1.37 def get_scope(self, name):
1.38 @@ -195,6 +208,9 @@
1.39
1.40 self.new_op(LoadAddress(self.get_builtin(name, node)))
1.41
1.42 + def get_builtin_class(self, name, node):
1.43 + return self.get_builtin(name, node).value
1.44 +
1.45 def get_builtin(self, name, node):
1.46
1.47 """
1.48 @@ -418,7 +434,7 @@
1.49 instruction).
1.50 """
1.51
1.52 - return isinstance(instruction, (LoadConst, LoadName, LoadTemp, LoadResult, LoadAddress, MakeObject))
1.53 + return isinstance(instruction, (LoadConst, LoadName, LoadTemp, LoadResult, LoadAddress))
1.54
1.55 def _is_simple_input_user(self, instruction):
1.56
1.57 @@ -430,7 +446,7 @@
1.58 StoreAttr, StoreAttrIndex, StoreCallable, # as the object being referenced
1.59 LoadCallable,
1.60 TestIdentity, TestIdentityAddress, CheckSelf, # as one of the operands
1.61 - CheckFrame,
1.62 + CheckFrame, MakeObject,
1.63 LoadContext # as the object providing the result
1.64 ))
1.65
1.66 @@ -851,7 +867,7 @@
1.67 # to the __init__ method.
1.68
1.69 elif isinstance(target, Class):
1.70 - self.new_op(MakeObject(len(target.instance_attributes())))
1.71 + self.make_object(target, len(target.instance_attributes()))
1.72 self.new_op(StoreFrame(0))
1.73
1.74 # Otherwise omit the context.
1.75 @@ -1107,7 +1123,7 @@
1.76 "Make the invocation."
1.77
1.78 if isinstance(target, Class):
1.79 - self.new_op(LoadAddress(target.get_init_method()))
1.80 + self.new_op(LoadConst(target.get_init_method()))
1.81 else:
1.82 self.new_op(instruction)
1.83 self.new_op(LoadCallable())
1.84 @@ -1154,7 +1170,7 @@
1.85 dynamic = function.name is None
1.86
1.87 if dynamic:
1.88 - self.new_op(MakeObject(("function", len(attr_to_default))))
1.89 + self.make_object(self.get_builtin_class("function", function), len(attr_to_default))
1.90 temp = self.get_temp()
1.91
1.92 for attr, default in attr_to_default:
1.93 @@ -1398,7 +1414,7 @@
1.94
1.95 "Make a sequence of 'sequence_type' for the given program 'node'."
1.96
1.97 - self.new_op(MakeObject((sequence_type, len(node.nodes))))
1.98 + self.make_object(self.get_builtin(sequence_type, node), len(node.nodes))
1.99 temp = self.get_temp()
1.100
1.101 for i, n in enumerate(node.nodes):