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

niko at codespeak.net niko at codespeak.net
Fri Oct 26 18:28:05 CEST 2007


Author: niko
Date: Fri Oct 26 18:28:05 2007
New Revision: 48085

Modified:
   pypy/dist/pypy/lang/smalltalk/interpreter.py
   pypy/dist/pypy/lang/smalltalk/primitives.py
   pypy/dist/pypy/lang/smalltalk/test/test_primitives.py
Log:
(niko, toon)
add SECONDS and the 256 INST_VAR_AT_x primitives



Modified: pypy/dist/pypy/lang/smalltalk/interpreter.py
==============================================================================
--- pypy/dist/pypy/lang/smalltalk/interpreter.py	(original)
+++ pypy/dist/pypy/lang/smalltalk/interpreter.py	Fri Oct 26 18:28:05 2007
@@ -150,6 +150,7 @@
                 # note: argcount does not include rcvr
                 w_result = func(interp, argcount)
             except primitives.PrimitiveFailedError:
+                print "PRIMITIVE FAILED: %d %s" % (method.primitive, selector,)
                 pass # ignore this error and fall back to the Smalltalk version
             else:
                 # the primitive succeeded
@@ -315,6 +316,7 @@
             # note that argcount does not include self
             self.push(primitives.prim_table[primitive](interp, argcount))
         except primitives.PrimitiveFailedError:
+            print "PRIMITIVE FAILED: %s" % (selector,)
             self._sendSelfSelector(selector, argcount, interp)
 
     def bytecodePrimAdd(self, interp):

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:28:05 2007
@@ -519,6 +519,7 @@
 #____________________________________________________________________________
 # Time Primitives
 MILLISECOND_CLOCK = 135
+SECONDS_CLOCK = 137
 
 @expose_primitive(MILLISECOND_CLOCK, unwrap_spec=[object])
 def func(interp, w_arg):
@@ -526,6 +527,11 @@
     import math
     return wrap_int(int(math.fmod(time.time()*1000,1073741823/2)))
 
+ at expose_primitive(SECONDS_CLOCK, unwrap_spec=[object])
+def func(interp, w_arg):
+    import time
+    return wrap_int(0) # wrap_int(int(time.time()))
+
 # ___________________________________________________________________________
 # Boolean Primitives
 
@@ -715,3 +721,22 @@
 @expose_primitive(PRIMITIVE_FLUSH_CACHE, unwrap_spec=[object])
 def func(interp, w_rcvr):
     raise PrimitiveNotYetWrittenError()
+
+# ___________________________________________________________________________
+# PrimitiveLoadInstVar
+#
+# These are some wacky bytecodes in squeak.  They are defined to do
+# the following:
+#   primitiveLoadInstVar
+#     | thisReceiver |
+#     thisReceiver := self popStack.
+#     self push: (self fetchPointer: primitiveIndex-264 ofObject: thisReceiver)
+
+for i in range(264, 520):
+    def make_prim(i):
+        @expose_primitive(i, unwrap_spec=[object])
+        def func(interp, w_object):
+            return w_object.fetch(i - 264)
+    globals()["INST_VAR_AT_%d" % (i-264)] = i
+    make_prim(i)
+    

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:28:05 2007
@@ -377,6 +377,11 @@
     # Should not fail :-)
     prim(primitives.FULL_GC, [42]) # Dummy arg
 
+def test_seconds_clock():
+    import time
+    now = int(time.time())
+    assert (prim(primitives.SECONDS_CLOCK, [42]).value - now) <= 2
+
 def test_become():
     py.test.skip("implement me!")
     """
@@ -399,6 +404,11 @@
 	
     	self should: [1 become: 2] raise: Error.
     """
+    
+def test_load_inst_var():
+    " try to test the LoadInstVar primitives a little "
+    w_v = prim(primitives.INST_VAR_AT_0, ["q"])
+    assert w_v.value == ord("q")
 
 # Note:
 #   primitives.NEXT is unimplemented as it is a performance optimization
@@ -409,3 +419,4 @@
 #   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