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

arigo at codespeak.net arigo at codespeak.net
Thu Oct 25 15:07:28 CEST 2007


Author: arigo
Date: Thu Oct 25 15:07:27 2007
New Revision: 47920

Modified:
   pypy/dist/pypy/lang/smalltalk/interpreter.py
   pypy/dist/pypy/lang/smalltalk/model.py
   pypy/dist/pypy/lang/smalltalk/primitives.py
   pypy/dist/pypy/lang/smalltalk/test/test_interpreter.py
Log:
(arigo, all watching)
Some fixes found by trying to translate it.  Not there yet.


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:07:27 2007
@@ -327,7 +327,7 @@
         self.callPrimitiveAndPush(primitives.NOTEQUAL, "~=", 1, interp)
 
     def bytecodePrimMultiply(self, interp):
-        self.callPrimitiveAndPush(primitives.MUL, "*", 1, interp)
+        self.callPrimitiveAndPush(primitives.MULTIPLY, "*", 1, interp)
 
     def bytecodePrimDivide(self, interp):
         self.callPrimitiveAndPush(primitives.DIVIDE, "/", 1, interp)

Modified: pypy/dist/pypy/lang/smalltalk/model.py
==============================================================================
--- pypy/dist/pypy/lang/smalltalk/model.py	(original)
+++ pypy/dist/pypy/lang/smalltalk/model.py	Thu Oct 25 15:07:27 2007
@@ -224,8 +224,7 @@
     """
     def __init__(self, literalsize, bytes, argsize=0, 
                  tempsize=0, primitive=0, w_compiledin=None):
-        # self.literals = [None] * size
-        self.literalsize = literalsize
+        self.literals = [None] * literalsize
         self.w_compiledin = w_compiledin
         self.bytes = bytes
         self.argsize = argsize

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:07:27 2007
@@ -97,16 +97,18 @@
     BIT_XOR: operator.xor
     }
 for (code,op) in math_ops.items():
-    @primitive(code)
-    @stack(2)
-    def func(args, (w_receiver, w_argument), op=op): # n.b. capture op value
-        receiver = unwrap_int(w_receiver)
-        argument = unwrap_int(w_argument)
-        try:
-            res = rarithmetic.ovfcheck(op(receiver, argument))
-        except OverflowError:
-            raise PrimitiveFailedError()
-        return wrap_int(res)
+    def make_func(op):
+        @primitive(code)
+        @stack(2)
+        def func(args, (w_receiver, w_argument)):
+            receiver = unwrap_int(w_receiver)
+            argument = unwrap_int(w_argument)
+            try:
+                res = rarithmetic.ovfcheck(op(receiver, argument))
+            except OverflowError:
+                raise PrimitiveFailedError()
+            return wrap_int(res)
+    make_func(op)
 
 # #/ -- return the result of a division, only succeed if the division is exact
 @primitive(DIVIDE)
@@ -190,13 +192,15 @@
     FLOAT_DIVIDE: operator.div,
     }
 for (code,op) in math_ops.items():
-    @primitive(code)
-    @stack(2)
-    def func(args, (w_v1, w_v2), op=op): # n.b. capture op value
-        v1 = unwrap_float(w_v1)
-        v2 = unwrap_float(w_v2)
-        w_res = objtable.wrap_float(op(v1, v2))
-        return w_res
+    def make_func(op):
+        @primitive(code)
+        @stack(2)
+        def func(args, (w_v1, w_v2)):
+            v1 = unwrap_float(w_v1)
+            v2 = unwrap_float(w_v2)
+            w_res = objtable.wrap_float(op(v1, v2))
+            return w_res
+    make_func(op)
 
 @primitive(FLOAT_TRUNCATED)
 @stack(1)
@@ -456,24 +460,28 @@
     NOTEQUAL: operator.ne
     }
 for (code,op) in bool_ops.items():
-    @primitive(code)
-    @stack(2)
-    def func(args, (w_v1, w_v2), op=op): # n.b. capture op value
-        v1 = unwrap_int(w_v1)
-        v2 = unwrap_int(w_v2)
-        res = op(v1, v2)
-        w_res = objtable.wrap_bool(res)
-        return w_res
+    def make_func(op):
+        @primitive(code)
+        @stack(2)
+        def func(args, (w_v1, w_v2)):
+            v1 = unwrap_int(w_v1)
+            v2 = unwrap_int(w_v2)
+            res = op(v1, v2)
+            w_res = objtable.wrap_bool(res)
+            return w_res
+    make_func(op)
 
 for (code,op) in bool_ops.items():
-    @primitive(code+_FLOAT_OFFSET)
-    @stack(2)
-    def func(args, (w_v1, w_v2), op=op): # n.b. capture op value
-        v1 = unwrap_float(w_v1)
-        v2 = unwrap_float(w_v2)
-        res = op(v1, v2)
-        w_res = objtable.wrap_bool(res)
-        return w_res
+    def make_func(op):
+        @primitive(code+_FLOAT_OFFSET)
+        @stack(2)
+        def func(args, (w_v1, w_v2)):
+            v1 = unwrap_float(w_v1)
+            v2 = unwrap_float(w_v2)
+            res = op(v1, v2)
+            w_res = objtable.wrap_bool(res)
+            return w_res
+    make_func(op)
     
 # ___________________________________________________________________________
 # Quick Push Const Primitives
@@ -526,6 +534,7 @@
 @primitive(PRIMITIVE_BLOCK_COPY)
 @stack(2)
 def func(args, (w_argcnt, w_context)):
+    raise PrimitiveNotYetWrittenError()
     frame = args.interp.w_active_context
 
     # From B.B.: If receiver is a MethodContext, then it becomes
@@ -550,6 +559,7 @@
     
 @primitive(PRIMITIVE_VALUE)
 def func(args):
+    raise PrimitiveNotYetWrittenError()
 
     # If nargs == 4, stack looks like:
     #  3      2       1      0

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:07:27 2007
@@ -1,5 +1,6 @@
 import py
 from pypy.lang.smalltalk import model, interpreter, primitives, shadow
+from pypy.lang.smalltalk import objtable
 from pypy.lang.smalltalk.objtable import wrap_int
 import pypy.lang.smalltalk.classtable as ct
 
@@ -28,7 +29,7 @@
 def fakeliterals(*literals):
     return ["methodheader"] + list(literals)
 
-def new_interpreter(bytes, receiver="receiver"):
+def new_interpreter(bytes, receiver=objtable.w_nil):
     assert isinstance(bytes, str)
     w_method = model.W_CompiledMethod(0, bytes=bytes,
                                       argsize=2, tempsize=1)



More information about the Pypy-commit mailing list