[pypy-svn] r20538 - in pypy/branch/somepbc-refactoring/pypy/translator/squeak: . test

arigo at codespeak.net arigo at codespeak.net
Thu Dec 1 22:48:11 CET 2005


Author: arigo
Date: Thu Dec  1 22:48:10 2005
New Revision: 20538

Modified:
   pypy/branch/somepbc-refactoring/pypy/translator/squeak/gensqueak.py
   pypy/branch/somepbc-refactoring/pypy/translator/squeak/test/test_oo.py
   pypy/branch/somepbc-refactoring/pypy/translator/squeak/test/test_squeaktrans.py
Log:
(pedronis, arigo)

Fixed the Squeak tests.  (Hopefully didn't harm gensqueak
too much in the process.)



Modified: pypy/branch/somepbc-refactoring/pypy/translator/squeak/gensqueak.py
==============================================================================
--- pypy/branch/somepbc-refactoring/pypy/translator/squeak/gensqueak.py	(original)
+++ pypy/branch/somepbc-refactoring/pypy/translator/squeak/gensqueak.py	Thu Dec  1 22:48:10 2005
@@ -22,13 +22,13 @@
         words[i] = words[i].capitalize()
     return ''.join(words)
 
-def arg_names(func, names = None):
+def arg_names(graph):
     #XXX need to handle more args, see 
     #    http://docs.python.org/ref/types.html#l2h-139
-    co = func.func_code
-    if not names:
-        names = co.co_varnames
-    return names[:co.co_argcount]
+    names, vararg, kwarg = graph.signature
+    assert vararg is None
+    assert kwarg is None
+    return names
 
 def selector(name, args):
     s = name
@@ -82,39 +82,38 @@
         self.sqdir = sqdir
         self.translator = translator
         self.modname = (modname or
-                        translator.functions[0].__name__)
+                        translator.graphs[0].name)
         self.sqnames = {
             Constant(None).key:  'nil',
             Constant(False).key: 'false',
             Constant(True).key:  'true',
         }
         self.seennames = {}
-        self.pendingfunctions = []
+        self.pendinggraphs = []
         self.pendingclasses = []
         self.pendingmethods = []
         self.classes = [] 
         self.methods = [] 
 
         t = self.translator
-        func = t.functions[0]
-        graph = t.getflowgraph(func)
+        graph = t.graphs[0]
         simplify_graph(graph)
         remove_direct_loops(t, graph)
         checkgraph(graph)
         #self.translator.view()
 
-        self.nameof(func) #add to pending
-        file = self.sqdir.join('%s.st' % func.__name__).open('w')
+        self.nameof(graph) #add to pending
+        file = self.sqdir.join('%s.st' % graph.name).open('w')
         self.gen_source(file)
         file.close()
         #self.translator.view()
 
 
     def gen_source(self, file):
-        while self.pendingfunctions or self.pendingclasses or self.pendingmethods:
-            while self.pendingfunctions:
-                func = self.pendingfunctions.pop()
-                self.gen_sqfunction(func, file)
+        while self.pendinggraphs or self.pendingclasses or self.pendingmethods:
+            while self.pendinggraphs:
+                graph = self.pendinggraphs.pop()
+                self.gen_sqfunction(graph, file)
             while self.pendingclasses:
                 inst = self.pendingclasses.pop()
                 self.gen_sqclass(inst, file)
@@ -146,7 +145,7 @@
         print >> f
 
 
-    def gen_sqfunction(self, func, f):
+    def gen_sqfunction(self, graph, f):
 
         def expr(v):
             if isinstance(v, Variable):
@@ -239,12 +238,9 @@
                         yield "    %s" % line
                     yield "]"
 
-        t = self.translator
-        graph = t.getflowgraph(func)
-
         start = graph.startblock
         args = [expr(arg) for arg in start.inputargs]
-        print >> f, '%s' % signature(self.nameof(func), args)
+        print >> f, '%s' % signature(self.nameof(graph), args)
     
         loops = LoopFinder(start).loops
 
@@ -276,27 +272,35 @@
     def nameof_str(self, s):
         return "'s'"
 
-    def nameof_function(self, func):
+    def nameof_FunctionGraph(self, graph):
         #XXX this should actually be a StaticMeth
-        printable_name = '(%s:%d) %s' % (
-            func.func_globals.get('__name__', '?'),
-            func.func_code.co_firstlineno,
-            func.__name__)
-        if self.translator.frozen:
-            if func not in self.translator.flowgraphs:
-                print "NOT GENERATING", printable_name
-                return self.skipped_function(func)
-        else:
-            if (func.func_doc and
-                func.func_doc.lstrip().startswith('NOT_RPYTHON')):
-                print "skipped", printable_name
-                return self.skipped_function(func)
-        name = self.unique_name(func.__name__)
-        args = arg_names(func)
+        name = self.unique_name(graph.name.split('.')[-1])
+        args = arg_names(graph)
         sel = selector(name, args)
-        self.pendingfunctions.append(func)
+        self.pendinggraphs.append(graph)
         return sel
 
+    #def nameof_function(self, func):
+    #    #XXX this should actually be a StaticMeth
+    #    printable_name = '(%s:%d) %s' % (
+    #        func.func_globals.get('__name__', '?'),
+    #        func.func_code.co_firstlineno,
+    #        func.__name__)
+    #    if self.translator.frozen:
+    #        if func not in self.translator.flowgraphs:
+    #            print "NOT GENERATING", printable_name
+    #            return self.skipped_function(func)
+    #    else:
+    #        if (func.func_doc and
+    #            func.func_doc.lstrip().startswith('NOT_RPYTHON')):
+    #            print "skipped", printable_name
+    #            return self.skipped_function(func)
+    #    name = self.unique_name(func.__name__)
+    #    args = arg_names(func)
+    #    sel = selector(name, args)
+    #    self.pendingfunctions.append(func)
+    #    return sel
+
     def nameof_Instance(self, inst):
         if inst is None:
             #empty superclass

Modified: pypy/branch/somepbc-refactoring/pypy/translator/squeak/test/test_oo.py
==============================================================================
--- pypy/branch/somepbc-refactoring/pypy/translator/squeak/test/test_oo.py	(original)
+++ pypy/branch/somepbc-refactoring/pypy/translator/squeak/test/test_oo.py	Thu Dec  1 22:48:10 2005
@@ -1,16 +1,15 @@
 from pypy.tool.udir import udir
 from pypy.translator.squeak.gensqueak import GenSqueak
-from pypy.translator.translator import Translator
+from pypy.translator.translator import TranslationContext
 from pypy.rpython.ootypesystem.ootype import *
 
 
 def build_sqfunc(func, args=[], view=False):
    try: func = func.im_func
    except AttributeError: pass
-   t = Translator(func)
-   t.annotate(args)
-   t.specialize(type_system="ootype")
-   t.simplify()
+   t = TranslationContext()
+   t.buildannotator().build_types(func, args)
+   t.buildrtyper(type_system="ootype").specialize()
    if view:
       t.viewcg()
    GenSqueak(udir, t)

Modified: pypy/branch/somepbc-refactoring/pypy/translator/squeak/test/test_squeaktrans.py
==============================================================================
--- pypy/branch/somepbc-refactoring/pypy/translator/squeak/test/test_squeaktrans.py	(original)
+++ pypy/branch/somepbc-refactoring/pypy/translator/squeak/test/test_squeaktrans.py	Thu Dec  1 22:48:10 2005
@@ -1,7 +1,7 @@
 from pypy.tool.udir import udir
 from pypy.translator.test import snippet
 from pypy.translator.squeak.gensqueak import GenSqueak
-from pypy.translator.translator import Translator
+from pypy.translator.translator import TranslationContext
 
 
 def looping(i = (int), j = (int)):
@@ -15,8 +15,9 @@
     def build_sqfunc(self, func):
         try: func = func.im_func
         except AttributeError: pass
-        t = Translator(func)
-        t.simplify()
+        t = TranslationContext()
+        graph = t.buildflowgraph(func)
+        t._prebuilt_graphs[func] = graph
         self.gen = GenSqueak(udir, t)
 
     def test_simple_func(self):



More information about the Pypy-commit mailing list