[pypy-svn] r24169 - in pypy/dist/pypy/translator/squeak: . test
nik at codespeak.net
nik at codespeak.net
Thu Mar 9 13:33:43 CET 2006
Author: nik
Date: Thu Mar 9 13:33:42 2006
New Revision: 24169
Modified:
pypy/dist/pypy/translator/squeak/gensqueak.py
pypy/dist/pypy/translator/squeak/test/test_squeaktrans.py
Log:
after consulting from pedronis, make the generation of squeak unique
identifiers almost ridiculously easy. package names are not integrated
into class names anymore.
Modified: pypy/dist/pypy/translator/squeak/gensqueak.py
==============================================================================
--- pypy/dist/pypy/translator/squeak/gensqueak.py (original)
+++ pypy/dist/pypy/translator/squeak/gensqueak.py Thu Mar 9 13:33:42 2006
@@ -225,20 +225,8 @@
if INSTANCE is None:
return "Object"
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.
- # XXX It's impossible with the current ootypesystem to
- # distinguish two equally named classes in the same
- # package. For now, just hope that this never actually
- # occurs within PyPy.
- class_name = INSTANCE._name
- class_name = class_name[0].upper() + class_name[1:]
- squeak_class_name = self.unique_name(class_name)
+ class_name = INSTANCE._name.split(".")[-1]
+ squeak_class_name = self.unique_name(INSTANCE, class_name)
return "Py%s" % squeak_class_name
def nameof__instance(self, inst):
@@ -248,10 +236,7 @@
return self.nameof_function(callable.graph.func)
def nameof_function(self, function):
- func_name = function.__name__
- if function.__module__:
- func_name = "%s.%s" % (function.__module__, func_name)
- squeak_func_name = self.unique_name(func_name)
+ squeak_func_name = self.unique_name(function, function.__name__)
return squeak_func_name
def note_Instance(self, inst):
@@ -275,13 +260,9 @@
if graph not in self.pendinggraphs:
self.pendinggraphs.append(graph)
- def unique_name(self, basename):
- # This can be used for both classes and functions, even though
- # they live in different namespaces. As long as class names
- # starting with an uppercase letter are enforced, interferences
- # should be seldom.
- if self.name_mapping.has_key(basename):
- unique = self.name_mapping[basename]
+ def unique_name(self, key, basename):
+ if self.name_mapping.has_key(key):
+ unique = self.name_mapping[key]
else:
camel_basename = camel_case(basename)
unique = camel_basename
@@ -289,7 +270,7 @@
while unique in self.seennames:
unique = camel_basename + str(ext)
ext += 1
- self.name_mapping[basename] = unique
+ self.name_mapping[key] = unique
self.seennames.add(unique)
return unique
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 Thu Mar 9 13:33:42 2006
@@ -80,11 +80,9 @@
"variable to point to an image.")
arg_types = [type(arg) for arg in args]
gen_squeak = build_sqfunc(function, arg_types)
- squeak_func_name = camel_case("%s.%s"
- % (function.__module__, function.__name__))
cmd = 'squeak -headless -- %s %s "%s" %s' \
% (self.startup_st, udir.join(gen_squeak.filename),
- Selector(squeak_func_name, len(args)).symbol(),
+ Selector(function.__name__, len(args)).symbol(),
" ".join(['"%s"' % a for a in args]))
squeak_process = os.popen(cmd)
result = squeak_process.read()
@@ -134,6 +132,16 @@
return A().m(0) + A2().m(0)
assert self.run_on_squeak(f) == "3"
+ def test_nameclash_classes_mean(self):
+ class A:
+ def m(self, i): return 1 + i
+ A2 = A
+ 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"
+
def test_nameclash_camel_case(self):
class ASomething:
def m(self, i): return 1 + i
More information about the Pypy-commit
mailing list