Author: Tim Felgentreff <[email protected]>
Branch:
Changeset: r325:771472472998
Date: 2013-04-23 18:13 +0200
http://bitbucket.org/pypy/lang-smalltalk/changeset/771472472998/
Log: (lwassermann, timfel) start adding some SocketPlugin primitives so
we can eventually benchmark Seaside
diff --git a/spyvm/plugins/__init__.py b/spyvm/plugins/__init__.py
new file mode 100644
diff --git a/spyvm/plugins/plugin.py b/spyvm/plugins/plugin.py
new file mode 100644
--- /dev/null
+++ b/spyvm/plugins/plugin.py
@@ -0,0 +1,38 @@
+from rpython.rlib import jit
+
+from spyvm import error
+from spyvm.primitives import wrap_primitive
+
+
+class Plugin(object):
+ def __init__(self):
+ self.prims = {}
+ self.userdata = {}
+
+ def call(self, name, interp, s_frame, argcount, s_method):
+ func = self._find_prim(name)
+ if not func:
+ raise error.PrimitiveFailedError
+ else:
+ return func(interp, s_frame, argcount, s_method)
+
+ @jit.elidable
+ def _find_prim(self, name):
+ return self.prims.get(name, None)
+
+ def expose_primitive(self, unwrap_spec=None, no_result=False,
+ result_is_new_frame=False, clean_stack=True,
+ compiled_method=False):
+ def decorator(func):
+ wrapped = wrap_primitive(
+ unwrap_spec=unwrap_spec, no_result=no_result,
+ result_is_new_frame=result_is_new_frame,
+ clean_stack=clean_stack, compiled_method=compiled_method
+ )(func)
+ wrapped.func_name = "wrap_prim_" + func.func_name
+ self.prims[func.func_name] = wrapped
+ return func
+ return decorator
+
+ def _freeze_(self):
+ return True
diff --git a/spyvm/plugins/socket.py b/spyvm/plugins/socket.py
new file mode 100644
--- /dev/null
+++ b/spyvm/plugins/socket.py
@@ -0,0 +1,61 @@
+from rpython.rlib import rsocket
+
+from spyvm import model, error
+from spyvm.plugins.plugin import Plugin
+
+
+SocketPlugin = Plugin()
+
+def is_squeak_socket(w_socket_handle):
+ return not isinstance(w_socket_handle, W_SocketHandle)
+
+
[email protected]_primitive(unwrap_spec=[object, object])
+def primitiveSocketConnectionStatus(interp, s_frame, w_rcvr, w_socket_handle):
+ """ "Socket Status Values"
+ InvalidSocket := -1.
+ Unconnected := 0.
+ WaitingForConnection := 1.
+ Connected := 2.
+ OtherEndClosed := 3.
+ ThisEndClosed := 4. """
+ if is_squeak_socket(w_socket_handle):
+ return interp.space.wrap_int(-1)
+ else:
+ return interp.space.wrap_int(-1) # for now ...
+
+
[email protected]_primitive(unwrap_spec=[object])
+def primitiveResolverStatus(interp, s_frame, w_rcvr):
+ """ "Resolver Status Values"
+ ResolverUninitialized := 0. "network is not initialized"
+ ResolverReady := 1. "resolver idle, last request succeeded"
+ ResolverBusy := 2. "lookup in progress"
+ ResolverError := 3. "resolver idle, last request failed"
+ """
+ if not SocketPlugin.userdata.get("thisNetSession", None):
+ return interp.space.wrap_int(0)
+ elif SocketPlugin.userdata.get("lastError", 0) != 0:
+ return interp.space.wrap_int(3)
+ else:
+ return interp.space.wrap_int(1)
+
+
[email protected]_primitive(unwrap_spec=[object, object])
+def primitiveInitializeNetwork(interp, s_frame, w_rcvr, w_semaphore):
+ """
+ Initialize the network drivers on platforms that need it.
+
+ ... Certainly sir ...
+
+ Note: some platforms (e.g., Mac) only allow
+ only one name lookup query at a time, so a manager process should
+ be used to serialize resolver lookup requests
+
+ ... IGNORE ME! ...
+ """
+ return w_rcvr
+
+
+class W_SocketHandle(model.W_WordsObject):
+ pass
diff --git a/spyvm/primitives.py b/spyvm/primitives.py
--- a/spyvm/primitives.py
+++ b/spyvm/primitives.py
@@ -815,6 +815,8 @@
@expose_primitive(EXTERNAL_CALL, clean_stack=False, no_result=True,
compiled_method=True)
def func(interp, s_frame, argcount, s_method):
+ from spyvm.plugins.socket import SocketPlugin
+
space = interp.space
w_description = s_method.w_self().literalat0(space, 1)
if not isinstance(w_description, model.W_PointersObject) or
w_description.size() < 2:
@@ -828,6 +830,8 @@
if signature == ('BitBltPlugin', 'primitiveCopyBits'):
return prim_holder.prim_table[BITBLT_COPY_BITS](interp, s_frame,
argcount, s_method)
+ elif signature[0] == "SocketPlugin":
+ return SocketPlugin.call(signature[1], interp, s_frame, argcount,
s_method)
raise PrimitiveFailedError
# ___________________________________________________________________________
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit