[pypy-commit] lang-smalltalk default: added decorator for interpreterProxy functions
lwassermann
noreply at buildbot.pypy.org
Sat Jun 1 11:48:18 CEST 2013
Author: Lars Wassermann <lars.wassermann at gmail.com>
Branch:
Changeset: r431:63aa3c3de920
Date: 2013-05-31 19:30 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/63aa3c3de920/
Log: added decorator for interpreterProxy functions
diff --git a/spyvm/interpreter_proxy.py b/spyvm/interpreter_proxy.py
--- a/spyvm/interpreter_proxy.py
+++ b/spyvm/interpreter_proxy.py
@@ -1,54 +1,74 @@
# struct VirtualMachine* sqGetInterpreterProxy(void);
# typedef struct VirtualMachine {
-# sqInt (*minorVersion)(void);
+# sqInt (*minorVersion)(void);
# } VirtualMachine;
# Loading a Plugin:
-# plugin setInterpreter: proxy.
-# (plugin respondsTo: #initialiseModule) ifTrue:[plugin initialiseModule].
-# plugin perform: primitiveName asSymbol.
+# plugin setInterpreter: proxy.
+# (plugin respondsTo: #initialiseModule) ifTrue:[plugin initialiseModule].
+# plugin perform: primitiveName asSymbol.
from spyvm import error
from rpython.rlib.entrypoint import entrypoint
from rpython.rtyper.annlowlevel import llhelper
from rpython.rlib.exports import export_struct
-from rpython.rtyper.lltypesystem.lltype import FuncType, Struct, Ptr
+from rpython.rtyper.lltypesystem.lltype import FuncType, Ptr
from rpython.rtyper.lltypesystem import lltype
+from rpython.rlib.unroll import unrolling_iterable
sqInt = lltype.Signed
sqLong = lltype.SignedLongLong
-minorVFTP = Ptr(FuncType([], sqInt))
+major = minor = 0
+functions = []
-VirtualMachine = Struct("VirtualMachine",
- ("minorVersion", minorVFTP)
- )
+def expose_on_virtual_machine_proxy(signature, minor=0, major=1):
+ f_ptr = Ptr(signature)
+ if minor < minor:
+ minor = minor
+ if major < major:
+ major = major
+ def decorator(func):
+ functions.append((func.func_name, f_ptr, func))
+ return func
+ return decorator
+
+ at expose_on_virtual_machine_proxy(FuncType([], sqInt))
+def minorVersion():
+ return minor
+
+ at expose_on_virtual_machine_proxy(FuncType([], sqInt))
+def majorVersion():
+ return major
+
+VirtualMachine = lltype.Struct("VirtualMachine",
+ *map(lambda x: (x[0], x[1]), functions))
VMPtr = Ptr(VirtualMachine)
-# export_struct("VirtualMachine", VirtualMachine)
+
+proxy_functions = unrolling_iterable(functions)
@entrypoint('main', [], c_name='sqGetInterpreterProxy')
def sqGetInterpreterProxy():
- if not InterpreterProxy.vm_initialized:
- vm_proxy = lltype.malloc(VirtualMachine, flavor='raw')
- vm_proxy.minorVersion = llhelper(minorVFTP, minorVersion)
- InterpreterProxy.vm_proxy = vm_proxy
- InterpreterProxy.vm_initialized = True
- return InterpreterProxy.vm_proxy
+ if not InterpreterProxy.vm_initialized:
+ vm_proxy = lltype.malloc(VirtualMachine, flavor='raw')
+ for func_name, signature, func in proxy_functions:
+ setattr(vm_proxy, func_name, llhelper(signature, func))
+ InterpreterProxy.vm_proxy = vm_proxy
+ InterpreterProxy.vm_initialized = True
+ return InterpreterProxy.vm_proxy
-def minorVersion():
- return 1
-
+# export_struct("VirtualMachine", VirtualMachine)
class _InterpreterProxy(object):
- _immutable_fields_ = ['vm_initialized?']
+ _immutable_fields_ = ['vm_initialized?']
- def __init__(self):
- self.vm_proxy = lltype.nullptr(VMPtr.TO)
- self.vm_initialized = False
+ def __init__(self):
+ self.vm_proxy = lltype.nullptr(VMPtr.TO)
+ self.vm_initialized = False
- def call(self, signature, interp, s_frame, argcount, s_method):
- print "Hello World..."
- raise error.Exit("External Call")
+ def call(self, signature, interp, s_frame, argcount, s_method):
+ print "Hello World..."
+ raise error.Exit("External Call")
InterpreterProxy = _InterpreterProxy()
diff --git a/spyvm/primitives.py b/spyvm/primitives.py
--- a/spyvm/primitives.py
+++ b/spyvm/primitives.py
@@ -850,6 +850,9 @@
elif signature[0] == "VMDebugging":
from spyvm.plugins.vmdebugging import DebuggingPlugin
return DebuggingPlugin.call(signature[1], interp, s_frame, argcount, s_method)
+ else:
+ from spyvm.interpreter_proxy import InterpreterProxy
+ return InterpreterProxy.call(signature, interp, s_frame, argcount, s_method)
raise PrimitiveFailedError
# ___________________________________________________________________________
diff --git a/targetimageloadingsmalltalk.py b/targetimageloadingsmalltalk.py
--- a/targetimageloadingsmalltalk.py
+++ b/targetimageloadingsmalltalk.py
@@ -7,6 +7,7 @@
from spyvm import model, interpreter, squeakimage, objspace, wrapper,\
error, shadow
from spyvm.tool.analyseimage import create_image
+from spyvm.interpreter_proxy import VirtualMachine
def _run_benchmark(interp, number, benchmark):
More information about the pypy-commit
mailing list