[pypy-svn] r24116 - in pypy/dist/pypy: rpython/ootypesystem translator/squeak translator/squeak/test
nik at codespeak.net
nik at codespeak.net
Wed Mar 8 17:50:10 CET 2006
Author: nik
Date: Wed Mar 8 17:50:08 2006
New Revision: 24116
Modified:
pypy/dist/pypy/rpython/ootypesystem/ootype.py
pypy/dist/pypy/rpython/ootypesystem/rclass.py
pypy/dist/pypy/translator/squeak/gensqueak.py
pypy/dist/pypy/translator/squeak/test/test_squeaktrans.py
Log:
always integrate package into the squeak class name. this looks really
ugly in the squeak code but is probably inevitable.
Modified: pypy/dist/pypy/rpython/ootypesystem/ootype.py
==============================================================================
--- pypy/dist/pypy/rpython/ootypesystem/ootype.py (original)
+++ pypy/dist/pypy/rpython/ootypesystem/ootype.py Wed Mar 8 17:50:08 2006
@@ -24,7 +24,10 @@
"""this is the type of user-defined objects"""
def __init__(self, name, superclass, fields={}, methods={},
_is_root=False):
- self._name = name
+ package_parts = name.split(".")
+ self._name = package_parts[-1]
+ self._package = ".".join(package_parts[:-1])
+
if _is_root:
self._superclass = None
else:
Modified: pypy/dist/pypy/rpython/ootypesystem/rclass.py
==============================================================================
--- pypy/dist/pypy/rpython/ootypesystem/rclass.py (original)
+++ pypy/dist/pypy/rpython/ootypesystem/rclass.py Wed Mar 8 17:50:08 2006
@@ -163,7 +163,7 @@
else:
b = OBJECT
- self.lowleveltype = ootype.Instance(classdef.shortname, b, {}, {})
+ self.lowleveltype = ootype.Instance(classdef.name, b, {}, {})
self.prebuiltinstances = {} # { id(x): (x, _ptr) }
self.object_type = self.lowleveltype
Modified: pypy/dist/pypy/translator/squeak/gensqueak.py
==============================================================================
--- pypy/dist/pypy/translator/squeak/gensqueak.py (original)
+++ pypy/dist/pypy/translator/squeak/gensqueak.py Wed Mar 8 17:50:08 2006
@@ -237,13 +237,19 @@
# self.pendingfunctions.append(func)
# return sel
- def nameof_Instance(self, inst):
- if inst is None:
- #empty superclass
+ def nameof_Instance(self, INSTANCE):
+ if INSTANCE is None:
return "Object"
- self.note_Instance(inst)
- # XXX need to properly handle package names
- class_name = inst._name.split(".")[-1]
+ self.note_Instance(INSTANCE)
+ # For now, always integrate the package name into the
+ # class name. Later maybe only do this when there actually
+ # is a nameclash.
+ # NB: In theory there could be nameclashes between internal
+ # classes like Root with classes defined in __main__, but
+ # in practice it should never happen because __main__ will
+ # never contain user classes.
+ class_name = "%s_%s" \
+ % (INSTANCE._package.replace(".", "_"), INSTANCE._name)
return "Py%s" % camel_case(class_name.capitalize())
def nameof__instance(self, _inst):
Modified: pypy/dist/pypy/translator/squeak/test/test_squeaktrans.py
==============================================================================
--- pypy/dist/pypy/translator/squeak/test/test_squeaktrans.py (original)
+++ pypy/dist/pypy/translator/squeak/test/test_squeaktrans.py Wed Mar 8 17:50:08 2006
@@ -115,6 +115,14 @@
return A().m(i, j=3)
assert self.run_on_squeak(simplemethod, 1) == "6"
+ def test_nameclash_classes(self):
+ from pypy.translator.squeak.test.support import A as A2
+ class A:
+ def m(self, i): return 2 + i
+ def f():
+ return A().m(0) + A2().m(0)
+ assert self.run_on_squeak(f) == "3"
+
class TestSelector:
More information about the Pypy-commit
mailing list