[pypy-svn] r74935 - pypy/branch/fast-ctypes/pypy/module/jitffi
getxsick at codespeak.net
getxsick at codespeak.net
Sun May 30 22:07:17 CEST 2010
Author: getxsick
Date: Sun May 30 22:07:15 2010
New Revision: 74935
Modified:
pypy/branch/fast-ctypes/pypy/module/jitffi/interp_jitffi.py
Log:
implement call()
it's working with some limitations (e.g. fixed number of arguments etc.)
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 Sun May 30 22:07:15 2010
@@ -4,6 +4,10 @@
from pypy.interpreter.typedef import TypeDef
from pypy.rlib import libffi
from pypy.rpython.lltypesystem import rffi, lltype
+from pypy.jit.backend.x86.runner import CPU
+from pypy.jit.metainterp.history import LoopToken, BasicFailDescr, BoxInt
+from pypy.jit.metainterp.resoperation import ResOperation, rop
+from pypy.jit.metainterp.typesystem import deref
class W_CDLL(Wrappable):
def __init__(self, space, name):
@@ -14,14 +18,45 @@
e.msg or 'unspecified error')
self.name = name
self.space = space
+ self.cpu = CPU(None, None)
- def call(self, space, func, a, b): # XXX temporary fixed number of func args
+ def call(self, space, func, a, b): # XXX temporary fixed number of func args (ints)
+ # result_type argument?
try:
- addr = rffi.cast(lltype.Unsigned, self.cdll.getaddressindll(func))
+ addr = rffi.cast(lltype.Signed, self.cdll.getaddressindll(func))
except KeyError:
raise operationerrfmt(space.w_ValueError,
"Cannot find symbol %s", func)
- # XXX unfinished yet
+
+ bfuncaddr = BoxInt(addr)
+ barg0 = BoxInt(a)
+ barg1 = BoxInt(b)
+ bres = BoxInt()
+
+ FPTR = lltype.Ptr(lltype.FuncType([lltype.Signed, lltype.Signed],
+ lltype.Signed))
+ FUNC = deref(FPTR)
+ calldescr = self.cpu.calldescrof(FUNC, FUNC.ARGS, FUNC.RESULT)
+
+ oplist = [ResOperation(rop.CALL, [bfuncaddr, barg0, barg1], bres,
+ descr=calldescr),
+ ResOperation(rop.FINISH, [bres], None,
+ descr=BasicFailDescr(0))]
+ inputargs = [bfuncaddr, barg0, barg1]
+ looptoken = LoopToken()
+ self.cpu.compile_loop(inputargs, oplist, looptoken)
+
+ i = 0
+ for box in inputargs:
+ self.cpu.set_future_value_int(i, box.getint())
+ i += 1
+
+ res = self.cpu.execute_token(looptoken)
+ if res is oplist[-1].descr:
+ self.guard_failed = False
+ else:
+ self.guard_failed = True
+ return space.wrap(BoxInt(self.cpu.get_latest_value_int(0)).getint())
call.unwrap_spec = ['self', ObjSpace, str, int, int]
def descr_new_cdll(space, w_type, name):
More information about the Pypy-commit
mailing list