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

cfbolz at codespeak.net cfbolz at codespeak.net
Fri Oct 26 00:49:24 CEST 2007


Author: cfbolz
Date: Fri Oct 26 00:49:24 2007
New Revision: 48009

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:
(arigo, cfbolz): puh. refactor the way primitives are registered to reduce the
amount of boilerplate, have more security checks and various fixes to
primitives along the way. annoying but worthwhile. note: please write more
tests, half of this it is not tested. I am looking at you, primitive people.


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 00:49:24 2007
@@ -131,7 +131,8 @@
         if method.primitive:
             func = primitives.prim_table[method.primitive]
             try:
-                w_result = func(primitives.Args(interp, argcount))
+                # add +1 to account for the receiver
+                w_result = func(interp, argcount + 1)
             except primitives.PrimitiveFailedError:
                 pass # ignore this error and fall back to the Smalltalk version
             else:
@@ -294,8 +295,8 @@
     def callPrimitiveAndPush(self, primitive, selector,
                              argcount, interp):
         try:
-            args = primitives.Args(interp, argcount)
-            self.push(primitives.prim_table[primitive](args))
+            # add one to the argcount to account for the self
+            self.push(primitives.prim_table[primitive](interp, argcount + 1))
         except primitives.PrimitiveFailedError:
             self._sendSelfSelector(selector, argcount, 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 00:49:24 2007
@@ -1,5 +1,6 @@
-import operator
+import inspect
 import math
+import operator
 from pypy.lang.smalltalk import model, shadow
 from pypy.lang.smalltalk import classtable
 from pypy.lang.smalltalk import objtable
@@ -35,41 +36,54 @@
 
 # ___________________________________________________________________________
 # Primitive table: it is filled in at initialization time with the
-# primitive functions.  Each primitive function takes a single
-# argument, an instance of the Args class below; the function either
+# primitive functions.  Each primitive function takes two
+# arguments, an interp and an argument_count
 # completes, and returns a result, or throws a PrimitiveFailedError.
 
-def raise_failing_default(args):
-	raise PrimitiveFailedError
+def raise_failing_default(interp, argument_count):
+    raise PrimitiveFailedError
 
 # Squeak has primitives all the way up to 575
 # So all optional primitives will default to the bytecode implementation
 prim_table = [raise_failing_default] * 576
 
-class Args:
-    def __init__(self, interp, argument_count):
-        self.interp = interp
-        self.argument_count = argument_count
-
-def primitive(code):
+def expose_primitive(code, unwrap_spec=None):
+    from pypy.rlib.unroll import unrolling_iterable
     def decorator(func):
         assert code not in prim_table
-        prim_table[code] = func
-        return func
-    return decorator
-
-def stack(n):
-    def decorator(wrapped):
-        def result(args):
-            frame = args.interp.w_active_context
-            start = len(frame.stack) - n
-            if start < 0:
-                raise PrimitiveFailedError()   # not enough arguments
-            items = frame.stack[start:]
-            res = wrapped(args, items)
-            frame.pop_n(n)   # only if no exception occurs!
+        if unwrap_spec is None:
+            prim_table[code] = func
+            return func
+        for spec in unwrap_spec:
+            assert spec in (int, float, object)
+        len_unwrap_spec = len(unwrap_spec)
+        assert (len_unwrap_spec == len(inspect.getargspec(func)[0]) + 1,
+                "wrong number of arguments")
+        unrolling_unwrap_spec = unrolling_iterable(enumerate(unwrap_spec))
+        def wrapped(interp, argument_count):
+            frame = interp.w_active_context
+            assert argument_count == len_unwrap_spec
+            if len(frame.stack) < len_unwrap_spec:
+                raise PrimitiveFailedError()
+            args = ()
+            for i, spec in unrolling_unwrap_spec:
+                index = -len_unwrap_spec + i
+                arg = frame.stack[index]
+                if spec is int:
+                    args += (unwrap_int(arg), )
+                elif spec is float:
+                    args += (unwrap_float(arg), )
+                elif spec is object:
+                    args += (arg, )
+                else:
+                    assert 0, "this should never happen"
+            res = func(interp, *args)
+            frame.pop_n(len_unwrap_spec)   # only if no exception occurs!
             return res
-        return result
+
+        wrapped.func_name = func.func_name
+        prim_table[code] = wrapped
+        return func
     return decorator
 
 # ___________________________________________________________________________
@@ -106,11 +120,8 @@
     }
 for (code,op) in math_ops.items():
     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)
+        @expose_primitive(code, unwrap_spec=[int, int])
+        def func(interp, receiver, argument):
             try:
                 res = rarithmetic.ovfcheck(op(receiver, argument))
             except OverflowError:
@@ -125,21 +136,15 @@
     }
 for (code,op) in bitwise_binary_ops.items():
     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)
+        @expose_primitive(code, unwrap_spec=[int, int])
+        def func(interp, receiver, argument):
             res = op(receiver, argument)
             return wrap_int(res)
     make_func(op)
 
 # #/ -- return the result of a division, only succeed if the division is exact
- at primitive(DIVIDE)
- at stack(2)
-def func(args, (w_receiver, w_argument)):
-    receiver = unwrap_int(w_receiver)
-    argument = unwrap_int(w_argument)
+ at expose_primitive(DIVIDE, unwrap_spec=[int, int])
+def func(interp, receiver, argument):
     if argument == 0:
         raise PrimitiveFailedError()
     if receiver % argument != 0:
