# HG changeset patch # User Paul Boddie # Date 1241138285 -7200 # Node ID eb7b56b0caa3f8cbce14518ee6e453d26f9e9e75 # Parent 79f8d72c8c78a6711dddae1be817f8e2980d3ef9 Added extra temporary storage to frames in order to let instantiators expand frames backwards when adding instances to revised frames. Simplified the AdjustFrame instruction, adding such an instruction at the end of instantiator functions. Reorganised the method invocation tests. Added an empty native function for object initialisation. diff -r 79f8d72c8c78 -r eb7b56b0caa3 micropython/ast.py --- a/micropython/ast.py Fri May 01 01:02:20 2009 +0200 +++ b/micropython/ast.py Fri May 01 02:38:05 2009 +0200 @@ -152,7 +152,7 @@ if unit.astnode is not None: self.dispatch(unit.astnode) - self.unit.temp_usage = self.max_temp_position + 1 + self.unit.temp_usage = self.max_temp_position + 2 # include space for instantiators to expand backwards self.unit.blocks = self.blocks return self.blocks @@ -191,6 +191,10 @@ self.new_op(LoadName(init_method.all_locals()["self"])) # load the context in the invocation frame self.new_op(StoreResult()) + + # Fix the current frame to release the storage slot at the beginning. + + self.new_op(AdjustFrame(1)) self.new_op(Return()) self.unit.blocks = self.blocks diff -r 79f8d72c8c78 -r eb7b56b0caa3 micropython/trans.py --- a/micropython/trans.py Fri May 01 01:02:20 2009 +0200 +++ b/micropython/trans.py Fri May 01 02:38:05 2009 +0200 @@ -235,7 +235,7 @@ on the 'extend' instruction. """ - ntemp = self.max_temp_position + 1 + ntemp = self.max_temp_position + 2 # include space for instantiators to expand backwards extend.attr = ntemp + node.unit.local_usage # NOTE: See get_code for similar code. # Code writing methods. diff -r 79f8d72c8c78 -r eb7b56b0caa3 rsvp.py --- a/rsvp.py Fri May 01 01:02:20 2009 +0200 +++ b/rsvp.py Fri May 01 02:38:05 2009 +0200 @@ -540,12 +540,7 @@ self.frame_stack.extend([None] * self.operand) def AdjustFrame(self): - if self.operand > 0: - self.frame_stack.append([None] * self.operand) - elif self.operand == -1: - self.invocation_sp_stack[-1] -= 1 - else: - raise Exception, "AdjustFrame %r" % self.operand + self.invocation_sp_stack[-1] += self.operand def Return(self): return self.pull_pc() @@ -720,11 +715,15 @@ self.result = list, list + def builtins_object_init(self): + pass + native_functions = { "__builtins__.int.__add__" : builtins_int_add, "__builtins__.int.__bool__" : builtins_int_bool, "__builtins__.bool.__bool__" : builtins_bool_bool, "__builtins__.list" : builtins_list_new, + "__builtins__.object.__init__" : builtins_object_init, } # vim: tabstop=4 expandtab shiftwidth=4 diff -r 79f8d72c8c78 -r eb7b56b0caa3 tests/call_method.py --- a/tests/call_method.py Fri May 01 01:02:20 2009 +0200 +++ b/tests/call_method.py Fri May 01 02:38:05 2009 +0200 @@ -2,23 +2,8 @@ class C: def __init__(self, x): - pass - - def f(self, a, b, c): - self.g(a) - m = self.g - m(b) - - def g(self, x): - C.h(self, x) - - def h(self, p): - pass + self.x = x c = C(123) -c.f(1, 2, 3) - -f = c.f -f(1, 2, 3) # vim: tabstop=4 expandtab shiftwidth=4 diff -r 79f8d72c8c78 -r eb7b56b0caa3 tests/call_method2.py --- a/tests/call_method2.py Fri May 01 01:02:20 2009 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,15 +0,0 @@ -#!/usr/bin/env python - -class C: - def f(self, a, b, c): - pass - -c = C() - -f = c.f -f(1, 2, 3) - -f = C.f -f(c, 1, 2, 3) - -# vim: tabstop=4 expandtab shiftwidth=4 diff -r 79f8d72c8c78 -r eb7b56b0caa3 tests/call_method3.py --- a/tests/call_method3.py Fri May 01 01:02:20 2009 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,12 +0,0 @@ -#!/usr/bin/env python - -class C: - def f(self, a, b, c): - pass - -c = C() - -f = C.f -f(c, 1, 2, 3) # test self argument - -# vim: tabstop=4 expandtab shiftwidth=4 diff -r 79f8d72c8c78 -r eb7b56b0caa3 tests/call_method_ref.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/call_method_ref.py Fri May 01 02:38:05 2009 +0200 @@ -0,0 +1,14 @@ +#!/usr/bin/env python + +class C: + def f(self, a, b, c): + self.a = a + self.b = b + self.c = c + +c = C() + +f = c.f +f(1, 2, 3) + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r 79f8d72c8c78 -r eb7b56b0caa3 tests/call_method_ref_internal.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/call_method_ref_internal.py Fri May 01 02:38:05 2009 +0200 @@ -0,0 +1,16 @@ +#!/usr/bin/env python + +class C: + def f(self, a, b, c): + m = self.g + m(a, b, c) + + def g(self, a, b, c): + self.a = a + self.b = b + self.c = c + +c = C() +c.f(1, 2, 3) + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r 79f8d72c8c78 -r eb7b56b0caa3 tests/call_method_self.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/call_method_self.py Fri May 01 02:38:05 2009 +0200 @@ -0,0 +1,15 @@ +#!/usr/bin/env python + +class C: + def f(self, a, b, c): + self.g(a, b, c) + + def g(self, a, b, c): + self.a = a + self.b = b + self.c = c + +c = C() +c.f(1, 2, 3) + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r 79f8d72c8c78 -r eb7b56b0caa3 tests/call_method_via_class.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/call_method_via_class.py Fri May 01 02:38:05 2009 +0200 @@ -0,0 +1,14 @@ +#!/usr/bin/env python + +class C: + def f(self, a, b, c): + self.a = a + self.b = b + self.c = c + +c = C() + +f = C.f +f(c, 1, 2, 3) # test self argument + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r 79f8d72c8c78 -r eb7b56b0caa3 tests/call_method_via_class_internal.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/call_method_via_class_internal.py Fri May 01 02:38:05 2009 +0200 @@ -0,0 +1,15 @@ +#!/usr/bin/env python + +class C: + def f(self, a, b, c): + C.h(self, a, b, c) + + def h(self, a, b, c): + self.a = a + self.b = b + self.c = c + +c = C() +c.f(1, 2, 3) + +# vim: tabstop=4 expandtab shiftwidth=4