[pypy-svn] r48083 - in pypy/dist/pypy/lang/smalltalk: . test
niko at codespeak.net
niko at codespeak.net
Fri Oct 26 18:01:04 CEST 2007
Author: niko
Date: Fri Oct 26 18:01:03 2007
New Revision: 48083
Modified:
pypy/dist/pypy/lang/smalltalk/constants.py
pypy/dist/pypy/lang/smalltalk/model.py
pypy/dist/pypy/lang/smalltalk/primitives.py
pypy/dist/pypy/lang/smalltalk/test/test_interpreter.py
pypy/dist/pypy/lang/smalltalk/test/test_primitives.py
Log:
(niko, toon)
implement objectAt: and objectAt:put: properly.
Modified: pypy/dist/pypy/lang/smalltalk/constants.py
==============================================================================
--- pypy/dist/pypy/lang/smalltalk/constants.py (original)
+++ pypy/dist/pypy/lang/smalltalk/constants.py Fri Oct 26 18:01:03 2007
@@ -40,7 +40,14 @@
MTHDCTX_RECEIVER_MAP = 4
MTHDCTX_RECEIVER = 5
MTHDCTX_TEMP_FRAME_START = 6
-# ----- special objects indices -------
+
+# ___________________________________________________________________________
+# Miscellaneous constants
+
+LITERAL_START = 1 # index of the first literal after the method header
+
+# ___________________________________________________________________________
+# Special objects indices
SO_NIL = 0
SO_FALSE = 1
Modified: pypy/dist/pypy/lang/smalltalk/model.py
==============================================================================
--- pypy/dist/pypy/lang/smalltalk/model.py (original)
+++ pypy/dist/pypy/lang/smalltalk/model.py Fri Oct 26 18:01:03 2007
@@ -264,7 +264,7 @@
return w_CompiledMethod
def getliteral(self, index):
- return self.literals[index + 1] # header of compiledmethod at index 0
+ return self.literals[index + constants.LITERAL_START]
def getliteralsymbol(self, index):
w_literal = self.getliteral(index)
Modified: pypy/dist/pypy/lang/smalltalk/primitives.py
==============================================================================
--- pypy/dist/pypy/lang/smalltalk/primitives.py (original)
+++ pypy/dist/pypy/lang/smalltalk/primitives.py Fri Oct 26 18:01:03 2007
@@ -359,13 +359,17 @@
@expose_primitive(OBJECT_AT, unwrap_spec=[object, index1_0])
def func(interp, w_rcvr, n0):
- assert_bounds(n0, 0, w_rcvr.shadow_of_my_class().instance_size)
- return w_rcvr.fetch(n0)
+ if not isinstance(w_rcvr, model.W_CompiledMethod):
+ raise PrimitiveFailedError()
+ assert_bounds(n0, 0, len(w_rcvr.literals))
+ return w_rcvr.literals[n0]
@expose_primitive(OBJECT_AT_PUT, unwrap_spec=[object, index1_0, object])
def func(interp, w_rcvr, n0, w_val):
- assert_bounds(n0, 0, w_rcvr.shadow_of_my_class().instance_size)
- w_rcvr.store(n0, w_val)
+ if not isinstance(w_rcvr, model.W_CompiledMethod):
+ raise PrimitiveFailedError()
+ assert_bounds(n0, 0, len(w_rcvr.literals))
+ w_rcvr.literals[n0] = w_val
return w_val
@expose_primitive(NEW, unwrap_spec=[object])
Modified: pypy/dist/pypy/lang/smalltalk/test/test_interpreter.py
==============================================================================
--- pypy/dist/pypy/lang/smalltalk/test/test_interpreter.py (original)
+++ pypy/dist/pypy/lang/smalltalk/test/test_interpreter.py Fri Oct 26 18:01:03 2007
@@ -745,3 +745,27 @@
run_with_faked_methods(
[[w_fakeclass, primitives.AT_PUT, 2, "at:put:"]],
test)
+
+def test_bc_objectAtAndAtPut():
+ # ^ self objectAt: 1. yields the method header
+ # ^ self objectAt: 2. yields the first literal (22)
+ # ^ self objectAt: 2 put: 3. changes the first literal to 3
+ # ^ self objectAt: 2. yields the new first literal (3)
+ prim_meth = model.W_CompiledMethod(0, "")
+ prim_meth.literals = fakeliterals(22)
+ mhs = fakesymbol("methodheader")
+ oal = fakeliterals("objectAt:")
+ oalp = fakeliterals("objectAt:put:", 3)
+ def test():
+ assert interpret_bc(
+ [112, 118, 224, 124], oal, receiver=prim_meth) == mhs
+ assert interpret_bc(
+ [112, 119, 224, 124], oal, receiver=prim_meth).value == 22
+ assert interpret_bc(
+ [112, 119, 33, 240, 124], oalp, receiver=prim_meth).value == 3
+ assert interpret_bc(
+ [112, 119, 224, 124], oal, receiver=prim_meth).value == 3
+ run_with_faked_methods(
+ [[ct.w_CompiledMethod, primitives.OBJECT_AT, 1, "objectAt:"],
+ [ct.w_CompiledMethod, primitives.OBJECT_AT_PUT, 2, "objectAt:put:"]],
+ test)
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 Oct 26 18:01:03 2007
@@ -215,18 +215,9 @@
for i in range(len(exp)):
assert prim(primitives.STRING_AT, [test_str, i]) == wrap(exp[i])
-def test_object_at():
- w_v = prim(primitives.OBJECT_AT, ["q", constants.CHARACTER_VALUE_INDEX+1])
- assert w_v.value == ord("q")
-
def test_invalid_object_at():
prim_fails(primitives.OBJECT_AT, ["q", constants.CHARACTER_VALUE_INDEX+2])
-def test_object_at_put():
- w_obj = mockclass(1).as_class_get_shadow().new()
- assert prim(primitives.OBJECT_AT_PUT, [w_obj, 1, "q"]) is wrap("q")
- assert prim(primitives.OBJECT_AT, [w_obj, 1]) is wrap("q")
-
def test_invalid_object_at_put():
w_obj = mockclass(1).as_class_get_shadow().new()
prim_fails(primitives.OBJECT_AT_PUT, [w_obj, 2, 42])
@@ -409,3 +400,5 @@
# primitives.PRIMITIVE_BLOCK_COPY is tested in test_interpreter
# primitives.PRIMITIVE_VALUE is tested in test_interpreter
# primitives.PRIMITIVE_VALUE_WITH_ARGS is tested in test_interpreter
+# primitives.OBJECT_AT is tested in test_interpreter
+# primitives.OBJECT_AT_PUT is tested in test_interpreter
More information about the Pypy-commit
mailing list