Author: cfbolz
Date: Fri Nov 2 20:14:50 2007
New Revision: 48260
Modified:
pypy/dist/pypy/lang/smalltalk/primitives.py
pypy/dist/pypy/lang/smalltalk/shadow.py
pypy/dist/pypy/lang/smalltalk/test/test_primitives.py
Log:
test and fix for NEW_METHOD primitive
Modified: pypy/dist/pypy/lang/smalltalk/primitives.py
==============================================================================
--- pypy/dist/pypy/lang/smalltalk/primitives.py (original)
+++ pypy/dist/pypy/lang/smalltalk/primitives.py Fri Nov 2 20:14:50 2007
@@ -35,6 +35,8 @@
# Squeak has primitives all the way up to 575
# So all optional primitives will default to the bytecode implementation
prim_table = [make_failing(i) for i in range(576)]
+# clean up namespace:
+del i
prim_table_implemented_only = []
# indicates that what is pushed is an index1, but it is unwrapped and
@@ -426,8 +428,8 @@
# XXX not sure this is correct
assert isinstance(w_method, model.W_CompiledMethod)
w_method.literals[constants.METHOD_HEADER_INDEX] = w_header
- for i in range(0,literalcount):
- w_method.literals[i+1] = objtable.w_nil
+ for i0 in range(1, literalcount):
+ w_method.literals[i0] = objtable.w_nil
w_method.bytes = "\x00" * bytecount
return w_method
Modified: pypy/dist/pypy/lang/smalltalk/shadow.py
==============================================================================
--- pypy/dist/pypy/lang/smalltalk/shadow.py (original)
+++ pypy/dist/pypy/lang/smalltalk/shadow.py Fri Nov 2 20:14:50 2007
@@ -129,6 +129,8 @@
return model.W_WordsObject(w_cls, extrasize)
elif self.instance_kind == BYTES:
return model.W_BytesObject(w_cls, extrasize)
+ elif self.instance_kind == COMPILED_METHOD:
+ return model.W_CompiledMethod(extrasize)
else:
raise NotImplementedError(self.instance_kind)
Modified: pypy/dist/pypy/lang/smalltalk/test/test_primitives.py
==============================================================================
--- pypy/dist/pypy/lang/smalltalk/test/test_primitives.py (original)
+++ pypy/dist/pypy/lang/smalltalk/test/test_primitives.py Fri Nov 2 20:14:50 2007
@@ -411,6 +411,17 @@
w_v = prim(primitives.INST_VAR_AT_0, ["q"])
assert w_v.value == ord("q")
+def test_new_method():
+ bytecode = ''.join(map(chr, [ 16, 119, 178, 154, 118, 164, 11, 112, 16, 118, 177, 224, 112, 16, 119, 177, 224, 176, 124 ]))
+
+ shadow = mockclass(0).as_class_get_shadow()
+ w_method = prim(primitives.NEW_METHOD, [classtable.w_CompiledMethod, len(bytecode), 1025])
+ assert w_method.literals[0].value == 1025
+ assert len(w_method.literals) == 2
+ assert w_method.literals[1] is objtable.w_nil
+ assert w_method.bytes == "\x00" * len(bytecode)
+
+
# Note:
# primitives.NEXT is unimplemented as it is a performance optimization
# primitives.NEXT_PUT is unimplemented as it is a performance optimization