[pypy-svn] r14300 - in pypy/dist/pypy: rpython translator/c translator/c/test
pedronis at codespeak.net
pedronis at codespeak.net
Tue Jul 5 18:23:06 CEST 2005
Author: pedronis
Date: Tue Jul 5 18:23:04 2005
New Revision: 14300
Modified:
pypy/dist/pypy/rpython/rstr.py
pypy/dist/pypy/rpython/rtyper.py
pypy/dist/pypy/translator/c/database.py
pypy/dist/pypy/translator/c/node.py
pypy/dist/pypy/translator/c/test/test_database.py
Log:
start of code to have types with fixed names preserved through the backend
Modified: pypy/dist/pypy/rpython/rstr.py
==============================================================================
--- pypy/dist/pypy/rpython/rstr.py (original)
+++ pypy/dist/pypy/rpython/rstr.py Tue Jul 5 18:23:04 2005
@@ -23,8 +23,8 @@
# chars: array of Char
# }
-STR = GcStruct('str', ('hash', Signed),
- ('chars', Array(Char)))
+STR = GcStruct('rpy_string', ('hash', Signed),
+ ('chars', Array(Char)))
SIGNED_ARRAY = GcArray(Signed)
Modified: pypy/dist/pypy/rpython/rtyper.py
==============================================================================
--- pypy/dist/pypy/rpython/rtyper.py (original)
+++ pypy/dist/pypy/rpython/rtyper.py Tue Jul 5 18:23:04 2005
@@ -50,6 +50,7 @@
r = self.getrepr(s_primitive)
self.primitive_to_repr[r.lowleveltype] = r
self.exceptiondata = ExceptionData(self)
+ self.fixednames = self.fixednames.copy()
def getexceptiondata(self):
return self.exceptiondata # built at the end of specialize()
@@ -542,3 +543,6 @@
from pypy.rpython import rlist, rstr, rtuple, rdict
from pypy.rpython import rclass, rbuiltin, rpbc
from pypy.rpython import rptr
+
+RPythonTyper.fixednames = {}
+RPythonTyper.fixednames[rstr.STR] = True
Modified: pypy/dist/pypy/translator/c/database.py
==============================================================================
--- pypy/dist/pypy/translator/c/database.py (original)
+++ pypy/dist/pypy/translator/c/database.py Tue Jul 5 18:23:04 2005
@@ -21,6 +21,16 @@
self.containernodes = {}
self.containerlist = []
self.namespace = CNameManager()
+ if translator is not None and translator.rtyper is not None:
+ rtyper = translator.rtyper
+ for lltype, nameorflag in rtyper.fixednames.iteritems():
+ if nameorflag is True:
+ self.namespace.make_reserved_names(lltype._name)
+ #else:
+ # self.namespace.make_reserved_names(nameorflag)
+ self.fixednames = rtyper.fixednames
+ else:
+ self.fixednames = {}
self.pyobjmaker = PyObjMaker(self.namespace, self.get, translator)
def gettypedefnode(self, T, varlength=1):
Modified: pypy/dist/pypy/translator/c/node.py
==============================================================================
--- pypy/dist/pypy/translator/c/node.py (original)
+++ pypy/dist/pypy/translator/c/node.py Tue Jul 5 18:23:04 2005
@@ -38,7 +38,10 @@
else:
basename = db.gettypedefnode(STRUCT).name
basename = '%s_len%d' % (basename, varlength)
- self.name = db.namespace.uniquename(basename)
+ if STRUCT in db.fixednames:
+ self.name = basename
+ else:
+ self.name = db.namespace.uniquename(basename)
self.dependencies = {}
self.fields = []
self.prefix = somelettersfrom(STRUCT._name) + '_'
Modified: pypy/dist/pypy/translator/c/test/test_database.py
==============================================================================
--- pypy/dist/pypy/translator/c/test/test_database.py (original)
+++ pypy/dist/pypy/translator/c/test/test_database.py Tue Jul 5 18:23:04 2005
@@ -196,6 +196,23 @@
db.complete()
dump_on_stdout(db)
+def test_fixedname():
+ def f():
+ return "foo"
+ t = Translator(f)
+ t.annotate([])
+ t.specialize()
+
+ db = LowLevelDatabase(t)
+ S = GcStruct('rpy_string', ('x', Signed))
+ s = malloc(S)
+ s.x = 42
+ db.get(s)
+ Sname = db.gettype(S)
+ db.get(pyobjectptr(f))
+ from pypy.rpython import rstr
+ assert db.gettype(rstr.STR) == "struct rpy_string @"
+ assert Sname != "struct rpy_string @"
def test_malloc():
S = GcStruct('testing', ('x', Signed), ('y', Signed))
More information about the Pypy-commit
mailing list