[pypy-svn] r75972 - in pypy/branch/fast-ctypes/pypy: module/jitffi rlib rlib/test
getxsick at codespeak.net
getxsick at codespeak.net
Wed Jul 7 15:47:32 CEST 2010
Author: getxsick
Date: Wed Jul 7 15:47:30 2010
New Revision: 75972
Modified:
pypy/branch/fast-ctypes/pypy/module/jitffi/interp_jitffi.py
pypy/branch/fast-ctypes/pypy/rlib/rjitffi.py
pypy/branch/fast-ctypes/pypy/rlib/test/test_rjitffi.py
Log:
return results as objects of Return subclasses to be more RPython
Modified: pypy/branch/fast-ctypes/pypy/module/jitffi/interp_jitffi.py
==============================================================================
--- pypy/branch/fast-ctypes/pypy/module/jitffi/interp_jitffi.py (original)
+++ pypy/branch/fast-ctypes/pypy/module/jitffi/interp_jitffi.py Wed Jul 7 15:47:30 2010
@@ -68,9 +68,7 @@
self.rget = rjitffi._Get(cpu, lib, func, args_type, res_type)
def call_w(self, space, w_args=None):
- if space.is_w(w_args, space.w_None):
- return space.wrap(self.rget.call())
- else:
+ if not space.is_w(w_args, space.w_None):
i = 0
w_iterator = space.iter(w_args)
while True:
@@ -93,7 +91,8 @@
space.wrap('Unsupported type of argument: %s'
% self.args_type[0]))
i += 1
- return space.wrap(self.rget.call())
+ res = self.rget.call()
+ return space.wrap(res.value)
def W_Get___new__(space, w_type, cpu, lib, func, args_type, res_type):
try:
Modified: pypy/branch/fast-ctypes/pypy/rlib/rjitffi.py
==============================================================================
--- pypy/branch/fast-ctypes/pypy/rlib/rjitffi.py (original)
+++ pypy/branch/fast-ctypes/pypy/rlib/rjitffi.py Wed Jul 7 15:47:30 2010
@@ -102,18 +102,18 @@
res = self.cpu.execute_token(self.looptoken)
if self.res_type == 'i':
- r = self.cpu.get_latest_value_int(0)
+ r = ReturnInt(self.cpu.get_latest_value_int(0))
elif self.res_type == 'f':
- r = self.cpu.get_latest_value_float(0)
+ r = ReturnFloat(self.cpu.get_latest_value_float(0))
elif self.res_type == 'p':
- r = self.cpu.get_latest_value_ref(0)
+ r = ReturnPtr(self.cpu.get_latest_value_ref(0))
elif self.res_type == 'v':
- r = None
+ r = ReturnNone(None)
else:
raise ValueError(self.res_type)
self.setup_stack() # clean up the stack
- return r # XXX can't return various types
+ return r
def setup_stack(self):
self.esp = 0
@@ -140,3 +140,19 @@
self.args_type = args_type
self.res_type = res_type
self.looptoken = looptoken
+
+class Return(object):
+ def __init__(self, value):
+ self.value = value
+
+class ReturnInt(Return):
+ pass
+
+class ReturnFloat(Return):
+ pass
+
+class ReturnPtr(Return):
+ pass
+
+class ReturnNone(Return):
+ pass
Modified: pypy/branch/fast-ctypes/pypy/rlib/test/test_rjitffi.py
==============================================================================
--- pypy/branch/fast-ctypes/pypy/rlib/test/test_rjitffi.py (original)
+++ pypy/branch/fast-ctypes/pypy/rlib/test/test_rjitffi.py Wed Jul 7 15:47:30 2010
@@ -71,44 +71,44 @@
func = lib.get('add_integers', ['i', 'i'], 'i')
func.push_int(1)
func.push_int(2)
- assert func.call() == 3
+ assert func.call().value == 3
func = lib.get('add_integers', ['i', 'i'], 'i')
func.push_int(-1)
func.push_int(2)
- assert func.call() == 1
+ assert func.call().value == 1
func = lib.get('add_integers', ['i', 'i'], 'i')
func.push_int(0)
func.push_int(0)
- assert func.call() == 0
+ assert func.call().value == 0
func = lib.get('max3', ['i', 'i', 'i'], 'i')
func.push_int(2)
func.push_int(8)
func.push_int(3)
- assert func.call() == 8
+ assert func.call().value == 8
func = lib.get('add_floats', ['f', 'f'], 'f')
func.push_float(1.2)
func.push_float(1.5)
- assert func.call() == 2.7
+ assert func.call().value == 2.7
def test_get_void(self):
lib = rjitffi.CDLL(self.lib_name)
func = lib.get('fvoid', [], 'i')
- assert func.call() == 1
+ assert func.call().value == 1
func = lib.get('return_void', ['i', 'i'], 'v')
func.push_int(1)
func.push_int(2)
- assert func.call() is None
+ assert func.call().value is None
func = lib.get('return_void', ['i', 'i'])
func.push_int(1)
func.push_int(2)
- assert func.call() is None
+ assert func.call().value is None
def test_various_type_args(self):
lib = rjitffi.CDLL(self.lib_name)
@@ -116,12 +116,12 @@
func = lib.get('add_intfloat', ['i', 'f'], 'i')
func.push_int(1)
func.push_float(2.9)
- assert func.call() == 3
+ assert func.call().value == 3
# stack is cleaned up after calling
func.push_int(0)
func.push_float(1.3)
- assert func.call() == 1
+ assert func.call().value == 1
def test_undefined_func(self):
lib = rjitffi.CDLL(self.lib_name)
More information about the Pypy-commit
mailing list