[pypy-svn] r14397 - pypy/dist/pypy/translator/c
arigo at codespeak.net
arigo at codespeak.net
Thu Jul 7 19:47:15 CEST 2005
Author: arigo
Date: Thu Jul 7 19:47:11 2005
New Revision: 14397
Added:
pypy/dist/pypy/translator/c/extfunc_include.h (contents, props changed)
Removed:
pypy/dist/pypy/translator/c/extfunc.py
Modified:
pypy/dist/pypy/translator/c/database.py
pypy/dist/pypy/translator/c/fixedname.py
pypy/dist/pypy/translator/c/g_include.h
pypy/dist/pypy/translator/c/node.py
Log:
Calling external functions seems to go in the good direction.
Replaced extfunc.py with a C include file, extfunc_include.h.
Modified: pypy/dist/pypy/translator/c/database.py
==============================================================================
--- pypy/dist/pypy/translator/c/database.py (original)
+++ pypy/dist/pypy/translator/c/database.py Thu Jul 7 19:47:11 2005
@@ -19,6 +19,7 @@
self.structdeflist = []
self.containernodes = {}
self.containerlist = []
+ self.externalfuncs = {}
self.namespace = CNameManager()
self.pyobjmaker = PyObjMaker(self.namespace, self.get, translator)
Deleted: /pypy/dist/pypy/translator/c/extfunc.py
==============================================================================
--- /pypy/dist/pypy/translator/c/extfunc.py Thu Jul 7 19:47:11 2005
+++ (empty file)
@@ -1,33 +0,0 @@
-import py
-from pypy.rpython import extfunctable, lltype
-
-
-class CHandWrittenWrapperFunctionCodeGenerator:
-
- def __init__(self, funcobj):
- self.funcobj = funcobj
- self.c_code = ll_externaltable[funcobj._callable]
-
- def argnames(self):
- argcount = len(lltype.typeOf(self.funcobj).ARGS)
- return ['a%d' % i for i in range(argcount)]
-
- def allconstantvalues(self):
- return []
-
- def cfunction_declarations(self):
- return []
-
- def cfunction_body(self):
- source = py.code.Source(self.c_code).strip()
- return list(source)
-
-
-# map {ll_xyz_helper: bit of C code}
-
-ll_externaltable = {
-
- extfunctable.ll_time_clock: """
- return ((double)clock()) / CLOCKS_PER_SEC;
- """,
-}
Added: pypy/dist/pypy/translator/c/extfunc_include.h
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/translator/c/extfunc_include.h Thu Jul 7 19:47:11 2005
@@ -0,0 +1,13 @@
+/************************************************************/
+ /*** C header subsection: external functions ***/
+
+#include <time.h>
+
+/* The functions below are mapped to functions from pypy.rpython.extfunctable
+ by the pypy.translator.c.fixedname.EXTERNALS dictionary. */
+
+
+double LL_time_clock(void)
+{
+ return ((double) clock()) / CLOCKS_PER_SEC;
+}
Modified: pypy/dist/pypy/translator/c/fixedname.py
==============================================================================
--- pypy/dist/pypy/translator/c/fixedname.py (original)
+++ pypy/dist/pypy/translator/c/fixedname.py Thu Jul 7 19:47:11 2005
@@ -1,16 +1,30 @@
import types
-from pypy.rpython.lltype import Ptr, pyobjectptr, LowLevelType
+from pypy.rpython.lltype import Ptr, pyobjectptr, LowLevelType, _ptr, typeOf
from pypy.translator.c.support import cdecl
from pypy.rpython.rmodel import getfunctionptr
from pypy.rpython.rstr import STR
+from pypy.rpython import extfunctable
-def predeclare_common_types(rtyper):
+# table of functions hand-written in extfunc_include.h
+EXTERNALS = {
+ extfunctable.ll_time_clock: 'LL_time_clock',
+ }
+
+
+def predeclare_common_types(db, rtyper):
# Common types
yield ('RPyString', Ptr(STR))
-def predeclare_exception_data(rtyper):
+def predeclare_extfuncs(db, rtyper):
+ for func, funcobj in db.externalfuncs.items():
+ c_name = EXTERNALS[func]
+ funcptr = _ptr(Ptr(typeOf(funcobj)), funcobj) # hum
+ yield c_name, funcptr
+
+
+def predeclare_exception_data(db, rtyper):
# Exception-related types and constants
exceptiondata = rtyper.getexceptiondata()
@@ -28,11 +42,12 @@
yield ('Exc_%s' % pyexccls.__name__, exc_llvalue)
-def predeclare_all(rtyper):
+def predeclare_all(db, rtyper):
for fn in [predeclare_common_types,
- predeclare_exception_data
+ predeclare_exception_data,
+ predeclare_extfuncs,
]:
- for t in fn(rtyper):
+ for t in fn(db, rtyper):
yield t
# ____________________________________________________________
@@ -56,7 +71,7 @@
typename = db.gettype(lowleveltype)
return 'typedef %s;' % cdecl(typename, c_typename)
- for c_name, obj in predeclare_all(rtyper):
+ for c_name, obj in predeclare_all(db, rtyper):
if isinstance(obj, LowLevelType):
yield predeclaretype(c_name, obj)
elif isinstance(obj, types.FunctionType):
Modified: pypy/dist/pypy/translator/c/g_include.h
==============================================================================
--- pypy/dist/pypy/translator/c/g_include.h (original)
+++ pypy/dist/pypy/translator/c/g_include.h Thu Jul 7 19:47:11 2005
@@ -21,3 +21,4 @@
#include "float_include.h"
#include "ll_include.h"
#include "pyobj_include.h"
+#include "extfunc_include.h"
Modified: pypy/dist/pypy/translator/c/node.py
==============================================================================
--- pypy/dist/pypy/translator/c/node.py (original)
+++ pypy/dist/pypy/translator/c/node.py Thu Jul 7 19:47:11 2005
@@ -5,10 +5,9 @@
from pypy.rpython.lltype import RuntimeTypeInfo, getRuntimeTypeInfo
from pypy.translator.c.funcgen import FunctionCodeGenerator
from pypy.translator.c.external import CExternalFunctionCodeGenerator
-from pypy.translator.c.extfunc import ll_externaltable
-from pypy.translator.c.extfunc import CHandWrittenWrapperFunctionCodeGenerator
from pypy.translator.c.support import cdecl, somelettersfrom
from pypy.translator.c.primitive import PrimitiveType
+from pypy.translator.c import fixedname
def needs_refcount(T):
@@ -470,11 +469,12 @@
def select_function_code_generator(fnobj, db):
- if fnobj._callable in ll_externaltable:
+ if fnobj._callable in fixedname.EXTERNALS:
# 'fnobj' is one of the ll_xyz() functions special-cased in
# pypy.rpython.extfunctable. The corresponding C wrappers are written
- # in extfunc.py.
- return CHandWrittenWrapperFunctionCodeGenerator(fnobj)
+ # by hand in extfunc_include.h, and declared in fixedname.EXTERNALS.
+ db.externalfuncs[fnobj._callable] = fnobj
+ return None
elif hasattr(fnobj, 'graph'):
cpython_exc = getattr(fnobj, 'exception_policy', None) == "CPython"
return FunctionCodeGenerator(fnobj.graph, db, cpython_exc)
More information about the Pypy-commit
mailing list