[pypy-svn] r32104 - in pypy/dist/pypy: bin translator/js translator/js/test translator/transformer

fijal at codespeak.net fijal at codespeak.net
Sat Sep 9 09:13:30 CEST 2006


Author: fijal
Date: Sat Sep  9 09:13:05 2006
New Revision: 32104

Modified:
   pypy/dist/pypy/bin/jscompile.py
   pypy/dist/pypy/translator/js/helper.py
   pypy/dist/pypy/translator/js/main.py
   pypy/dist/pypy/translator/js/test/test_transformer.py
   pypy/dist/pypy/translator/transformer/basictransform.py
   pypy/dist/pypy/translator/transformer/debug.py
Log:
jscompile needs to specify manually that we need debug transform. Fix list issues with debug transform (actually fix *in* transform instead of hacking annotator), probably need to track more stuff which track position_key. Some minor improvements in js, now show_traceback is standart (not using innerHTML any more). Need to rewrite as well distributed py.test.


Modified: pypy/dist/pypy/bin/jscompile.py
==============================================================================
--- pypy/dist/pypy/bin/jscompile.py	(original)
+++ pypy/dist/pypy/bin/jscompile.py	Sat Sep  9 09:13:05 2006
@@ -9,15 +9,12 @@
 import autopath
 import sys
 
-from pypy.translator.js.main import rpython2javascript_main
+from pypy.translator.js.main import rpython2javascript_main, Options
 
 from pypy.tool import option
 import optparse
 make_option = optparse.make_option
 
-class Options(option.Options):
-    pass
-
 def get_options():
     options = []
     
@@ -27,13 +24,17 @@
     
     options.append(make_option(
         '-o', '--output', action='store', type='string', dest='output',
-        default='output.js', help='File to save results (default output.js)'))
+        help='File to save results (default output.js)'))
+    
+    options.append(make_option(
+        '-d', '--debug', action='store_true', dest='debug_transform',
+        help="Use !EXPERIMENTAL! debug transform to produce tracebacks"
+    ))
     
     return options
     
 def process_options(argv):
     return option.process_options(get_options(), Options, argv)
-    
 
 if __name__ == '__main__':
     argv = process_options(sys.argv[1:])

Modified: pypy/dist/pypy/translator/js/helper.py
==============================================================================
--- pypy/dist/pypy/translator/js/helper.py	(original)
+++ pypy/dist/pypy/translator/js/helper.py	Sat Sep  9 09:13:05 2006
@@ -16,7 +16,7 @@
     get_document().childNodes[0].childNodes[1].appendChild(debug_div)
     return debug_div
 
-def show_traceback(tb, exc):
+def __show_traceback(tb, exc):
     debug_div = get_document().getElementById("debug_div")
     if not debug_div:
         # create div here
@@ -36,3 +36,5 @@
         txt.nodeValue += line1 + '\n' + line2
 
     txt.nodeValue += str(exc)
+
+__show_traceback.explicit_traceback = True

Modified: pypy/dist/pypy/translator/js/main.py
==============================================================================
--- pypy/dist/pypy/translator/js/main.py	(original)
+++ pypy/dist/pypy/translator/js/main.py	Sat Sep  9 09:13:05 2006
@@ -12,7 +12,12 @@
 from pypy.annotation.policy import AnnotatorPolicy
 import optparse
 import py
-from pypy.tool.option import Options
+from pypy.tool import option
+
+class Options(option.Options):
+    view = False
+    output = 'output.js'
+    debug_transform = False
 
 class FunctionNotFound(Exception):
     pass
@@ -52,7 +57,7 @@
 source_ssf_base = """
 
 import %(module_name)s
-from pypy.translator.js.helper import show_traceback
+from pypy.translator.js.helper import __show_traceback
 from pypy.translator.transformer.debug import traceback_handler
 from pypy.rpython.nonconst import NonConstant as NonConst
 
@@ -71,10 +76,12 @@
         traceback_handler.leave(NonConst("entrypoint"))
     except Exception, e:
         new_tb = traceback_handler.tb[:]
-        show_traceback(new_tb, str(e))
+        __show_traceback(new_tb, str(e))
+
+%(fun_name)s.explicit_traceback = True
 """
 
-function_base = "%(module)s.%(fun_name)s(%(args)s)"
+function_base = "%(module_name)s.%(fun_name)s(%(args)s)"
 wrapped_function_base = "%(fun_name)s(%(args)s)"
 
 def get_source_ssf(mod, module_name, function_names, use_debug=True):
@@ -98,7 +105,7 @@
     print retval
     return retval
 
-def rpython2javascript(mod, function_names, use_debug=True, opts=Options):
+def rpython2javascript(mod, function_names, opts=Options):
     module_name = mod.__name__
     if not function_names and 'main' in mod.__dict__:
         function_names.append('main')
@@ -109,17 +116,18 @@
         if func_code.func_code.co_argcount > 0 and func_code.func_code. \
                 co_argcount != len(func_code.func_defaults):
             raise BadSignature("Function %s does not have default arguments" % func_name)
