[pypy-svn] r26440 - in pypy/dist/pypy/translator/cli: . test

antocuni at codespeak.net antocuni at codespeak.net
Thu Apr 27 13:59:14 CEST 2006


Author: antocuni
Date: Thu Apr 27 13:59:05 2006
New Revision: 26440

Modified:
   pypy/dist/pypy/translator/cli/database.py
   pypy/dist/pypy/translator/cli/function.py
   pypy/dist/pypy/translator/cli/gencli.py
   pypy/dist/pypy/translator/cli/metavm.py
   pypy/dist/pypy/translator/cli/test/compile.py
Log:
Fixed a bug that prevented the code from being compiled when there are
two distinct graphs with the very same name.



Modified: pypy/dist/pypy/translator/cli/database.py
==============================================================================
--- pypy/dist/pypy/translator/cli/database.py	(original)
+++ pypy/dist/pypy/translator/cli/database.py	Thu Apr 27 13:59:05 2006
@@ -38,7 +38,7 @@
     def record_class(self, classdef, name):
         self.classes[classdef] = name
 
-    def function_name(self, graph):
+    def graph_name(self, graph):
         return self.functions.get(graph, None)
 
     def class_name(self, classdef):

Modified: pypy/dist/pypy/translator/cli/function.py
==============================================================================
--- pypy/dist/pypy/translator/cli/function.py	(original)
+++ pypy/dist/pypy/translator/cli/function.py	Thu Apr 27 13:59:05 2006
@@ -47,7 +47,7 @@
         return (not block.exits) and len(block.inputargs) == 2        
 
     def render(self, ilasm):
-        if self.db.function_name(self.graph) is not None and not self.is_method:
+        if self.db.graph_name(self.graph) is not None and not self.is_method:
             return # already rendered
 
         self.ilasm = ilasm
@@ -255,9 +255,10 @@
     def emit(self, instr, *args):
         self.ilasm.opcode(instr, *args)
 
-    def call(self, graph, func_name):
+    def call_graph(self, graph):
         self.db.pending_function(graph)
-        self.ilasm.call(func_name)
+        func_sig = self.function_signature(graph)        
+        self.ilasm.call(func_sig)
 
     def call_signature(self, signature):
         self.ilasm.call(signature)

Modified: pypy/dist/pypy/translator/cli/gencli.py
==============================================================================
--- pypy/dist/pypy/translator/cli/gencli.py	(original)
+++ pypy/dist/pypy/translator/cli/gencli.py	Thu Apr 27 13:59:05 2006
@@ -45,7 +45,8 @@
         
         # TODO: instance methods that are also called as unbound
         # methods are rendered twice, once within the class and once
-        # as an external function. Fix this.        
+        # as an external function. Fix this.
+        self.fix_names()
         self.gen_entrypoint()
         self.gen_pendings()
         self.db.gen_constants(self.ilasm)
@@ -65,4 +66,11 @@
             node = self.db._pending_nodes.pop()
             node.render(self.ilasm)
 
-
+    def fix_names(self):
+        # it could happen that two distinct graph have the same name;
+        # here we assign an unique name to each graph.
+        names = set()
+        for graph in self.translator.graphs:
+            while graph.name in names:
+                graph.name += '_'
+            names.add(graph.name)

Modified: pypy/dist/pypy/translator/cli/metavm.py
==============================================================================
--- pypy/dist/pypy/translator/cli/metavm.py	(original)
+++ pypy/dist/pypy/translator/cli/metavm.py	Thu Apr 27 13:59:05 2006
@@ -63,10 +63,10 @@
             self._render_method(generator, method_name, op.args[1:])
 
     def _render_function(self, generator, graph, args):
-        func_sig = generator.function_signature(graph)
+        #func_sig = generator.function_signature(graph)
         for func_arg in args[1:]: # push parameters
             generator.load(func_arg)
-        generator.call(graph, func_sig)
+        generator.call_graph(graph)
 
     def _render_method(self, generator, method_name, args):
         this = args[0]

Modified: pypy/dist/pypy/translator/cli/test/compile.py
==============================================================================
--- pypy/dist/pypy/translator/cli/test/compile.py	(original)
+++ pypy/dist/pypy/translator/cli/test/compile.py	Thu Apr 27 13:59:05 2006
@@ -26,8 +26,8 @@
 
 
 def bar(x, y):
-    d = {x: y}
-    return d[x]
+    a = [x] + [y]
+    return a[0]
 
 f = compile_function(bar, [int, int])
 



More information about the Pypy-commit mailing list