[pypy-svn] r26102 - in pypy/dist/pypy: module/_demo rpython/rctypes rpython/rctypes/socketmodule rpython/rctypes/test rpython/rctypes/tool rpython/rctypes/tool/test translator/goal

arigo at codespeak.net arigo at codespeak.net
Fri Apr 21 15:43:16 CEST 2006


Author: arigo
Date: Fri Apr 21 15:43:13 2006
New Revision: 26102

Added:
   pypy/dist/pypy/rpython/rctypes/tool/   (props changed)
   pypy/dist/pypy/rpython/rctypes/tool/__init__.py
      - copied unchanged from r26097, pypy/dist/pypy/rpython/rctypes/__init__.py
   pypy/dist/pypy/rpython/rctypes/tool/compilemodule.py   (contents, props changed)
   pypy/dist/pypy/rpython/rctypes/tool/cpyobjspace.py   (contents, props changed)
   pypy/dist/pypy/rpython/rctypes/tool/ctypes_platform.py
      - copied unchanged from r26097, pypy/dist/pypy/rpython/rctypes/ctypes_platform.py
   pypy/dist/pypy/rpython/rctypes/tool/test/   (props changed)
   pypy/dist/pypy/rpython/rctypes/tool/test/__init__.py
      - copied unchanged from r26097, pypy/dist/pypy/rpython/rctypes/test/__init__.py
   pypy/dist/pypy/rpython/rctypes/tool/test/test_ctypes_platform.py
      - copied, changed from r26097, pypy/dist/pypy/rpython/rctypes/test/test_ctypes_platform.py
Removed:
   pypy/dist/pypy/rpython/rctypes/ctypes_platform.py
   pypy/dist/pypy/rpython/rctypes/test/test_ctypes_platform.py
Modified:
   pypy/dist/pypy/module/_demo/demo.py
   pypy/dist/pypy/rpython/rctypes/socketmodule/ctypes_socket.py
   pypy/dist/pypy/translator/goal/targetdemomodule.py
Log:
Intermediate check-in: reorganize files, add a dir rctypes/tool/
where things will be moved to when they start working in
targetdemomodule.py.  The CPyObjSpace is now there.  Any ideas
for a better place to put the compilemodule.py script?


Modified: pypy/dist/pypy/module/_demo/demo.py
==============================================================================
--- pypy/dist/pypy/module/_demo/demo.py	(original)
+++ pypy/dist/pypy/module/_demo/demo.py	Fri Apr 21 15:43:13 2006
@@ -1,6 +1,6 @@
 from pypy.interpreter.error import OperationError
 from pypy.interpreter.baseobjspace import ObjSpace, W_Root
-from pypy.rpython.rctypes import implementation, ctypes_platform
+from pypy.rpython.rctypes.tool import ctypes_platform
 import sys
 from ctypes import *
 

Modified: pypy/dist/pypy/rpython/rctypes/socketmodule/ctypes_socket.py
==============================================================================
--- pypy/dist/pypy/rpython/rctypes/socketmodule/ctypes_socket.py	(original)
+++ pypy/dist/pypy/rpython/rctypes/socketmodule/ctypes_socket.py	Fri Apr 21 15:43:13 2006
@@ -1,5 +1,5 @@
 import os
-from pypy.rpython.rctypes import ctypes_platform
+from pypy.rpython.rctypes.tool import ctypes_platform
 from ctypes import *
 
 includes = ('sys/types.h',

Added: pypy/dist/pypy/rpython/rctypes/tool/compilemodule.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/rpython/rctypes/tool/compilemodule.py	Fri Apr 21 15:43:13 2006
@@ -0,0 +1,32 @@
+#! /usr/bin/env python
+"""
+Usage:  compilemodule.py <module-name>
+
+Compiles the PyPy extension module from  pypy/module/<module-name>/
+into a regular CPython extension module.
+"""
+
+import sys
+import pypy.rpython.rctypes.implementation
+from pypy.translator.goal.ann_override import PyPyAnnotatorPolicy
+from pypy.rpython.rctypes.tool.cpyobjspace import CPyObjSpace
+from pypy.translator.driver import TranslationDriver
+
+
+def compilemodule(modname):
+    "Compile a PyPy module for CPython."
+
+    space = CPyObjSpace()
+    ModuleClass = __import__('pypy.module.%s' % modname,
+                             None, None, ['Module']).Module
+    module = ModuleClass(space, space.wrap(modname))
+    w_moduledict = module.getdict()
+
+    XXX in-progress, for now see translator/goal/targetdemomodule.py
+
+
+if __name__ == '__main__':
+    if len(sys.argv) != 2:
+        print >> sys.stderr, __doc__
+        sys.exit(2)
+    compilemodule(sys.argv[1])

Added: pypy/dist/pypy/rpython/rctypes/tool/cpyobjspace.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/rpython/rctypes/tool/cpyobjspace.py	Fri Apr 21 15:43:13 2006
@@ -0,0 +1,88 @@
+import sys
+from ctypes import *
+
+assert sys.version < (2, 5), "XXX fix Py_ssize_t for Python 2.5"
+Py_ssize_t = c_int
+
+PyObject_GetAttr = pythonapi.PyObject_GetAttr
+PyObject_GetAttr.argtypes = [py_object, py_object]
+PyObject_GetAttr.restype = py_object
+
+PyImport_ImportModule = pythonapi.PyImport_ImportModule
+PyImport_ImportModule.argtypes = [c_char_p]
+PyImport_ImportModule.restype = py_object
+
+PyInt_FromLong = pythonapi.PyInt_FromLong
+PyInt_FromLong.argtypes = [c_long]
+PyInt_FromLong.restype = py_object
+
+PyString_FromStringAndSize = pythonapi.PyString_FromStringAndSize
+PyString_FromStringAndSize.argtypes = [c_char_p, Py_ssize_t]
+PyString_FromStringAndSize.restype = py_object
+
+PyString_InternInPlace = pythonapi.PyString_InternInPlace
+PyString_InternInPlace.argtypes = [POINTER(py_object)]
+PyString_InternInPlace.restype = None
+
+PyObject_SetItem = pythonapi.PyObject_SetItem
+PyObject_SetItem.argtypes = [py_object, py_object, py_object]
+PyObject_SetItem.restype = c_int
+
+PyObject_Call = pythonapi.PyObject_Call
+PyObject_Call.argtypes = [py_object, py_object, py_object]
+PyObject_Call.restype = py_object
+
+PyTuple_New = pythonapi.PyTuple_New
+PyTuple_New.argtypes = [Py_ssize_t]
+PyTuple_New.restype = py_object
+
+PyDict_New = pythonapi.PyDict_New
+PyDict_New.argtypes = []
+PyDict_New.restype = py_object
+
+PyDict_SetItem = pythonapi.PyDict_SetItem
+PyDict_SetItem.argtypes = [py_object, py_object, py_object]
+PyDict_SetItem.restype = c_int
+
+
+class CPyObjSpace:
+    W_Object = py_object
+
+    def __init__(self):
+        self.w_int = py_object(int)
+        self.w_None = py_object(None)
+        self.w_False = py_object(False)
+        self.w_True = py_object(True)
+
+    def getbuiltinmodule(self, name):
+        return PyImport_ImportModule(name)
+
+    def wrap(self, x):
+        if x is None:
+            return self.w_None
+        if isinstance(x, int):
+            return PyInt_FromLong(x)
+        if isinstance(x, str):
+            return PyString_FromStringAndSize(x, len(x))
+        raise TypeError("wrap(%r)" % (x,))
+    wrap._annspecialcase_ = "specialize:wrap"
+
+    def getattr(self, w_obj, w_attr):
+        return PyObject_GetAttr(w_obj, w_attr)
+
+    def call_function(self, w_callable):
+        return PyObject_Call(w_callable, PyTuple_New(0), PyDict_New())
+
+    def _freeze_(self):
+        return True
+
+    def new_interned_str(self, s):
+        w_s = self.wrap(s)
+        PyString_InternInPlace(byref(w_s))
+        return w_s
+
+    def newdict(self, items_w):
+        w_dict = PyDict_New()
+        for w_key, w_value in items_w:
+            PyDict_SetItem(w_dict, w_key, w_value)
+        return w_dict

Modified: pypy/dist/pypy/translator/goal/targetdemomodule.py
==============================================================================
--- pypy/dist/pypy/translator/goal/targetdemomodule.py	(original)
+++ pypy/dist/pypy/translator/goal/targetdemomodule.py	Fri Apr 21 15:43:13 2006
@@ -1,63 +1,7 @@
 from pypy.module._demo import demo
 from pypy.translator.goal.ann_override import PyPyAnnotatorPolicy
-
-from ctypes import *
-
-Py_ssize_t = c_int    # XXX changes in Python 2.5
-
-PyObject_GetAttr = pythonapi.PyObject_GetAttr
-PyObject_GetAttr.argtypes = [py_object, py_object]
-PyObject_GetAttr.restype = py_object
-
-PyImport_ImportModule = pythonapi.PyImport_ImportModule
-PyImport_ImportModule.argtypes = [c_char_p]
-PyImport_ImportModule.restype = py_object
-
-PyInt_FromLong = pythonapi.PyInt_FromLong
-PyInt_FromLong.argtypes = [c_long]
-PyInt_FromLong.restype = py_object
-
-PyString_FromStringAndSize = pythonapi.PyString_FromStringAndSize
-PyString_FromStringAndSize.argtypes = [c_char_p, Py_ssize_t]
-PyString_FromStringAndSize.restype = py_object
-
-PyObject_Call = pythonapi.PyObject_Call
-PyObject_Call.argtypes = [py_object, py_object, py_object]
-PyObject_Call.restype = py_object
-
-PyTuple_New = pythonapi.PyTuple_New
-PyTuple_New.argtypes = [Py_ssize_t]
-PyTuple_New.restype = py_object
-
-PyDict_New = pythonapi.PyDict_New
-PyDict_New.argtypes = []
-PyDict_New.restype = py_object
-
-
-class CPyObjSpace:
-
-    def __init__(self):
-        self.w_int = py_object(int)
-        self.w_None = py_object(None)
-
-    def getbuiltinmodule(self, name):
-        return PyImport_ImportModule(name)
-
-    def wrap(self, x):
-        if x is None:
-            return self.w_None
-        if isinstance(x, int):
-            return PyInt_FromLong(x)
-        if isinstance(x, str):
-            return PyString_FromStringAndSize(x, len(x))
-        raise TypeError("wrap(%r)" % (x,))
-    wrap._annspecialcase_ = "specialize:wrap"
-
-    def getattr(self, w_obj, w_attr):
-        return PyObject_GetAttr(w_obj, w_attr)
-
-    def call_function(self, w_callable):
-        return PyObject_Call(w_callable, PyTuple_New(0), PyDict_New())
+from pypy.rpython.rctypes.tool.cpyobjspace import CPyObjSpace
+import pypy.rpython.rctypes.implementation
 
 
 space = CPyObjSpace()
@@ -68,7 +12,7 @@
 # _____ Define and setup target ___
 
 def target(*args):
-    return entry_point, [int, py_object], PyPyAnnotatorPolicy()
+    return entry_point, [int, CPyObjSpace.W_Object], PyPyAnnotatorPolicy()
 
 
 if __name__ == '__main__':



More information about the Pypy-commit mailing list