[pypy-svn] r47924 - in pypy/dist/pypy/lang/smalltalk: . test

niko at codespeak.net niko at codespeak.net
Thu Oct 25 15:17:09 CEST 2007


Author: niko
Date: Thu Oct 25 15:17:08 2007
New Revision: 47924

Modified:
   pypy/dist/pypy/lang/smalltalk/classtable.py
   pypy/dist/pypy/lang/smalltalk/constants.py
   pypy/dist/pypy/lang/smalltalk/interpreter.py
   pypy/dist/pypy/lang/smalltalk/primitives.py
   pypy/dist/pypy/lang/smalltalk/test/test_interpreter.py
Log:
(niko, lukas, tudor)
commit some intermediate work toward getting the block_copy_and_value
to work



Modified: pypy/dist/pypy/lang/smalltalk/classtable.py
==============================================================================
--- pypy/dist/pypy/lang/smalltalk/classtable.py	(original)
+++ pypy/dist/pypy/lang/smalltalk/classtable.py	Thu Oct 25 15:17:08 2007
@@ -1,4 +1,5 @@
 from pypy.lang.smalltalk import shadow
+from pypy.lang.smalltalk import constants
 
 def bootstrap_class(instsize, w_superclass=None, w_metaclass=None,
                     name='?', format=shadow.POINTERS, varsized=False):
@@ -94,4 +95,7 @@
 define_cls("w_False", "w_Boolean")
 define_cls("w_ByteArray", "w_ArrayedCollection", format=shadow.BYTES)
 define_cls("w_CompiledMethod", "w_ByteArray", format=shadow.COMPILED_METHOD)
-define_cls("w_MethodContext", "w_Object")
+define_cls("w_ContextPart", "w_Object")
+define_cls("w_MethodContext", "w_ContextPart")
+define_cls("w_BlockContext", "w_ContextPart",
+           instvarsize=constants.BLKCTX_TEMP_FRAME_START)

Modified: pypy/dist/pypy/lang/smalltalk/constants.py
==============================================================================
--- pypy/dist/pypy/lang/smalltalk/constants.py	(original)
+++ pypy/dist/pypy/lang/smalltalk/constants.py	Thu Oct 25 15:17:08 2007
@@ -20,13 +20,13 @@
 ASSOCIATION_KEY_INDEX = 0
 ASSOCIATION_VALUE_INDEX = 1
 
-BLOCK_CONTEXT_CALLER_INDEX = 0
-BLOCK_CONTEXT_INSTRUCTION_POINTER_INDEX = 1
-BLOCK_CONTEXT_STACK_POINTER_INDEX = 2
-BLOCK_CONTEXT_BLOCK_ARGUMENT_COUNT_INDEX = 3
-BLOCK_CONTEXT_INITIAL_IP_INDEX = 4
-BLOCK_CONTEXT_HOME_INDEX = 5
-BLOCK_CONTEXT_TEMP_FRAME_START = 6
+BLKCTX_CALLER_INDEX = 0
+BLKCTX_INSTRUCTION_POINTER_INDEX = 1
+BLKCTX_STACK_POINTER_INDEX = 2
+BLKCTX_BLOCK_ARGUMENT_COUNT_INDEX = 3
+BLKCTX_INITIAL_IP_INDEX = 4
+BLKCTX_HOME_INDEX = 5
+BLKCTX_TEMP_FRAME_START = 6
 
 # ----- special objects indices -------
 

Modified: pypy/dist/pypy/lang/smalltalk/interpreter.py
==============================================================================
--- pypy/dist/pypy/lang/smalltalk/interpreter.py	(original)
+++ pypy/dist/pypy/lang/smalltalk/interpreter.py	Thu Oct 25 15:17:08 2007
@@ -372,10 +372,12 @@
         raise MissingBytecode
 
     def bytecodePrimBlockCopy(self, interp):
-        raise MissingBytecode
+        self.callPrimitiveAndPush(
+            primitives.PRIMITIVE_BLOCK_COPY, "blockCopy:", 1, interp)
 
     def bytecodePrimValue(self, interp):
-        raise MissingBytecode
+        self.callPrimitiveAndPush(
+            primitives.PRIMITIVE_VALUE, "value", 0, interp)
 
     def bytecodePrimValueWithArg(self, interp):
         raise MissingBytecode

Modified: pypy/dist/pypy/lang/smalltalk/primitives.py
==============================================================================
--- pypy/dist/pypy/lang/smalltalk/primitives.py	(original)
+++ pypy/dist/pypy/lang/smalltalk/primitives.py	Thu Oct 25 15:17:08 2007
@@ -4,6 +4,15 @@
 from pypy.lang.smalltalk import objtable
 from pypy.rlib import rarithmetic
 
+from pypy.lang.smalltalk.constants import \
+     BLKCTX_CALLER_INDEX, \
+     BLKCTX_INSTRUCTION_POINTER_INDEX, \
+     BLKCTX_STACK_POINTER_INDEX, \
+     BLKCTX_BLOCK_ARGUMENT_COUNT_INDEX, \
+     BLKCTX_INITIAL_IP_INDEX, \
+     BLKCTX_HOME_INDEX, \
+     BLKCTX_TEMP_FRAME_START
+
 class PrimitiveFailedError(Exception):
     pass
 
@@ -533,28 +542,29 @@
 
 @primitive(PRIMITIVE_BLOCK_COPY)
 @stack(2)
-def func(args, (w_argcnt, w_context)):
+def func(args, (w_context, w_argcnt)):
     raise PrimitiveNotYetWrittenError()
     frame = args.interp.w_active_context
 
     # From B.B.: If receiver is a MethodContext, then it becomes
     # the new BlockContext's home context.  Otherwise, the home
     # context of the receiver is used for the new BlockContext.
-    if isinstance(w_context, classtable.w_BlockContext):
-        w_method_context = w_context.fetch(BLOCK_CONTEXT_HOME_INDEX)
+    if w_context.getclass() == classtable.w_BlockContext:
+        w_method_context = w_context.fetch(BLKCTX_HOME_INDEX)
     else:
         w_method_context = w_context
 
     # The block bytecodes are stored inline: so we skip past the
     # byteodes to invoke this primitive to find them (hence +3)
-    w_new_context = classtable.w_BlockContext.new(unwrap_int(w_argcnt))
+    w_new_context = classtable.w_BlockContext.as_class_get_shadow().new(
+        unwrap_int(w_argcnt))
     initialip = frame.pc + 3
 
     # Initialize various fields.
-    w_new_context.store(BLOCK_CONTEXT_INITIAL_IP_INDEX, initialip)
-    w_new_context.store(BLOCK_CONTEXT_INSTRUCTION_POINTER_INDEX, initialip)
-    w_new_context.store(BLOCK_CONTEXT_BLOCK_ARGUMENT_COUNT_INDEX, w_argcnt)
-    w_new_context.store(BLOCK_CONTEXT_HOME_INDEX, w_method_context)
+    w_new_context.store(BLKCTX_INITIAL_IP_INDEX, initialip)
+    w_new_context.store(BLKCTX_INSTRUCTION_POINTER_INDEX, initialip)
+    w_new_context.store(BLKCTX_BLOCK_ARGUMENT_COUNT_INDEX, w_argcnt)
+    w_new_context.store(BLKCTX_HOME_INDEX, w_method_context)
     return w_new_context
     
 @primitive(PRIMITIVE_VALUE)
@@ -568,23 +578,23 @@
     
     w_block_ctx = args.interp.w_active_context.peek(args.argument_count-1)
 
-    w_exp_arg_cnt = w_block_ctx.fetch(BLOCK_CONTEXT_BLOCK_ARGUMENT_COUNT_INDEX)
+    w_exp_arg_cnt = w_block_ctx.fetch(BLKCTX_BLOCK_ARGUMENT_COUNT_INDEX)
     exp_arg_cnt = unwrap_int(w_exp_arg_cnt)
     if args.argument_count != exp_arg_cnt:
         raise PrimitiveFailedError()
 
     # Copy the values from the stack such that the most recently pushed
-    # item (index 0) ends up in slot BLOCK_CONTEXT_TEMP_FRAME_START + nargs - 1
+    # item (index 0) ends up in slot BLKCTX_TEMP_FRAME_START + nargs - 1
     for idx in range(exp_arg_cnt - 1):
         w_block_ctx.store(
-            BLOCK_CONTEXT_TEMP_FRAME_START+idx,     
+            BLKCTX_TEMP_FRAME_START+idx,     
             w_block_ctx.fetch(exp_arg_cnt - idx - 1))
 
     # Set some fields
-    w_initial_ip = w_block_ctx.fetch(BLOCK_CONTEXT_INITIAL_IP_INDEX)
-    w_block_ctx.store(BLOCK_CONTEXT_INSTRUCTION_POINTER_INDEX, w_initial_ip)
-    w_block_ctx.store(BLOCK_CONTEXT_STACK_POINTER_INDEX, w_exp_arg_cnt)
-    w_block_ctx.store(BLOCK_CONTEXT_CALLER_INDEX, args.interp.w_active_context)
+    w_initial_ip = w_block_ctx.fetch(BLKCTX_INITIAL_IP_INDEX)
+    w_block_ctx.store(BLKCTX_INSTRUCTION_POINTER_INDEX, w_initial_ip)
+    w_block_ctx.store(BLKCTX_STACK_POINTER_INDEX, w_exp_arg_cnt)
+    w_block_ctx.store(BLKCTX_CALLER_INDEX, args.interp.w_active_context)
     args.interp.w_active_context = w_block_ctx
     
 @primitive(PRIMITIVE_VALUE_WITH_ARGS)

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	Thu Oct 25 15:17:08 2007
@@ -450,13 +450,14 @@
 
 def test_block_copy_and_value():
 
-    py.test.skip("waiting for bytecode")
-    
+    py.test.skip("block_copy_and_value not working yet")
+
     bc_3_plus_4 = [ 137, 117, 200, 164, 4, 32, 33, 176, 125, 201, 124]
     bc_x_plus_x_plus_1 = [ 137, 118, 200, 164, 7, 104, 16, 16, 176, 118, 176, 125, 32, 202, 124 ]
     bc_x_plus_y = [ 137, 119, 200, 164, 6, 105, 104, 16, 17, 176, 125, 33, 34, 240, 124 ]
-    
-    for bcode in [ bc_3_plus_4, bc_x_plus_x_plus_1, bc_x_plus_y ]:
+
+    for bcodes in [ bc_3_plus_4, bc_x_plus_x_plus_1, bc_x_plus_y ]:
+        bcode = "".join([chr(x) for x in bcodes])
         interp = new_interpreter(bcode)
         res = interp.interpret()
         assert res == wrap_int(7)



More information about the Pypy-commit mailing list