-    source_ssf = get_source_ssf(mod, module_name, function_names, use_debug)
+    source_ssf = get_source_ssf(mod, module_name, function_names, opts.debug_transform)
     exec(source_ssf) in globals()
     # now we gonna just cut off not needed function
     # XXX: Really do that
     options = optparse.Values(defaults=DEFAULT_OPTIONS)
-    options.debug_transform = use_debug
+    options.debug_transform = opts.debug_transform
+    # XXX: This makes no sense (copying options)
     driver = TranslationDriver(options=options)
     try:
         driver.setup(some_strange_function_which_will_never_be_called, [], policy = JsPolicy())
         driver.proceed(["compile_js"])
-        if getattr(opts, 'view', False):
+        if opts.view:
             driver.translator.view()
         return driver.gen.tmpfile.open().read()
         # XXX: Add some possibility to write down selected file

Modified: pypy/dist/pypy/translator/js/test/test_transformer.py
==============================================================================
--- pypy/dist/pypy/translator/js/test/test_transformer.py	(original)
+++ pypy/dist/pypy/translator/js/test/test_transformer.py	Sat Sep  9 09:13:05 2006
@@ -105,3 +105,29 @@
     retval = fn()
     lst = retval.split("|")
     check_tb(lst[0], "f", "()", wrapper, 3)
+
+def test_list_ann():
+    def z():
+        return 3
+    
+    def f(i,x):
+        l = [i, x, z()]
+        return l
+    
+    def g(i, x):
+        l = f(i, x)
+        l.append(3)
+    
+    def wrapper(a, b):
+        try:
+            traceback_handler.enter(NonConst("entrypoint"), NonConst("()"), NonConst(""), NonConst(0))
+            g(a, b)
+        except:
+            return "|".join(["%s:%s:%s:%s" % k for k in traceback_handler.tb[1:]])
+        return ""
+    
+    fn = compile_function(wrapper, [int, int], debug_transform=True)
+    retval = fn()
+    lst = retval.split("|")
+    assert len(lst) == 1
+    assert lst[0] == ''

Modified: pypy/dist/pypy/translator/transformer/basictransform.py
==============================================================================
--- pypy/dist/pypy/translator/transformer/basictransform.py	(original)
+++ pypy/dist/pypy/translator/transformer/basictransform.py	Sat Sep  9 09:13:05 2006
@@ -43,15 +43,13 @@
         retval = model.Variable()
         return model.SpaceOperation(name, real_args, retval), retval
     
+    def clear_block(self, graph, block):
+        pass
+    
     def add_block(self, graph, block):
-        ann = self.annotator
-        args_s = [ann.bindings[v] for v in block.inputargs]
-        try:
-            del ann.annotated[block]
-        except KeyError:
-            pass
-        ann.addpendingblock(graph, block, args_s)
-        
+        assert self.annotator.annotated[block]
+        self.annotator.reflowpendingblock(graph, block)
+    
     def flow_method(self, _class, func_name, args):
         ann = self.annotator
         bk = self.bookkeeper
@@ -66,7 +64,6 @@
             self.transform_graph(graph)
             checkgraph(graph)
         self.translator.annotator.complete()
-        
 
     def get_const(self, arg):
         bk = self.bookkeeper

Modified: pypy/dist/pypy/translator/transformer/debug.py
==============================================================================
--- pypy/dist/pypy/translator/transformer/debug.py	(original)
+++ pypy/dist/pypy/translator/transformer/debug.py	Sat Sep  9 09:13:05 2006
@@ -45,16 +45,16 @@
             concretetype=bk.immutablevalue(traceback_handler))
         
     def register_helpers(self):
-        return None
         for func_name, func_args in [("traceback", []), 
                 ("enter", ["aa", "aa", "aa", 3]), ("leave", ["aa"])]:
             graph = self.flow_method(TracebackHandler, func_name, func_args)
             graph.explicit_traceback = True
     
     def transform_block(self, graph, block):
+        self.clear_block(graph, block)
         next = []
         changed = False
-        for op in block.operations:
+        for num, op in enumerate(block.operations):
             # XXX: We need to support indirect calls as well, but
             # just need to do it somehow differently
             if op.opname == 'simple_call' and \
@@ -71,6 +71,13 @@
                 next += [opg, opc, op, opgl, oplc]
                 changed = True
                 #next.append(op)
+            elif op.opname == 'newlist':
+                # move listdef position key
+                bk = self.bookkeeper
+                listdef = bk.listdefs[(graph, block, num)]
+                del bk.listdefs[(graph, block, num)]
+                bk.listdefs[(graph, block, len(next))] = listdef
+                next.append(op)
             else:
                 next.append(op)
         block.operations = next
@@ -92,7 +99,8 @@
         return call_str, filename, lineno
         
     def transform_graph(self, graph):
-        if getattr(graph, 'explicit_traceback', None):
+        if getattr(graph, 'explicit_traceback', None) or\
+            getattr(graph.func, 'explicit_traceback', None):
             return
         
         for block in graph.iterblocks():



More information about the Pypy-commit mailing list