[pypy-commit] lang-smalltalk default: renamed interpreter_proxy.InterpreterProxy to IProxy
lwassermann
noreply at buildbot.pypy.org
Sat Jun 1 11:48:20 CEST 2013
Author: Lars Wassermann <lars.wassermann at gmail.com>
Branch:
Changeset: r433:03dc3c9bbf83
Date: 2013-05-31 22:40 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/03dc3c9bbf83/
Log: renamed interpreter_proxy.InterpreterProxy to IProxy added 13
interpreterProxy functions, oop & Array-result handling is only
stubed
diff --git a/spyvm/interpreter_proxy.py b/spyvm/interpreter_proxy.py
--- a/spyvm/interpreter_proxy.py
+++ b/spyvm/interpreter_proxy.py
@@ -8,8 +8,6 @@
# 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
@@ -17,8 +15,11 @@
from rpython.rtyper.lltypesystem import lltype, rffi
from rpython.rlib.unroll import unrolling_iterable
+from spyvm import error, model
+
sqInt = rffi.INT
sqLong = rffi.LONG
+sqDouble = rffi.DOUBLE
major = minor = 0
functions = []
@@ -42,6 +43,109 @@
def majorVersion():
return major
+ at expose_on_virtual_machine_proxy(FuncType([sqInt], sqInt))
+def pop(nItems):
+ IProxy.s_frame.pop_n(nItems)
+ return 0
+
+ at expose_on_virtual_machine_proxy(FuncType([sqInt, sqInt], sqInt))
+def popthenPush(nItems, oop):
+ s_frame = IProxy.s_frame
+ s_frame.pop_n(nItems)
+ s_frame.push(IProxy.oop_to_object(oop))
+ return 0
+
+ at expose_on_virtual_machine_proxy(FuncType([sqInt], sqInt))
+def push(oop):
+ s_frame = IProxy.s_frame
+ s_frame.push(IProxy.oop_to_object(oop))
+ return 0
+
+ at expose_on_virtual_machine_proxy(FuncType([sqInt], sqInt))
+def pushBool(trueOrFalse):
+ s_frame = IProxy.s_frame
+ if trueOrFalse:
+ s_frame.push(IProxy.interp.space.w_true)
+ else:
+ s_frame.push(IProxy.interp.space.w_false)
+ return 0
+
+ at expose_on_virtual_machine_proxy(FuncType([sqDouble], sqInt))
+def pushFloat(f):
+ s_frame = IProxy.s_frame
+ s_frame.push(IProxy.space.wrap_float(f))
+ return 0
+
+ at expose_on_virtual_machine_proxy(FuncType([sqInt], sqInt))
+def pushInteger(n):
+ s_frame = IProxy.s_frame
+ s_frame.push(IProxy.space.wrap_int(n))
+ return 0
+
+ at expose_on_virtual_machine_proxy(FuncType([sqInt], sqDouble))
+def stackFloatValue(offset):
+ s_frame = IProxy.s_frame
+ f = s_frame.peek(offset)
+ if isinstance(f, model.W_Float):
+ return f.value
+ else:
+ IProxy.successFlag = False
+ return 0.0
+
+ at expose_on_virtual_machine_proxy(FuncType([sqInt], sqInt))
+def stackIntegerValue(offset):
+ s_frame = IProxy.s_frame
+ n = s_frame.peek(offset)
+ try:
+ return IProxy.space.unwrap_int(n)
+ except error.PrimitiveFailedError:
+ IProxy.successFlag = False
+ return 0
+
+ at expose_on_virtual_machine_proxy(FuncType([sqInt], sqInt))
+def stackObjectValue(offset):
+ s_frame = IProxy.s_frame
+ w_object = s_frame.peek(offset)
+ if not isinstance(w_object, model.W_SmallInteger):
+ return IProxy.object_to_oop(w_object)
+ IProxy.successFlag = False
+ return 0
+
+ at expose_on_virtual_machine_proxy(FuncType([sqInt], sqInt))
+def stackValue(offset):
+ s_frame = IProxy.s_frame
+ return IProxy.object_to_oop(s_frame.peek(offset))
+
+ at expose_on_virtual_machine_proxy(FuncType([sqInt], sqInt))
+def argumentCountOf(methodOOP):
+ w_method = IProxy.oop_to_object(methodOOP)
+ if isinstance(w_method, model.W_CompiledMethod):
+ return w_method.argsize
+ IProxy.successFlag = False
+ return 0
+
+ at expose_on_virtual_machine_proxy(FuncType([sqInt], Ptr(lltype.Array(sqInt))))
+def arrayValueOf(oop):
+ w_array = IProxy.oop_to_object(oop)
+ if isinstance(w_array, model.W_WordsObject) or isinstance(w_array, model.W_BytesObject):
+ raise NotImplementedError
+ IProxy.successFlag = False
+ return []
+
+ at expose_on_virtual_machine_proxy(FuncType([sqInt], sqInt))
+def byteSizeOf(oop):
+ w_object = IProxy.oop_to_object(oop)
+ s_class = w_object.shadow_of_my_class(IProxy.space)
+ size = s_class.instsize()
+ if s_class.isvariable():
+ size += w_object.primsize(IProxy.space)
+ if isinstance(w_object, model.W_BytesObject):
+ size *= size * 4
+ return IProxy.space.wrap_int(size)
+
+
+# ##############################################################################
+
VirtualMachine = lltype.Struct("VirtualMachine",
*map(lambda x: (x[0], x[1]), functions),
hints={'c_name': 'VirtualMachine'})
@@ -51,13 +155,13 @@
@entrypoint('main', [], c_name='sqGetInterpreterProxy')
def sqGetInterpreterProxy():
- if not InterpreterProxy.vm_initialized:
+ if not IProxy.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
+ IProxy.vm_proxy = vm_proxy
+ IProxy.vm_initialized = True
+ return IProxy.vm_proxy
# rffi.llexternal is supposed to represent c-functions.
@@ -67,9 +171,31 @@
def __init__(self):
self.vm_proxy = lltype.nullptr(VMPtr.TO)
self.vm_initialized = False
+ self.reset()
+
+ def reset(self):
+ self.interp = None
+ self.s_frame = None
+ self.argcount = 0
+ self.s_method = None
+ self.successFlag = True
def call(self, signature, interp, s_frame, argcount, s_method):
- print "Hello World..."
- raise error.Exit("External Call")
+ self.interp = interp
+ self.s_frame = s_frame
+ self.argcount = argcount
+ self.s_method = s_method
+ self.space = interp.space
+ try:
+ print "Hello World..."
+ raise error.Exit("External Call")
+ finally:
+ self.reset()
-InterpreterProxy = _InterpreterProxy()
+ def oop_to_object(self, oop):
+ return self.interp.space.w_nil
+
+ def object_to_oop(self, oop):
+ return 0
+
+IProxy = _InterpreterProxy()
diff --git a/spyvm/primitives.py b/spyvm/primitives.py
--- a/spyvm/primitives.py
+++ b/spyvm/primitives.py
@@ -851,8 +851,8 @@
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)
+ from spyvm.interpreter_proxy import IProxy
+ return IProxy.call(signature, interp, s_frame, argcount, s_method)
raise PrimitiveFailedError
# ___________________________________________________________________________
More information about the pypy-commit
mailing list