@@ -147,45 +152,29 @@
     return wrap_int(receiver // argument)
 
 # #\\ -- return the remainder of a division
- at primitive(MOD)
- at stack(2)
-def func(args, (w_receiver, w_argument)):
-    receiver = unwrap_int(w_receiver)
-    argument = unwrap_int(w_argument)
+ at expose_primitive(MOD, unwrap_spec=[int, int])
+def func(interp, receiver, argument):
     if argument == 0:
         raise PrimitiveFailedError()
     return wrap_int(receiver % argument)
 
 # #// -- return the result of a division, rounded towards negative zero
- at primitive(DIV)
- at stack(2)
-def func(args, (w_receiver, w_argument)):
-    receiver = unwrap_int(w_receiver)
-    argument = unwrap_int(w_argument)
+ at expose_primitive(DIV, unwrap_spec=[int, int])
+def func(interp, receiver, argument):
     if argument == 0:
         raise PrimitiveFailedError()
     return wrap_int(receiver // argument)
     
 # #// -- return the result of a division, rounded towards negative infinity
- at primitive(QUO)
- at stack(2)
-def func(args, (w_receiver, w_argument)):
-    receiver = unwrap_int(w_receiver)
-    argument = unwrap_int(w_argument)
+ at expose_primitive(QUO, unwrap_spec=[int, int])
+def func(interp, receiver, argument):
     if argument == 0:
         raise PrimitiveFailedError()
     return wrap_int(receiver // argument)
     
 # #bitShift: -- return the shifted value
- at primitive(BIT_SHIFT)
- at stack(2)
-def func(args, (w_receiver, w_argument)):
-    receiver = unwrap_int(w_receiver)
-    argument = unwrap_int(w_argument)
-    
-    # heh, no shifting at all
-    if argument == 0:
-        return w_receiver
+ at expose_primitive(BIT_SHIFT, unwrap_spec=[int, int])
+def func(interp, receiver, argument):
 
     # left shift, must fail if we loose bits beyond 32
     if argument > 0:
@@ -225,57 +214,41 @@
     }
 for (code,op) in math_ops.items():
     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)
+        @expose_primitive(code, unwrap_spec=[float, float])
+        def func(interp, v1, v2):
             w_res = objtable.wrap_float(op(v1, v2))
             return w_res
     make_func(op)
 
- at primitive(FLOAT_TRUNCATED)
- at stack(1)
-def func(args, (w_float,)): 
-    f = unwrap_float(w_float)
+ at expose_primitive(FLOAT_TRUNCATED, unwrap_spec=[float])
+def func(interp, f): 
     w_res = objtable.wrap_int(int(f))
     return w_res
 
- at primitive(FLOAT_TIMES_TWO_POWER)
- at stack(2)
-def func(args, (w_rcvr,w_arg,)): 
-    rcvr = unwrap_float(w_rcvr)
-    arg = unwrap_int(w_arg)
+ at expose_primitive(FLOAT_TIMES_TWO_POWER, unwrap_spec=[float, float])
+def func(interp, rcvr, arg): 
     w_res = objtable.wrap_float(math.ldexp(rcvr,arg))
     return w_res
 
- at primitive(FLOAT_SQUARE_ROOT)
- at stack(1)
-def func(args, (w_float,)): 
-    f = unwrap_float(w_float)
+ at expose_primitive(FLOAT_SQUARE_ROOT, unwrap_spec=[float])
+def func(interp, f): 
     if f < 0.0:
         raise PrimitiveFailedError
     w_res = objtable.wrap_float(math.sqrt(f))
     return w_res
 
- at primitive(FLOAT_SIN)
- at stack(1)
-def func(args, (w_float,)): 
-    f = unwrap_float(w_float)
+ at expose_primitive(FLOAT_SIN, unwrap_spec=[float])
+def func(interp, f): 
     w_res = objtable.wrap_float(math.sin(f))
     return w_res
 
- at primitive(FLOAT_ARCTAN)
- at stack(1)
-def func(args, (w_float,)): 
-    f = unwrap_float(w_float)
+ at expose_primitive(FLOAT_ARCTAN, unwrap_spec=[float])
+def func(interp, f): 
     w_res = objtable.wrap_float(math.atan(f))
     return w_res
 
- at primitive(FLOAT_LOG_N)
- at stack(1)
-def func(args, (w_float,)): 
-    f = unwrap_float(w_float)
+ at expose_primitive(FLOAT_LOG_N, unwrap_spec=[float])
+def func(interp, f): 
     if f == 0:
         res = -rarithmetic.INFINITY
     elif f < 0:
@@ -284,10 +257,8 @@
         res = math.log(f)
     return objtable.wrap_float(res)
 
- at primitive(FLOAT_EXP)
- at stack(1)
-def func(args, (w_float,)): 
-    f = unwrap_float(w_float)
+ at expose_primitive(FLOAT_EXP, unwrap_spec=[float])
+def func(interp, f): 
     w_res = objtable.wrap_float(math.exp(f))
     return w_res
 
@@ -301,47 +272,42 @@
 STRING_AT = 63
 STRING_AT_PUT = 64
 
-def common_at((w_obj, w_index1)):
+def common_at(w_obj, w_index1):
     index1 = unwrap_int(w_index1)
     assert_valid_index(index1-1, w_obj)
     return w_obj, index1-1
 
-def common_at_put((w_obj, w_idx, w_val)):
+def common_at_put(w_obj, w_idx, w_val):
     idx = unwrap_int(w_idx)
     assert_valid_index(idx-1, w_obj)
     return w_obj, idx-1, w_val
 
- at primitive(AT)
- at stack(2)
-def func(args, stack):
-    [w_obj, idx] = common_at(stack)
+ at expose_primitive(AT, unwrap_spec=[object, object])
+def func(interp, w_obj, w_idx):
+    [w_obj, idx] = common_at(w_obj, w_idx)
     return w_obj.fetch(idx)
 
- at primitive(AT_PUT)
- at stack(3)
-def func(args, stack):
-    [w_obj, idx, w_val] = common_at_put(stack)
+ at expose_primitive(AT_PUT, unwrap_spec=[object, object, object])
+def func(interp, w_obj, w_idx, w_val):
+    [w_obj, idx, w_val] = common_at_put(w_obj, w_idx, w_val)
     w_obj.store(idx, w_val)
     return w_val
 
- at primitive(SIZE)
- at stack(1)
-def func(args, (w_obj,)):
+ at expose_primitive(SIZE, unwrap_spec=[object])
+def func(interp, w_obj):
     if not w_obj.shadow_of_my_class().isvariable():
         raise PrimitiveFailedError()
     return wrap_int(w_obj.size())
 
- at primitive(STRING_AT)
- at stack(2)
-def func(args, stack):
-    w_obj, idx = common_at(stack)
+ at expose_primitive(STRING_AT, unwrap_spec=[object, object])
+def func(interp, w_obj, w_idx):
+    w_obj, idx = common_at(w_obj, w_idx)
     byte = w_obj.getbyte(idx)
     return objtable.CharacterTable[byte]
 
- at primitive(STRING_AT_PUT)
- at stack(3)
-def func(args, stack):
-    w_obj, idx, w_val = common_at_put(stack)
+ at expose_primitive(STRING_AT_PUT, unwrap_spec=[object, object, object])
+def func(interp, w_obj, w_idx, w_val):
+    w_obj, idx, w_val = common_at_put(w_obj, w_idx, w_val)
     if w_val.getclass() is not classtable.w_Character:
         raise PrimitiveFailedError()
     w_obj.setbyte(idx, objtable.ord_w_char(w_val))
@@ -363,50 +329,44 @@
 NEXT_INSTANCE = 78
 NEW_METHOD = 79
 
- at primitive(OBJECT_AT)
- at stack(2)
-def func(args, (w_rcvr, w_n1)):
-    n0 = unwrap_int(w_n1) - 1
+ at expose_primitive(OBJECT_AT, unwrap_spec=[object, int])
+def func(interp, w_rcvr, n1):
+    n0 = n1 - 1
     assert_bounds(n0, 0, w_rcvr.shadow_of_my_class().instance_size)
     return w_rcvr.fetch(n0)
 
- at primitive(OBJECT_AT_PUT)
- at stack(3)
-def func(args, (w_rcvr, w_n1, w_val)):
-    n0 = unwrap_int(w_n1) - 1
+ at expose_primitive(OBJECT_AT_PUT, unwrap_spec=[object, int, object])
+def func(interp, w_rcvr, n1, w_val):
+    n0 = n1 - 1
     assert_bounds(n0, 0, w_rcvr.shadow_of_my_class().instance_size)
     w_rcvr.store(n0, w_val)
     return w_val
 
- at primitive(NEW)
- at stack(1)
-def func(args, (w_cls,)):
+ at expose_primitive(NEW, unwrap_spec=[object])
+def func(interp, w_cls):
     shadow = w_cls.as_class_get_shadow()
     if shadow.isvariable():
         raise PrimitiveFailedError()
     return shadow.new()
 
- at primitive(NEW_WITH_ARG)
- at stack(2)
-def func(args, (w_cls, w_size)):
+ at expose_primitive(NEW_WITH_ARG, unwrap_spec=[object, object])
+def func(interp, w_cls, w_size):
     shadow = w_cls.as_class_get_shadow()
     if not shadow.isvariable():
         raise PrimitiveFailedError()
     size = unwrap_int(w_size)
     return shadow.new(size)
 
- at primitive(ARRAY_BECOME_ONE_WAY)
-def func(args):
+ at expose_primitive(ARRAY_BECOME_ONE_WAY, unwrap_spec=[])
+def func(interp):
     raise PrimitiveNotYetWrittenError
 
- at primitive(INST_VAR_AT)
- at stack(2)
-def func(args, (w_rcvr, w_idx)):
+ at expose_primitive(INST_VAR_AT, unwrap_spec=[object, int])
+def func(interp, w_rcvr, idx):
     # I *think* this is the correct behavior, but I'm not quite sure.
     # Might be restricted to fixed length fields?
     # XXX this doesn't look correct.  Our guess is that INST_VAR_AT
     # is used to access *only* the fixed length fields.
-    idx = unwrap_int(w_idx)
     shadow = w_rcvr.shadow_of_my_class()
     if idx < 0:
         raise PrimitiveFailedError()
@@ -417,41 +377,37 @@
         return subscript(idx, w_rcvr)
     raise PrimitiveFailedError()
 
- at primitive(INST_VAR_AT_PUT)
-def func(args):
+ at expose_primitive(INST_VAR_AT_PUT, unwrap_spec=[])
+def func(interp):
     raise PrimitiveNotYetWrittenError()
 
- at primitive(AS_OOP)
- at stack(1)
-def func(args, (w_rcvr,)):
+ at expose_primitive(AS_OOP, unwrap_spec=[object])
+def func(interp, w_rcvr):
     if isinstance(w_rcvr, model.W_SmallInteger):
         raise PrimitiveFailedError()
     return wrap_int(w_rcvr.gethash())
 
- at primitive(STORE_STACKP)
- at stack(2)
-def func(args, stack):
+ at expose_primitive(STORE_STACKP, unwrap_spec=[object, object])
+def func(interp, w_obj1, w_obj2):
     # This primitive seems to resize the stack.  I don't think this is
     # really relevant in our implementation.
     raise PrimitiveNotYetWrittenError()
 
- at primitive(SOME_INSTANCE)
- at stack(1)
-def func(args, (w_class,)):
+ at expose_primitive(SOME_INSTANCE, unwrap_spec=[object])
+def func(interp, w_class):
     # This primitive returns some instance of the class on the stack.
     # Not sure quite how to do this; maintain a weak list of all
     # existing instances or something?
     raise PrimitiveNotYetWrittenError()
 
- at primitive(NEXT_INSTANCE)
- at stack(1)
-def func(args, (w_obj,)):
+ at expose_primitive(NEXT_INSTANCE, unwrap_spec=[object])
+def func(interp, w_obj):
     # This primitive is used to iterate through all instances of a class:
     # it returns the "next" instance after w_obj.
     raise PrimitiveNotYetWrittenError()
 
- at primitive(NEW_METHOD)
-def func(args):
+ at expose_primitive(NEW_METHOD, unwrap_spec=[])
+def func(interp):
     raise PrimitiveNotYetWrittenError()
 
 # ___________________________________________________________________________
@@ -464,40 +420,38 @@
 EXIT_TO_DEBUGGER = 114
 CHANGE_CLASS = 115      # Blue Book: primitiveOopsLeft
 
- at primitive(EQUIVALENT)
- at stack(2)
-def func(args, (w_arg, w_rcvr)):
+ at expose_primitive(EQUIVALENT, unwrap_spec=[object, object])
+def func(interp, w_arg, w_rcvr):
     # XXX this is bogus in the presence of (our implementation of) become,
     # as we might plan to implement become by copying all fields from one
     # object to the other
     return objtable.wrap_bool(w_arg is w_rcvr)
 
- at primitive(CLASS)
- at stack(1)
-def func(args, (w_obj,)):
+ at expose_primitive(CLASS, unwrap_spec=[object])
+def func(interp, w_obj):
     return w_obj.getclass()
 
- at primitive(BYTES_LEFT)
-def func(args):
+ at expose_primitive(BYTES_LEFT, unwrap_spec=[])
+def func(interp):
     raise PrimitiveNotYetWrittenError()
 
- at primitive(QUIT)
-def func(args):
+ at expose_primitive(QUIT, unwrap_spec=[])
+def func(interp):
     raise PrimitiveNotYetWrittenError()
 
- at primitive(EXIT_TO_DEBUGGER)
-def func(args):
+ at expose_primitive(EXIT_TO_DEBUGGER, unwrap_spec=[])
+def func(interp):
     raise PrimitiveNotYetWrittenError()
 
- at primitive(CHANGE_CLASS)
- at stack(2)
-def func(args, (w_arg, w_rcvr)):
+ at expose_primitive(CHANGE_CLASS, unwrap_spec=[object, object])
+def func(interp, w_arg, w_rcvr):
     w_arg_class = w_arg.getclass()
     w_rcvr_class = w_rcvr.getclass()
 
     # We should fail if:
 
     # 1. Rcvr or arg are SmallIntegers
+    # XXX this is wrong too
     if (w_arg_class == classtable.w_SmallInteger or
         w_rcvr_class == classtable.w_SmallInteger):
         raise PrimitiveFailedError()
@@ -526,10 +480,9 @@
 def fake_bytes_left():
     return wrap_int(2**20) # XXX we don't know how to do this :-(
 
- at primitive(INC_GC) # XXX the same for now
- at primitive(FULL_GC)
- at stack(1) # Squeak pops the arg and ignores it ... go figure
-def func(args, (w_arg,)):
+ at expose_primitive(INC_GC, unwrap_spec=[object])
+ at expose_primitive(FULL_GC, unwrap_spec=[object])
+def func(interp, w_arg): # Squeak pops the arg and ignores it ... go figure
     from pypy.rlib import rgc
     rgc.collect()
     return fake_bytes_left()
@@ -561,11 +514,8 @@
     }
 for (code,op) in bool_ops.items():
     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)
