Author: David Schneider <david.schnei...@picle.org> Branch: Changeset: r44:666653c3a8e7 Date: 2011-09-22 15:04 +0200 http://bitbucket.org/pypy/lang-io/changeset/666653c3a8e7/
Log: implemented special version of updateSlot for Locals objects diff --git a/io/locals.py b/io/locals.py new file mode 100644 --- /dev/null +++ b/io/locals.py @@ -0,0 +1,14 @@ +from io.register import register_method + +@register_method('Locals', 'updateSlot') +def locals_update_slot(space, w_target, w_message, w_context): + slotname = w_message.arguments[0].eval(space, w_target, w_context).value + assert w_target.lookup(slotname) is not None + + if slotname in w_target.slots: + w_value = w_message.arguments[1].eval(space, w_target, w_context) + w_target.slots[slotname] = w_value + return w_value + else: + w_self = w_target.lookup('self') + return w_message.eval(space, w_self, w_context) diff --git a/io/model.py b/io/model.py --- a/io/model.py +++ b/io/model.py @@ -47,7 +47,7 @@ def __repr__(self): """NOT RPYTHON""" - return "<W_Object slots=%s>" % (self.slots.keys(),) + return "<%s slots=%s>" % (self.__class__.__name__, self.slots.keys(),) class W_Number(W_Object): """Number""" @@ -297,10 +297,10 @@ w_locals.slots[args[i]] = space.w_nil if self.activateable: - w_locals.protos = [w_receiver] + w_locals.protos.append(w_receiver) w_locals.slots['self'] = w_receiver else: - w_locals.protos = [w_context] + w_locals.protos.append(w_context) w_locals.slots['self'] = w_context w_locals.slots['call'] = w_call diff --git a/io/objspace.py b/io/objspace.py --- a/io/objspace.py +++ b/io/objspace.py @@ -13,6 +13,7 @@ import io.coroutine import io.sequence import io.compiler +import io.locals class ObjSpace(object): """docstring for ObjSpace""" @@ -79,6 +80,8 @@ self.init_w_compiler() + self.init_w_locals() + def init_w_map(self): for key, function in cfunction_definitions['Map'].items(): self.w_map.slots[key] = W_CFunction(self, function) @@ -99,6 +102,10 @@ for key, function in cfunction_definitions['List'].items(): self.w_list.slots[key] = W_CFunction(self, function) + def init_w_locals(self): + for key, function in cfunction_definitions['Locals'].items(): + self.w_locals.slots[key] = W_CFunction(self, function) + def init_w_core(self): self.w_core.protos.append(self.w_object) self.w_core.slots['Locals'] = self.w_locals diff --git a/io/test/test_locals.py b/io/test/test_locals.py new file mode 100644 --- /dev/null +++ b/io/test/test_locals.py @@ -0,0 +1,22 @@ +from io.interpreter import parse, interpret + +def test_updateSlot_in_self(): + inp = """a := Object clone + a foo := 5 + a bar := method(foo = 10) + a bar + a foo + """ + res, space = interpret(inp) + assert res.number_value == 10 + assert space.w_lobby.slots['a'].slots['foo'].number_value == 10 + +def test_updateSlot_in_locals(): + inp = """a := Object clone + a foo := 5 + a bar := method(foo := foo; foo = 10) + a bar + """ + res, space = interpret(inp) + assert res.number_value == 10 + assert space.w_lobby.slots['a'].slots['foo'].number_value == 5 _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit