[pypy-svn] r39872 - in pypy/branch/pypy-2.5/pypy: interpreter interpreter/test rlib

xoraxax at codespeak.net xoraxax at codespeak.net
Sun Mar 4 13:24:48 CET 2007


Author: xoraxax
Date: Sun Mar  4 13:24:41 2007
New Revision: 39872

Modified:
   pypy/branch/pypy-2.5/pypy/interpreter/gateway.py
   pypy/branch/pypy-2.5/pypy/interpreter/test/test_gateway.py
   pypy/branch/pypy-2.5/pypy/rlib/streamio.py
Log:
(xorAxAx, gbrandl, samuele in the kitchen) Added gateway support for the index protocol.

Modified: pypy/branch/pypy-2.5/pypy/interpreter/gateway.py
==============================================================================
--- pypy/branch/pypy-2.5/pypy/interpreter/gateway.py	(original)
+++ pypy/branch/pypy-2.5/pypy/interpreter/gateway.py	Sun Mar  4 13:24:41 2007
@@ -106,7 +106,17 @@
 
     def visit_self(self, cls, app_sig):
         self.visit__Wrappable(cls, app_sig)
-        
+
+    def checked_space_method(self, typ, app_sig):
+        argname = self.orig_arg()
+        assert not argname.startswith('w_'), (
+            "unwrapped %s argument %s of built-in function %r should "
+            "not start with 'w_'" % (typ.__name__, argname, self.func))
+        app_sig.append(argname)
+
+    def visit_index(self, index, app_sig):
+        self.checked_space_method(index, app_sig)
+
     def visit__Wrappable(self, el, app_sig):
         name = el.__name__
         argname = self.orig_arg()
@@ -154,11 +164,7 @@
     def visit__object(self, typ, app_sig):
         if typ not in (int, str, float):
             assert False, "unsupported basic type in unwrap_spec"
-        argname = self.orig_arg()
-        assert not argname.startswith('w_'), (
-            "unwrapped %s argument %s of built-in function %r should "
-            "not start with 'w_'" % (typ.__name__, argname, self.func))
-        app_sig.append(argname)        
+        self.checked_space_method(typ, app_sig)
 
 
 class UnwrapSpec_EmitRun(UnwrapSpecEmit):
@@ -207,6 +213,9 @@
         self.run_args.append("space.%s_w(%s)" %
                              (typ.__name__, self.scopenext()))
 
+    def visit_index(self, typ):
+        self.run_args.append("space.getindex_w(%s)" % (self.scopenext(), ))
+
     def _make_unwrap_activation_class(self, unwrap_spec, cache={}):
         try:
             key = tuple(unwrap_spec)
@@ -316,6 +325,9 @@
         self.unwrap.append("space.%s_w(%s)" % (typ.__name__,
                                                self.nextarg()))
 
+    def visit_index(self, typ):
+        self.unwrap.append("space.getindex_w(%s)" % (self.nextarg()), )
+
     def make_fastfunc(unwrap_spec, func):
         unwrap_info = UnwrapSpec_FastFunc_Unwrap()
         unwrap_info.apply_over(unwrap_spec)

Modified: pypy/branch/pypy-2.5/pypy/interpreter/test/test_gateway.py
==============================================================================
--- pypy/branch/pypy-2.5/pypy/interpreter/test/test_gateway.py	(original)
+++ pypy/branch/pypy-2.5/pypy/interpreter/test/test_gateway.py	Sun Mar  4 13:24:41 2007
@@ -33,6 +33,12 @@
                                                    gateway.Arguments])
         assert code.signature() == (['x', 'y'], 'args', 'keywords')
 
+        def f(space, index):
+            pass
+        code = gateway.BuiltinCode(f, unwrap_spec=[gateway.ObjSpace, "index"])
+        assert code.signature() == (["index"], None, None)
+
+
     def test_call(self):
         def c(space, w_x, w_y, hello_w):
             u = space.unwrap
@@ -50,6 +56,15 @@
         w_result = code.funcrun(FakeFunc(self.space, "c"), args)
         assert self.space.eq_w(w_result, w(102))
 
+    def test_call_index(self):
+        def c(space, index):
+            assert type(index) is int
+        code = gateway.BuiltinCode(c, unwrap_spec=[gateway.ObjSpace,
+                                                   "index"])
+        w = self.space.wrap
+        args = argument.Arguments(self.space, [w(123)])
+        code.funcrun(FakeFunc(self.space, "c"), args)
+
     def test_call_args(self):
         def c(space, w_x, w_y, __args__):
             args_w, kwds_w = __args__.unpack()

Modified: pypy/branch/pypy-2.5/pypy/rlib/streamio.py
==============================================================================
--- pypy/branch/pypy-2.5/pypy/rlib/streamio.py	(original)
+++ pypy/branch/pypy-2.5/pypy/rlib/streamio.py	Sun Mar  4 13:24:41 2007
@@ -356,7 +356,7 @@
     ("read", [int]),
     ("write", [str]),
     ("tell", []),
-    ("seek", [int, int]),
+    ("seek", ["index", int]),
     ("readall", []),
     ("readline", []),
     ("truncate", [int]),



More information about the Pypy-commit mailing list