+        @expose_primitive(code, unwrap_spec=[int, int])
+        def func(interp, v1, v2):
             res = op(v1, v2)
             w_res = objtable.wrap_bool(res)
             return w_res
@@ -573,11 +523,8 @@
 
 for (code,op) in bool_ops.items():
     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)
+        @expose_primitive(code+_FLOAT_OFFSET, unwrap_spec=[float, float])
+        def func(interp, v1, v2):
             res = op(v1, v2)
             w_res = objtable.wrap_bool(res)
             return w_res
@@ -595,29 +542,25 @@
 PUSH_ONE = 262
 PUSH_TWO = 263
 
- at primitive(PUSH_SELF)
- at stack(1)
-def func(args, stack):
-    [w_self] = stack
+ at expose_primitive(PUSH_SELF, unwrap_spec=[object])
+def func(interp, w_self):
+    # no-op really
     return w_self
 
-def define_const_primitives():
-    for (code, const) in [
-        (PUSH_TRUE, objtable.w_true),
-        (PUSH_FALSE, objtable.w_false),
-        (PUSH_NIL, objtable.w_nil),
-        (PUSH_MINUS_ONE, objtable.w_mone),
-        (PUSH_ZERO, objtable.w_zero),
-        (PUSH_ONE, objtable.w_one),
-        (PUSH_TWO, objtable.w_two),
-        ]:
-        def make_func(const):
-            @primitive(code)
-            @stack(1)
-            def func(args, stack):
-                return const
-        make_func(const)
-define_const_primitives()
+for (code, const) in [
+    (PUSH_TRUE, objtable.w_true),
+    (PUSH_FALSE, objtable.w_false),
+    (PUSH_NIL, objtable.w_nil),
+    (PUSH_MINUS_ONE, objtable.w_mone),
+    (PUSH_ZERO, objtable.w_zero),
+    (PUSH_ONE, objtable.w_one),
+    (PUSH_TWO, objtable.w_two),
+    ]:
+    def make_func(const):
+        @expose_primitive(code, unwrap_spec=[object])
+        def func(interp, w_ignored):
+            return const
+    make_func(const)
         
 # ___________________________________________________________________________
 # Control Primitives
@@ -633,10 +576,9 @@
 PRIMITIVE_SUSPEND = 88
 PRIMITIVE_FLUSH_CACHE = 89
 
- at primitive(PRIMITIVE_BLOCK_COPY)
- at stack(2)
-def func(args, (w_context, w_argcnt)):
-    frame = args.interp.w_active_context
+ at expose_primitive(PRIMITIVE_BLOCK_COPY, unwrap_spec=[object, object])
+def func(interp, w_context, w_argcnt):
+    frame = interp.w_active_context
     argcnt = unwrap_int(w_argcnt)
 
     # From B.B.: If receiver is a MethodContext, then it becomes
@@ -654,23 +596,23 @@
         w_method_context, objtable.w_nil, argcnt, initialip)
     return w_new_context
     
- at primitive(PRIMITIVE_VALUE)
-def func(args):
-
-    # If nargs == 4, stack looks like:
+ at expose_primitive(PRIMITIVE_VALUE)
+def func(interp, argument_count):
+    # XXX XXX XXX XXX test me
+    # If argument_count == 4, stack looks like:
     #  3      2       1      0
     #  Rcvr | Arg 0 | Arg1 | Arg 2
     #
     
-    frame = args.interp.w_active_context
+    frame = interp.w_active_context
     
     # Validate that we have a block on the stack and that it received
     # the proper number of arguments:
-    w_block_ctx = frame.peek(args.argument_count-1)
+    w_block_ctx = frame.peek(argument_count-1)
     if not isinstance(w_block_ctx, model.W_BlockContext):
         raise PrimitiveFailedError()
     exp_arg_cnt = w_block_ctx.expected_argument_count()
-    if args.argument_count != exp_arg_cnt:
+    if argument_count != exp_arg_cnt + 1: # exp_arg_cnt doesn't count self
         raise PrimitiveFailedError()
 
     # Initialize the block stack from the contents of the stack:
@@ -681,45 +623,38 @@
     # Set some fields
     w_block_ctx.pc = w_block_ctx.initialip
     w_block_ctx.w_sender = frame
-    args.interp.w_active_context = w_block_ctx
+    interp.w_active_context = w_block_ctx
     
- at primitive(PRIMITIVE_VALUE_WITH_ARGS)
- at stack(2)
-def func(args, (w_rcvr, w_args)):
+ at expose_primitive(PRIMITIVE_VALUE_WITH_ARGS, unwrap_spec=[object, object])
+def func(interp, w_rcvr, w_args):
     raise PrimitiveNotYetWrittenError()
 
- at primitive(PRIMITIVE_PERFORM)
- at stack(2)
-def func(args, (w_rcvr, w_sel)):
+ at expose_primitive(PRIMITIVE_PERFORM, unwrap_spec=[object, object])
+def func(interp, w_rcvr, w_sel):
     # XXX we can implement this when lookup on shadow class is done
     raise PrimitiveNotYetWrittenError()
 
- at primitive(PRIMITIVE_PERFORM_WITH_ARGS)
- at stack(3)
-def func(args, (w_rcvr, w_sel, w_args)):
+ at expose_primitive(PRIMITIVE_PERFORM_WITH_ARGS,
+                  unwrap_spec=[object, object, object])
+def func(interp, w_rcvr, w_sel, w_args):
     raise PrimitiveNotYetWrittenError()
 
- at primitive(PRIMITIVE_SIGNAL)
- at stack(1)
-def func(args, (w_rcvr,)):
+ at expose_primitive(PRIMITIVE_SIGNAL, unwrap_spec=[object])
+def func(interp, w_rcvr):
     raise PrimitiveNotYetWrittenError()
     
- at primitive(PRIMITIVE_WAIT)
- at stack(1)
-def func(args, (w_rcvr,)):
+ at expose_primitive(PRIMITIVE_WAIT, unwrap_spec=[object])
+def func(interp, w_rcvr):
     raise PrimitiveNotYetWrittenError()
     
- at primitive(PRIMITIVE_RESUME)
- at stack(1)
-def func(args, (w_rcvr,)):
+ at expose_primitive(PRIMITIVE_RESUME, unwrap_spec=[object])
+def func(interp, w_rcvr,):
     raise PrimitiveNotYetWrittenError()
 
- at primitive(PRIMITIVE_SUSPEND)
- at stack(1)
-def func(args, (w_rcvr,)):
+ at expose_primitive(PRIMITIVE_SUSPEND, unwrap_spec=[object])
+def func(interp, w_rcvr):
     raise PrimitiveNotYetWrittenError()
 
- at primitive(PRIMITIVE_FLUSH_CACHE)
- at stack(1)
-def func(args, (w_rcvr,)):
+ at expose_primitive(PRIMITIVE_FLUSH_CACHE, unwrap_spec=[object])
+def func(interp, w_rcvr):
     raise PrimitiveNotYetWrittenError()

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 00:49:24 2007
@@ -8,7 +8,7 @@
 from pypy.rlib.rarithmetic import INFINITY, NAN, isinf, isnan
 
 # Violates the guideline, but we use it A LOT to reference the primitive codes:
-import pypy.lang.smalltalk.primitives as p
+from pypy.lang.smalltalk import primitives
 
 mockclass = classtable.bootstrap_class
 
@@ -29,257 +29,257 @@
     frame = MockFrame(mapped_stack)
     interp = interpreter.Interpreter()
     interp.w_active_context = frame
-    return p.Args(interp, len(stack))
+    return (interp, len(stack))
 
 def prim(code, stack):
-    args = mock(stack)
-    res = prim_table[code](args)
-    assert not len(args.interp.w_active_context.stack) # check args are consumed
+    interp, argument_count = mock(stack)
+    res = prim_table[code](interp, argument_count)
+    assert not len(interp.w_active_context.stack) # check args are consumed
     return res
 
 def prim_fails(code, stack):
-    args = mock(stack)
-    orig_stack = list(args.interp.w_active_context.stack)
+    interp, argument_count = mock(stack)
+    orig_stack = list(interp.w_active_context.stack)
     try:
-        prim_table[code](args)
+        prim_table[code](interp, argument_count)
         py.test.fail("Expected PrimitiveFailedError")
     except PrimitiveFailedError:
-        assert args.interp.w_active_context.stack == orig_stack
+        assert interp.w_active_context.stack == orig_stack
         
 # smallinteger tests
 def test_small_int_add():
-    assert prim(p.ADD, [1,2]).value == 3
-    assert prim(p.ADD, [3,4]).value == 7
+    assert prim(primitives.ADD, [1,2]).value == 3
+    assert prim(primitives.ADD, [3,4]).value == 7
 
 def test_small_int_add_fail():
-    prim_fails(p.ADD, [1073741823,2])
+    prim_fails(primitives.ADD, [1073741823,2])
 
 def test_small_int_minus():
-    assert prim(p.SUBTRACT, [5,9]).value == -4
+    assert prim(primitives.SUBTRACT, [5,9]).value == -4
 
 def test_small_int_minus_fail():
-    prim_fails(p.SUBTRACT, [-1073741823,2])
+    prim_fails(primitives.SUBTRACT, [-1073741823,2])
     
 def test_small_int_divide():
-    assert prim(p.DIVIDE, [6,3]).value == 2
+    assert prim(primitives.DIVIDE, [6,3]).value == 2
     
 def test_small_int_divide_fail():
-    prim_fails(p.DIVIDE, [12, 0])
-    prim_fails(p.DIVIDE, [12, 7])
+    prim_fails(primitives.DIVIDE, [12, 0])
+    prim_fails(primitives.DIVIDE, [12, 7])
     
 def test_small_int_mod():
-    assert prim(p.MOD, [12,7]).value == 5
+    assert prim(primitives.MOD, [12,7]).value == 5
 
 def test_small_int_mod_fail():
-    prim_fails(p.MOD, [12, 0])
+    prim_fails(primitives.MOD, [12, 0])
     
 def test_small_int_div():
-    assert prim(p.DIV, [12,3]).value == 4
-    assert prim(p.DIV, [12,7]).value == 1
+    assert prim(primitives.DIV, [12,3]).value == 4
+    assert prim(primitives.DIV, [12,7]).value == 1
 
 def test_small_int_div_fail():
-    prim_fails(p.DIV, [12, 0])
+    prim_fails(primitives.DIV, [12, 0])
     
 def test_small_int_quo():
-    assert prim(p.QUO, [12,3]).value == 4
-    assert prim(p.QUO, [12,7]).value == 1
+    assert prim(primitives.QUO, [12,3]).value == 4
+    assert prim(primitives.QUO, [12,7]).value == 1
 
 def test_small_int_quo_fail():
-    prim_fails(p.QUO, [12, 0])
+    prim_fails(primitives.QUO, [12, 0])
     
 def test_small_int_bit_and():
-    assert prim(p.BIT_AND, [2, 4]).value == 0
-    assert prim(p.BIT_AND, [2, 3]).value == 2
-    assert prim(p.BIT_AND, [3, 4]).value == 0
-    assert prim(p.BIT_AND, [4, 4]).value == 4
+    assert prim(primitives.BIT_AND, [2, 4]).value == 0
+    assert prim(primitives.BIT_AND, [2, 3]).value == 2
+    assert prim(primitives.BIT_AND, [3, 4]).value == 0
+    assert prim(primitives.BIT_AND, [4, 4]).value == 4
     
 def test_small_int_bit_or():
-    assert prim(p.BIT_OR, [2, 4]).value == 6
-    assert prim(p.BIT_OR, [2, 3]).value == 3
-    assert prim(p.BIT_OR, [3, 4]).value == 7
-    assert prim(p.BIT_OR, [4, 4]).value == 4
+    assert prim(primitives.BIT_OR, [2, 4]).value == 6
+    assert prim(primitives.BIT_OR, [2, 3]).value == 3
+    assert prim(primitives.BIT_OR, [3, 4]).value == 7
+    assert prim(primitives.BIT_OR, [4, 4]).value == 4
 
 def test_small_int_bit_xor():
-    assert prim(p.BIT_XOR, [2, 4]).value == 6
-    assert prim(p.BIT_XOR, [2, 3]).value == 1
-    assert prim(p.BIT_XOR, [3, 4]).value == 7
-    assert prim(p.BIT_XOR, [4, 4]).value == 0
+    assert prim(primitives.BIT_XOR, [2, 4]).value == 6
+    assert prim(primitives.BIT_XOR, [2, 3]).value == 1
+    assert prim(primitives.BIT_XOR, [3, 4]).value == 7
+    assert prim(primitives.BIT_XOR, [4, 4]).value == 0
 
 def test_small_int_bit_shift():
-    assert prim(p.BIT_SHIFT, [0, -3]).value == 0
-    assert prim(p.BIT_SHIFT, [0, -2]).value == 0
-    assert prim(p.BIT_SHIFT, [0, -1]).value == 0
-    assert prim(p.BIT_SHIFT, [0, 0]).value == 0
-    assert prim(p.BIT_SHIFT, [0, 1]).value == 0
-    assert prim(p.BIT_SHIFT, [0, 2]).value == 0
-    assert prim(p.BIT_SHIFT, [0, 3]).value == 0
+    assert prim(primitives.BIT_SHIFT, [0, -3]).value == 0
+    assert prim(primitives.BIT_SHIFT, [0, -2]).value == 0
+    assert prim(primitives.BIT_SHIFT, [0, -1]).value == 0
+    assert prim(primitives.BIT_SHIFT, [0, 0]).value == 0
+    assert prim(primitives.BIT_SHIFT, [0, 1]).value == 0
+    assert prim(primitives.BIT_SHIFT, [0, 2]).value == 0
+    assert prim(primitives.BIT_SHIFT, [0, 3]).value == 0
     
 def test_small_int_bit_shift_positive():
-    assert prim(p.BIT_SHIFT, [4, -3]).value == 0
-    assert prim(p.BIT_SHIFT, [4, -2]).value == 1
-    assert prim(p.BIT_SHIFT, [4, -1]).value == 2
-    assert prim(p.BIT_SHIFT, [4, 0]).value == 4
-    assert prim(p.BIT_SHIFT, [4, 1]).value == 8
-    assert prim(p.BIT_SHIFT, [4, 2]).value == 16
-    assert prim(p.BIT_SHIFT, [4, 3]).value == 32
-    assert prim(p.BIT_SHIFT, [4, 27]).value == 536870912
+    assert prim(primitives.BIT_SHIFT, [4, -3]).value == 0
+    assert prim(primitives.BIT_SHIFT, [4, -2]).value == 1
+    assert prim(primitives.BIT_SHIFT, [4, -1]).value == 2
+    assert prim(primitives.BIT_SHIFT, [4, 0]).value == 4
+    assert prim(primitives.BIT_SHIFT, [4, 1]).value == 8
+    assert prim(primitives.BIT_SHIFT, [4, 2]).value == 16
+    assert prim(primitives.BIT_SHIFT, [4, 3]).value == 32
+    assert prim(primitives.BIT_SHIFT, [4, 27]).value == 536870912
     
 def test_small_int_bit_shift_negative():
-    assert prim(p.BIT_SHIFT, [-4, -3]).value == -1
-    assert prim(p.BIT_SHIFT, [-4, -2]).value == -1
-    assert prim(p.BIT_SHIFT, [-4, -1]).value == -2
-    assert prim(p.BIT_SHIFT, [-4, 0]).value == -4
-    assert prim(p.BIT_SHIFT, [-4, 1]).value == -8
-    assert prim(p.BIT_SHIFT, [-4, 2]).value == -16
-    assert prim(p.BIT_SHIFT, [-4, 3]).value == -32
-    assert prim(p.BIT_SHIFT, [-4, 27]).value == -536870912
+    assert prim(primitives.BIT_SHIFT, [-4, -3]).value == -1
+    assert prim(primitives.BIT_SHIFT, [-4, -2]).value == -1
+    assert prim(primitives.BIT_SHIFT, [-4, -1]).value == -2
+    assert prim(primitives.BIT_SHIFT, [-4, 0]).value == -4
+    assert prim(primitives.BIT_SHIFT, [-4, 1]).value == -8
+    assert prim(primitives.BIT_SHIFT, [-4, 2]).value == -16
+    assert prim(primitives.BIT_SHIFT, [-4, 3]).value == -32
+    assert prim(primitives.BIT_SHIFT, [-4, 27]).value == -536870912
     
 def test_small_int_bit_shift_fail():
-    prim_fails(p.BIT_SHIFT, [4, 32])
-    prim_fails(p.BIT_SHIFT, [4, 31])
-    prim_fails(p.BIT_SHIFT, [4, 30])
-    prim_fails(p.BIT_SHIFT, [4, 29])
-    prim_fails(p.BIT_SHIFT, [4, 28])
+    prim_fails(primitives.BIT_SHIFT, [4, 32])
+    prim_fails(primitives.BIT_SHIFT, [4, 31])
+    prim_fails(primitives.BIT_SHIFT, [4, 30])
+    prim_fails(primitives.BIT_SHIFT, [4, 29])
+    prim_fails(primitives.BIT_SHIFT, [4, 28])
 
 def test_float_add():
-    assert prim(p.FLOAT_ADD, [1.0,2.0]).value == 3.0
-    assert prim(p.FLOAT_ADD, [3.0,4.5]).value == 7.5
+    assert prim(primitives.FLOAT_ADD, [1.0,2.0]).value == 3.0
+    assert prim(primitives.FLOAT_ADD, [3.0,4.5]).value == 7.5
 
 def test_float_subtract():
-    assert prim(p.FLOAT_SUBTRACT, [1.0,2.0]).value == -1.0
-    assert prim(p.FLOAT_SUBTRACT, [15.0,4.5]).value == 10.5
+    assert prim(primitives.FLOAT_SUBTRACT, [1.0,2.0]).value == -1.0
+    assert prim(primitives.FLOAT_SUBTRACT, [15.0,4.5]).value == 10.5
 
 def test_float_multiply():
-    assert prim(p.FLOAT_MULTIPLY, [10.0,2.0]).value == 20.0
-    assert prim(p.FLOAT_MULTIPLY, [3.0,4.5]).value == 13.5
+    assert prim(primitives.FLOAT_MULTIPLY, [10.0,2.0]).value == 20.0
+    assert prim(primitives.FLOAT_MULTIPLY, [3.0,4.5]).value == 13.5
 
 def test_float_divide():
-    assert prim(p.FLOAT_DIVIDE, [1.0,2.0]).value == 0.5
-    assert prim(p.FLOAT_DIVIDE, [3.5,4.0]).value == 0.875
+    assert prim(primitives.FLOAT_DIVIDE, [1.0,2.0]).value == 0.5
+    assert prim(primitives.FLOAT_DIVIDE, [3.5,4.0]).value == 0.875
 
 def test_float_truncate():
-    assert prim(p.FLOAT_TRUNCATED, [-4.6]).value == -4
-    assert prim(p.FLOAT_TRUNCATED, [-4.5]).value == -4
-    assert prim(p.FLOAT_TRUNCATED, [-4.4]).value == -4
-    assert prim(p.FLOAT_TRUNCATED, [4.4]).value == 4
-    assert prim(p.FLOAT_TRUNCATED, [4.5]).value == 4
-    assert prim(p.FLOAT_TRUNCATED, [4.6]).value == 4
+    assert prim(primitives.FLOAT_TRUNCATED, [-4.6]).value == -4
+    assert prim(primitives.FLOAT_TRUNCATED, [-4.5]).value == -4
+    assert prim(primitives.FLOAT_TRUNCATED, [-4.4]).value == -4
+    assert prim(primitives.FLOAT_TRUNCATED, [4.4]).value == 4
+    assert prim(primitives.FLOAT_TRUNCATED, [4.5]).value == 4
+    assert prim(primitives.FLOAT_TRUNCATED, [4.6]).value == 4
 
 
 def test_at():
     w_obj = mockclass(0, varsized=True).as_class_get_shadow().new(1)
     w_obj.store(0, "foo")
-    assert prim(p.AT, [w_obj, 1]) == "foo"
+    assert prim(primitives.AT, [w_obj, 1]) == "foo"
 
 def test_invalid_at():
     w_obj = mockclass(0).as_class_get_shadow().new()
-    prim_fails(p.AT, [w_obj, 1])
+    prim_fails(primitives.AT, [w_obj, 1])
 
 def test_at_put():
     w_obj = mockclass(0, varsized=1).as_class_get_shadow().new(1)
-    assert prim(p.AT_PUT, [w_obj, 1, 22]).value == 22
-    assert prim(p.AT, [w_obj, 1]).value == 22
+    assert prim(primitives.AT_PUT, [w_obj, 1, 22]).value == 22
+    assert prim(primitives.AT, [w_obj, 1]).value == 22
     
 def test_invalid_at_put():
     w_obj = mockclass(0).as_class_get_shadow().new()
-    prim_fails(p.AT_PUT, [w_obj, 1, 22])
+    prim_fails(primitives.AT_PUT, [w_obj, 1, 22])
 
 def test_string_at():
-    assert prim(p.STRING_AT, ["foobar", 4]) == wrap("b")
+    assert prim(primitives.STRING_AT, ["foobar", 4]) == wrap("b")
 
 def test_string_at_put():
     test_str = wrap("foobar")
-    assert prim(p.STRING_AT_PUT, [test_str, 4, "c"]) == wrap("c")
+    assert prim(primitives.STRING_AT_PUT, [test_str, 4, "c"]) == wrap("c")
     exp = "foocar"
     for i in range(len(exp)):
-        assert prim(p.STRING_AT, [test_str, i]) == wrap(exp[i])
+        assert prim(primitives.STRING_AT, [test_str, i]) == wrap(exp[i])
 
 def test_object_at():
-    w_v = prim(p.OBJECT_AT, ["q", objtable.CHARACTER_VALUE_INDEX+1])
+    w_v = prim(primitives.OBJECT_AT, ["q", objtable.CHARACTER_VALUE_INDEX+1])
     assert w_v.value == ord("q")
 
 def test_invalid_object_at():
-    prim_fails(p.OBJECT_AT, ["q", objtable.CHARACTER_VALUE_INDEX+2])
+    prim_fails(primitives.OBJECT_AT, ["q", objtable.CHARACTER_VALUE_INDEX+2])
     
 def test_object_at_put():
     w_obj = mockclass(1).as_class_get_shadow().new()
-    assert prim(p.OBJECT_AT_PUT, [w_obj, 1, "q"]) is wrap("q")
-    assert prim(p.OBJECT_AT, [w_obj, 1]) is wrap("q")
+    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(p.OBJECT_AT, [w_obj, 2, 42])
+    prim_fails(primitives.OBJECT_AT_PUT, [w_obj, 2, 42])
     
 def test_string_at_put():
     test_str = wrap("foobar")
-    assert prim(p.STRING_AT_PUT, [test_str, 4, "c"]) == wrap("c")
+    assert prim(primitives.STRING_AT_PUT, [test_str, 4, "c"]) == wrap("c")
     exp = "foocar"
     for i in range(1,len(exp)+1):
-        assert prim(p.STRING_AT, [test_str, i]) == wrap(exp[i-1])
+        assert prim(primitives.STRING_AT, [test_str, i]) == wrap(exp[i-1])
 
 def test_new():
     w_Object = classtable.classtable['w_Object']
-    w_res = prim(p.NEW, [w_Object])
+    w_res = prim(primitives.NEW, [w_Object])
     assert w_res.getclass() is w_Object
     
 def test_invalid_new():
-    prim_fails(p.NEW, [classtable.w_String])
+    prim_fails(primitives.NEW, [classtable.w_String])
 
 def test_new_with_arg():
-    w_res = prim(p.NEW_WITH_ARG, [classtable.w_String, 20])
+    w_res = prim(primitives.NEW_WITH_ARG, [classtable.w_String, 20])
     assert w_res.getclass() == classtable.w_String
     assert w_res.size() == 20    
 
 def test_invalid_new_with_arg():
     w_Object = classtable.classtable['w_Object']
-    prim_fails(p.NEW_WITH_ARG, [w_Object, 20])
+    prim_fails(primitives.NEW_WITH_ARG, [w_Object, 20])
     
 def test_inst_var_at():
     # I am not entirely sure if this is what this primitive is
     # supposed to do, so the test may be bogus:
-    w_v = prim(p.INST_VAR_AT, ["q", objtable.CHARACTER_VALUE_INDEX])
+    w_v = prim(primitives.INST_VAR_AT, ["q", objtable.CHARACTER_VALUE_INDEX])
     assert w_v.value == ord("q")
-    w_v = prim(p.INST_VAR_AT, ["abc", 1])
+    w_v = prim(primitives.INST_VAR_AT, ["abc", 1])
     assert w_v.value == ord("b")
 
 def test_as_oop():
     py.test.skip("not yet clear what AS_OOP returns: hash or header?")
     w_obj = mockclass(0).as_class_get_shadow().new()
     w_obj.w_hash = wrap(22)
-    assert prim(p.AS_OOP, [w_obj]).value == 22
+    assert prim(primitives.AS_OOP, [w_obj]).value == 22
 
 def test_as_oop_not_applicable_to_int():
-    prim_fails(p.AS_OOP, [22])
+    prim_fails(primitives.AS_OOP, [22])
 
 def test_const_primitives():
     for (code, const) in [
-        (p.PUSH_TRUE, objtable.w_true),
-        (p.PUSH_FALSE, objtable.w_false),
-        (p.PUSH_NIL, objtable.w_nil),
-        (p.PUSH_MINUS_ONE, objtable.w_mone),
-        (p.PUSH_ZERO, objtable.w_zero),
-        (p.PUSH_ONE, objtable.w_one),
-        (p.PUSH_TWO, objtable.w_two),
+        (primitives.PUSH_TRUE, objtable.w_true),
+        (primitives.PUSH_FALSE, objtable.w_false),
+        (primitives.PUSH_NIL, objtable.w_nil),
+        (primitives.PUSH_MINUS_ONE, objtable.w_mone),
+        (primitives.PUSH_ZERO, objtable.w_zero),
+        (primitives.PUSH_ONE, objtable.w_one),
+        (primitives.PUSH_TWO, objtable.w_two),
         ]:
         assert prim(code, [objtable.w_nil]) is const
-    assert prim(p.PUSH_SELF, [objtable.w_nil]) is objtable.w_nil
-    assert prim(p.PUSH_SELF, ["a"]) is wrap("a")
+    assert prim(primitives.PUSH_SELF, [objtable.w_nil]) is objtable.w_nil
+    assert prim(primitives.PUSH_SELF, ["a"]) is wrap("a")
 
 def test_boolean():
-    assert prim(p.LESSTHAN, [1,2]) == objtable.w_true
-    assert prim(p.GREATERTHAN, [3,4]) == objtable.w_false
-    assert prim(p.LESSOREQUAL, [1,2]) == objtable.w_true
-    assert prim(p.GREATEROREQUAL, [3,4]) == objtable.w_false
-    assert prim(p.EQUAL, [2,2]) == objtable.w_true
-    assert prim(p.NOTEQUAL, [2,2]) == objtable.w_false
+    assert prim(primitives.LESSTHAN, [1,2]) == objtable.w_true
+    assert prim(primitives.GREATERTHAN, [3,4]) == objtable.w_false
+    assert prim(primitives.LESSOREQUAL, [1,2]) == objtable.w_true
+    assert prim(primitives.GREATEROREQUAL, [3,4]) == objtable.w_false
+    assert prim(primitives.EQUAL, [2,2]) == objtable.w_true
+    assert prim(primitives.NOTEQUAL, [2,2]) == objtable.w_false
 
 def test_float_boolean():
-    assert prim(p.FLOAT_LESSTHAN, [1.0,2.0]) == objtable.w_true
-    assert prim(p.FLOAT_GREATERTHAN, [3.0,4.0]) == objtable.w_false
-    assert prim(p.FLOAT_LESSOREQUAL, [1.3,2.6]) == objtable.w_true
-    assert prim(p.FLOAT_GREATEROREQUAL, [3.5,4.9]) == objtable.w_false
-    assert prim(p.FLOAT_EQUAL, [2.2,2.2]) == objtable.w_true
-    assert prim(p.FLOAT_NOTEQUAL, [2.2,2.2]) == objtable.w_false
+    assert prim(primitives.FLOAT_LESSTHAN, [1.0,2.0]) == objtable.w_true
+    assert prim(primitives.FLOAT_GREATERTHAN, [3.0,4.0]) == objtable.w_false
+    assert prim(primitives.FLOAT_LESSOREQUAL, [1.3,2.6]) == objtable.w_true
+    assert prim(primitives.FLOAT_GREATEROREQUAL, [3.5,4.9]) == objtable.w_false
+    assert prim(primitives.FLOAT_EQUAL, [2.2,2.2]) == objtable.w_true
+    assert prim(primitives.FLOAT_NOTEQUAL, [2.2,2.2]) == objtable.w_false
     
 def test_block_copy_and_value():
     # see test_interpreter for tests of these opcodes
@@ -291,35 +291,35 @@
     return round(w_f.value,ROUNDING_DIGITS) == round(f,ROUNDING_DIGITS)
 
 def test_primitive_square_root():
-    assert prim(p.FLOAT_SQUARE_ROOT, [4.0]).value == 2.0
-    assert float_equals(prim(p.FLOAT_SQUARE_ROOT, [2.0]), math.sqrt(2))
-    prim_fails(p.FLOAT_SQUARE_ROOT, [-2.0])
+    assert prim(primitives.FLOAT_SQUARE_ROOT, [4.0]).value == 2.0
+    assert float_equals(prim(primitives.FLOAT_SQUARE_ROOT, [2.0]), math.sqrt(2))
+    prim_fails(primitives.FLOAT_SQUARE_ROOT, [-2.0])
 
 def test_primitive_sin():
-    assert prim(p.FLOAT_SIN, [0.0]).value == 0.0
-    assert float_equals(prim(p.FLOAT_SIN, [math.pi]), 0.0)
-    assert float_equals(prim(p.FLOAT_SIN, [math.pi/2]), 1.0)
+    assert prim(primitives.FLOAT_SIN, [0.0]).value == 0.0
+    assert float_equals(prim(primitives.FLOAT_SIN, [math.pi]), 0.0)
+    assert float_equals(prim(primitives.FLOAT_SIN, [math.pi/2]), 1.0)
 
 def test_primitive_arctan():
-    assert prim(p.FLOAT_ARCTAN, [0.0]).value == 0.0
-    assert float_equals(prim(p.FLOAT_ARCTAN, [1]), math.pi/4)
-    assert float_equals(prim(p.FLOAT_ARCTAN, [1e99]), math.pi/2)
+    assert prim(primitives.FLOAT_ARCTAN, [0.0]).value == 0.0
+    assert float_equals(prim(primitives.FLOAT_ARCTAN, [1]), math.pi/4)
+    assert float_equals(prim(primitives.FLOAT_ARCTAN, [1e99]), math.pi/2)
 
 def test_primitive_log_n():
-    assert prim(p.FLOAT_LOG_N, [1.0]).value == 0.0
-    assert prim(p.FLOAT_LOG_N, [math.e]).value == 1.0
-    assert float_equals(prim(p.FLOAT_LOG_N, [10.0]), math.log(10))
-    assert isinf(prim(p.FLOAT_LOG_N, [0.0]).value) # works also for negative infinity
-    assert isnan(prim(p.FLOAT_LOG_N, [-1.0]).value)
+    assert prim(primitives.FLOAT_LOG_N, [1.0]).value == 0.0
+    assert prim(primitives.FLOAT_LOG_N, [math.e]).value == 1.0
+    assert float_equals(prim(primitives.FLOAT_LOG_N, [10.0]), math.log(10))
+    assert isinf(prim(primitives.FLOAT_LOG_N, [0.0]).value) # works also for negative infinity
+    assert isnan(prim(primitives.FLOAT_LOG_N, [-1.0]).value)
 
 def test_primitive_exp():
-    assert float_equals(prim(p.FLOAT_EXP, [-1.0]), 1/math.e)
-    assert prim(p.FLOAT_EXP, [0]).value == 1
-    assert float_equals(prim(p.FLOAT_EXP, [1]), math.e)
-    assert float_equals(prim(p.FLOAT_EXP, [math.log(10)]), 10)
+    assert float_equals(prim(primitives.FLOAT_EXP, [-1.0]), 1/math.e)
+    assert prim(primitives.FLOAT_EXP, [0]).value == 1
+    assert float_equals(prim(primitives.FLOAT_EXP, [1]), math.e)
+    assert float_equals(prim(primitives.FLOAT_EXP, [math.log(10)]), 10)
 
 def equals_ttp(rcvr,arg,res):
-    return float_equals(prim(p.FLOAT_TIMES_TWO_POWER, [rcvr,arg]), res)
+    return float_equals(prim(primitives.FLOAT_TIMES_TWO_POWER, [rcvr,arg]), res)
 
 def test_times_two_power():
     assert equals_ttp(1,1,2)
@@ -332,9 +332,9 @@
 
 def test_inc_gc():
     # Should not fail :-)
-    prim(p.INC_GC, [42]) # Dummy arg
+    prim(primitives.INC_GC, [42]) # Dummy arg
 
 def test_full_gc():
     # Should not fail :-)
-    prim(p.FULL_GC, [42]) # Dummy arg
+    prim(primitives.FULL_GC, [42]) # Dummy arg
 



More information about the Pypy-commit mailing list