Author: Tim Felgentreff <[email protected]>
Branch: rbigint
Changeset: r334:ec8930f58b8b
Date: 2013-04-24 16:44 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/ec8930f58b8b/

Log:    commit WIP for largeinteger plugin

diff --git a/spyvm/objspace.py b/spyvm/objspace.py
--- a/spyvm/objspace.py
+++ b/spyvm/objspace.py
@@ -227,6 +227,10 @@
     def wrap_char(self, c):
         return self.w_charactertable.fetch(self, ord(c))
 
+    def wrap_rbigint(self, b):
+        bytes
+        w_lpi = self.w_LargePositiveInteger.as_class_get_shadow(self).new(
+
     def wrap_bool(self, b):
         if b:
             return self.w_true
@@ -298,6 +302,26 @@
 
         return [w_array.at0(self, i) for i in range(w_array.size())]
 
+    def unwrap_rbigint(self, w_arg):
+        if isinstance(w_arg, model.W_SmallInteger):
+            arg = rbigint.fromint(space.unwrap_int(w_arg))
+        elif isinstance(w_arg, model.W_LargePositiveInteger1Word):
+            arg = rbigint.fromint(space.unwrap_uint(w_arg))
+        elif isinstance(w_arg, model.W_BytesObject):
+            # TODO: Check actual classes?
+            arg = rbigint.frombytes(w_arg.bytes, 'little', False)
+            if interp.space.getclass(w_arg) is not self.w_LargePositiveInteger:
+                arg = arg.neg()
+        else:
+            raise error.PrimitiveFailedError
+        return arg
+
+    def unwrap_bool(self, w_arg):
+        if w_arg not in (self.w_true, self.w_false):
+            raise PrimitiveFailedError
+        else:
+            return w_arg is self.w_true
+
     def get_display(self):
         w_display = self.objtable['w_display']
         if w_display:
diff --git a/spyvm/plugins/largeintegers.py b/spyvm/plugins/largeintegers.py
new file mode 100644
--- /dev/null
+++ b/spyvm/plugins/largeintegers.py
@@ -0,0 +1,13 @@
+from rpython.rlib import rbigint
+
+from spyvm import model, error
+from spyvm.plugins.plugin import Plugin
+
+
+SocketPlugin = Plugin()
+
+
[email protected]_primitive(unwrap_spec=[rbigint, rbigint, bool])
+def primDigitMultiplyNegative(interp, s_frame, rcvr, arg, neg):
+    result = rcvr.mul(arg)
+
diff --git a/spyvm/primitives.py b/spyvm/primitives.py
--- a/spyvm/primitives.py
+++ b/spyvm/primitives.py
@@ -8,7 +8,7 @@
     PrimitiveNotYetWrittenError
 from spyvm import wrapper
 
-from rpython.rlib import rarithmetic, rfloat, unroll, jit
+from rpython.rlib import rarithmetic, rfloat, unroll, jit, rbigint
 
 def assert_bounds(n0, minimum, maximum):
     if not minimum <= n0 < maximum:
@@ -134,6 +134,10 @@
                         args += (interp.space.unwrap_array(w_arg), )
                     elif spec is char:
                         args += (unwrap_char(w_arg), )
+                    elif spec is rbigint:
+                        arg += (interp.space.unwrap_rbigint(w_arg), )
+                    elif spec is bool:
+                        arg += (interp.space.unwrap_bool(w_arg), )
                     else:
                         raise NotImplementedError(
                             "unknown unwrap_spec %s" % (spec, ))
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to