[pypy-svn] r50051 - pypy/dist/pypy/translator/c
arigo at codespeak.net
arigo at codespeak.net
Sun Dec 23 21:09:44 CET 2007
Author: arigo
Date: Sun Dec 23 21:09:42 2007
New Revision: 50051
Modified:
pypy/dist/pypy/translator/c/database.py
pypy/dist/pypy/translator/c/funcgen.py
pypy/dist/pypy/translator/c/genc.py
pypy/dist/pypy/translator/c/primitive.py
pypy/dist/pypy/translator/c/support.py
Log:
(rxe) Some general clean-ups in genc.
Modified: pypy/dist/pypy/translator/c/database.py
==============================================================================
--- pypy/dist/pypy/translator/c/database.py (original)
+++ pypy/dist/pypy/translator/c/database.py Sun Dec 23 21:09:42 2007
@@ -7,11 +7,10 @@
from pypy.rpython.lltypesystem.rffi import CConstant
from pypy.tool.sourcetools import valid_identifier
from pypy.translator.c.primitive import PrimitiveName, PrimitiveType
-from pypy.translator.c.primitive import PrimitiveErrorValue
from pypy.translator.c.node import StructDefNode, ArrayDefNode
from pypy.translator.c.node import FixedSizeArrayDefNode, BareBoneArrayDefNode
from pypy.translator.c.node import ContainerNodeFactory, ExtTypeOpaqueDefNode
-from pypy.translator.c.support import cdecl, CNameManager, ErrorValue
+from pypy.translator.c.support import cdecl, CNameManager
from pypy.translator.c.support import log, barebonearray
from pypy.translator.c.extfunc import do_the_getting
from pypy import conftest
@@ -170,15 +169,8 @@
return node
def get(self, obj):
- if isinstance(obj, ErrorValue):
- T = obj.TYPE
- if isinstance(T, Primitive):
- return PrimitiveErrorValue[T]
- elif isinstance(T, Ptr):
- return 'NULL'
- else:
- raise Exception("don't know about %r" % (T,))
- else:
+ # XXX extra indent is preserve svn blame - kind of important IMHO (rxe)
+ if 1:
if isinstance(obj, CConstant):
return obj.c_name # without further checks
T = typeOf(obj)
Modified: pypy/dist/pypy/translator/c/funcgen.py
==============================================================================
--- pypy/dist/pypy/translator/c/funcgen.py (original)
+++ pypy/dist/pypy/translator/c/funcgen.py Sun Dec 23 21:09:42 2007
@@ -1,6 +1,6 @@
from __future__ import generators
from pypy.translator.c.support import USESLOTS # set to False if necessary while refactoring
-from pypy.translator.c.support import cdecl, ErrorValue
+from pypy.translator.c.support import cdecl
from pypy.translator.c.support import llvalue_from_constant, gen_assignments
from pypy.translator.c.support import c_string_constant, barebonearray
from pypy.objspace.flow.model import Variable, Constant, Block
@@ -178,21 +178,6 @@
else:
raise TypeError, "expr(%r)" % (v,)
- def error_return_value(self):
- returnlltype = self.lltypemap(self.graph.getreturnvar())
- return self.db.get(ErrorValue(returnlltype))
-
- def return_with_error(self):
- if self.exception_policy == "CPython":
- assert self.lltypemap(self.graph.getreturnvar()) == PyObjPtr
- v, exc_cleanup_ops = self.graph.exc_cleanup
- vanishing_exc_value = self.expr(v)
- yield 'RPyConvertExceptionToCPython(%s);' % vanishing_exc_value
- for cleanupop in exc_cleanup_ops:
- for line in self.gen_op(cleanupop):
- yield line
- yield 'return %s; ' % self.error_return_value()
-
# ____________________________________________________________
def cfunction_declarations(self):
Modified: pypy/dist/pypy/translator/c/genc.py
==============================================================================
--- pypy/dist/pypy/translator/c/genc.py (original)
+++ pypy/dist/pypy/translator/c/genc.py Sun Dec 23 21:09:42 2007
@@ -23,18 +23,13 @@
_compiled = False
modulename = None
- def __init__(self, translator, entrypoint, config,
- eci=ExternalCompilationInfo(), gcpolicy=None):
+ def __init__(self, translator, entrypoint, config):
self.translator = translator
self.entrypoint = entrypoint
self.entrypoint_name = self.entrypoint.func_name
self.originalentrypoint = entrypoint
- self.gcpolicy = gcpolicy
- if gcpolicy is not None and gcpolicy.requires_stackless:
- config.translation.stackless = True
self.config = config
- self.exports = {}
- self.eci = eci
+ self.eci = ExternalCompilationInfo()
def build_database(self):
translator = self.translator
@@ -59,11 +54,7 @@
thread_enabled=self.config.translation.thread,
sandbox=self.config.translation.sandbox)
self.db = db
-
- # we need a concrete gcpolicy to do this
- self.eci = self.eci.merge(ExternalCompilationInfo(
- libraries=db.gcpolicy.gc_libraries()))
-
+
# give the gc a chance to register interest in the start-up functions it
# need (we call this for its side-effects of db.get())
list(db.gcpolicy.gc_startup_code())
@@ -71,16 +62,19 @@
# build entrypoint and eventually other things to expose
pf = self.getentrypointptr()
pfname = db.get(pf)
- self.exports[self.entrypoint_name] = pf
self.c_entrypoint_name = pfname
db.complete()
-
- self.collect_compilation_info()
+
+ self.collect_compilation_info(db)
return db
have___thread = None
- def collect_compilation_info(self):
+ def collect_compilation_info(self, db):
+ # we need a concrete gcpolicy to do this
+ self.eci = self.eci.merge(ExternalCompilationInfo(
+ libraries=db.gcpolicy.gc_libraries()))
+
all = []
for node in self.db.globalcontainers():
eci = getattr(node, 'compilation_info', None)
@@ -89,12 +83,10 @@
self.eci = self.eci.merge(*all)
def get_gcpolicyclass(self):
- if self.gcpolicy is None:
- name = self.config.translation.gctransformer
- if self.config.translation.stacklessgc:
- name = "%s+stacklessgc" % (name,)
- return gc.name_to_gcpolicy[name]
- return self.gcpolicy
+ name = self.config.translation.gctransformer
+ if self.config.translation.stacklessgc:
+ name = "%s+stacklessgc" % (name,)
+ return gc.name_to_gcpolicy[name]
# use generate_source(defines=DEBUG_DEFINES) to force the #definition
# of the macros that enable debugging assertions
@@ -125,8 +117,7 @@
if not self.standalone:
assert not self.config.translation.instrument
cfile, extra = gen_source(db, modulename, targetdir, self.eci,
- defines = defines,
- exports = self.exports)
+ defines = defines)
else:
if self.config.translation.instrument:
defines['INSTRUMENT'] = 1
@@ -687,7 +678,7 @@
return filename, sg.getextrafiles() + list(eci.separate_module_files)
-def gen_source(database, modulename, targetdir, eci, defines={}, exports={}):
+def gen_source(database, modulename, targetdir, eci, defines={}):
assert not database.standalone
if isinstance(targetdir, str):
targetdir = py.path.local(targetdir)
Modified: pypy/dist/pypy/translator/c/primitive.py
==============================================================================
--- pypy/dist/pypy/translator/c/primitive.py (original)
+++ pypy/dist/pypy/translator/c/primitive.py Sun Dec 23 21:09:42 2007
@@ -158,20 +158,6 @@
Address: 'void* @',
}
-PrimitiveErrorValue = {
- SignedLongLong: '-1LL',
- Signed: '-1',
- UnsignedLongLong: '((unsigned long long) -1)',
- Unsigned: '((unsigned) -1)',
- Float: '-1.0',
- SingleFloat: '-1.0f',
- Char: '((char) -1)',
- UniChar: '((unsigned) -1)',
- Bool: '0 /* error */',
- Void: '/* error */',
- Address: 'NULL',
- }
-
def define_c_primitive(ll_type, c_name):
if ll_type in PrimitiveName:
return
@@ -181,7 +167,6 @@
name_str = '((%s) %%dLL)' % c_name
PrimitiveName[ll_type] = lambda value, db: name_str % value
PrimitiveType[ll_type] = '%s @'% c_name
- PrimitiveErrorValue[ll_type] = '((%s) -1)'% c_name
for ll_type, c_name in [(rffi.SIGNEDCHAR, 'signed char'),
(rffi.UCHAR, 'unsigned char'),
Modified: pypy/dist/pypy/translator/c/support.py
==============================================================================
--- pypy/dist/pypy/translator/c/support.py (original)
+++ pypy/dist/pypy/translator/c/support.py Sun Dec 23 21:09:42 2007
@@ -9,11 +9,6 @@
PyObjPtr = lltype.Ptr(lltype.PyObject)
-
-class ErrorValue:
- def __init__(self, TYPE):
- self.TYPE = TYPE
-
def barebonearray(ARRAY):
"""Check if ARRAY is a 'simple' array type,
i.e. doesn't need a length nor GC headers."""
More information about the Pypy-commit
mailing list