Author: David Schneider <david.schnei...@picle.org> Branch: Changeset: r45:e3b24ae80e73 Date: 2011-09-22 18:01 +0200 http://bitbucket.org/pypy/lang-io/changeset/e3b24ae80e73/
Log: enable io implementation of newSlot diff --git a/io/io/A2_Object.io b/io/io/A2_Object.io --- a/io/io/A2_Object.io +++ b/io/io/A2_Object.io @@ -331,7 +331,6 @@ and sets it's default the value aValue. Returns self. For example, newSlot("foo", 1) would create slot named foo with the value 1 as well as a setter method setFoo(). */ -/* newSlot := method(name, value, doc, getSlot("self") setSlot(name, getSlot("value")) getSlot("self") setSlot("set" .. name asCapitalized, @@ -339,7 +338,6 @@ //if(doc, getSlot("self") docSlot(name, doc)) getSlot("value") ) -*/ //doc Object launchFile(pathString) Eval file at pathString as if from the command line in it's folder. //doc System launchPath Returns a pathComponent of the launch file. launchFile := method(path, args, diff --git a/io/object.py b/io/object.py --- a/io/object.py +++ b/io/object.py @@ -175,24 +175,6 @@ ast = parse(space, code) return ast.eval(space, w_target, w_target) -# XXX replace with the original one in A2_Object.io when it works -from io.model import W_Object -class W_setSlotFunction(W_Object): - def __init__(self, space, name): - W_Object.__init__(self, space) - self.name = name - - def apply(self, space, w_receiver, w_message, w_context): - w_receiver.slots[self.name] = w_message.arguments[0].eval(space, w_context, - w_receiver) - return w_receiver -@register_method('Object', 'newSlot', unwrap_spec=[object, str, object]) -def object_new_slot(space, w_target, name, w_value): - from io.model import W_CFunction - w_target.slots[name] = w_value - slot_name = 'set%s%s' % (name[0].upper(), name[1:]) - w_target.slots[slot_name] = W_setSlotFunction(space, name) - @register_method('Object', 'updateSlot', unwrap_spec=[object, str, object]) def object_update_slot(space, w_target, slotname, w_value): assert w_target.lookup(slotname) is not None diff --git a/io/test/test_object.py b/io/test/test_object.py --- a/io/test/test_object.py +++ b/io/test/test_object.py @@ -261,10 +261,34 @@ res, space = interpret(inp) assert res.number_value == 5 assert space.w_lobby.slots['a'].number_value == 5 + def test_object_update_slot_raises(): inp = 'qwer = 23' py.test.raises(Exception, 'interpret(inp)') +def test_new_slot(): + inp = """a := Object clone + a foo ::= 45 + a bar ::= 99 + a setBar(123) + a + """ + res, space = interpret(inp) + assert res.slots['foo'].number_value == 45 + assert res.slots['bar'].number_value == 123 + assert 'setFoo' in res.slots + assert 'setBar' in res.slots + +def test_new_slot_with_method(): + inp = """a := Object clone + a foo := method(setBar(123)) + a bar ::= 99 + a foo + a bar + """ + res, space = interpret(inp) + assert res.number_value == 123 + def test_object_write(): inp = """ p := Object clone do( _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit