[pypy-svn] r18663 - pypy/dist/pypy/translator/js

ericvrp at codespeak.net ericvrp at codespeak.net
Sat Oct 15 23:06:36 CEST 2005


Author: ericvrp
Date: Sat Oct 15 23:06:35 2005
New Revision: 18663

Modified:
   pypy/dist/pypy/translator/js/codewriter.py
   pypy/dist/pypy/translator/js/exception.py
   pypy/dist/pypy/translator/js/js.py
   pypy/dist/pypy/translator/js/node.py
   pypy/dist/pypy/translator/js/opwriter.py
Log:
* cleaning up (somewhat) exception policy 
* adapt to js syntax (somwhat)
* replace dot with space in function-names ( A.__init__ )


Modified: pypy/dist/pypy/translator/js/codewriter.py
==============================================================================
--- pypy/dist/pypy/translator/js/codewriter.py	(original)
+++ pypy/dist/pypy/translator/js/codewriter.py	Sat Oct 15 23:06:35 2005
@@ -13,6 +13,9 @@
         self.js = js
         self._skip_closeblock = False
 
+    def skip_closeblock(self, flag=True):
+        self._skip_closeblock = flag
+
     def append(self, line, indentation_level=4): 
         if indentation_level:
             s = self.tabstring * indentation_level
@@ -43,7 +46,7 @@
     def closeblock(self):
         if not self._skip_closeblock:
             self.append('break')
-        self._skip_closeblock = False
+        self.skip_closeblock(False)
 
     def globalinstance(self, name, typeanddata):
         #self.append('%s = %s' % (name, typeanddata[1:].split('{')[1][:-1]), 0)
@@ -98,7 +101,7 @@
     def br_uncond(self, block, exit): 
         self._phi(block, exit)
         self._goto_block(block)
-        self._skip_closeblock = True
+        self.skip_closeblock()
 
     def br(self, cond, block_false, exit_false, block_true, exit_true):
         self.append('if (%s) {' % cond)
@@ -108,7 +111,7 @@
         self._phi(block_false, exit_false, 5)
         self._goto_block(block_false, 5)
         self.append('}')
-        self._skip_closeblock = True
+        self.skip_closeblock()
 
     def switch(self, intty, cond, defaultdest, value_label):
         labels = ''
@@ -147,7 +150,7 @@
             self.append("return")
         else:
             self.append("return " + ref)
-        self._skip_closeblock = True
+        self.skip_closeblock()
 
     def binaryop(self, name, targetvar, type_, ref1, ref2):
         self.append("%(targetvar)s = %(ref1)s %(name)s %(ref2)s" % locals())

Modified: pypy/dist/pypy/translator/js/exception.py
==============================================================================
--- pypy/dist/pypy/translator/js/exception.py	(original)
+++ pypy/dist/pypy/translator/js/exception.py	Sat Oct 15 23:06:35 2005
@@ -1,26 +1,4 @@
 class ExceptionPolicy:
-    RINGBUGGER_SIZE          = 8192
-    RINGBUFFER_ENTRY_MAXSIZE = 16
-    RINGBUGGER_OVERSIZE      = RINGBUGGER_SIZE + RINGBUFFER_ENTRY_MAXSIZE
-    RINGBUFFER_LLVMCODE      = '''
-sbyte* %%malloc_exception(uint %%nbytes) {
-    %%cond = setle uint %%nbytes, %d
-    br bool %%cond, label %%then, label %%else
-
-then:
-    %%tmp.3 = load uint* %%exception_ringbuffer_index
-    %%tmp.4 = getelementptr [%d x sbyte]* %%exception_ringbuffer, int 0, uint %%tmp.3
-    %%tmp.6 = add uint %%tmp.3, %%nbytes
-    %%tmp.7 = and uint %%tmp.6, %d
-    store uint %%tmp.7, uint* %%exception_ringbuffer_index
-    ret sbyte* %%tmp.4
-
-else:
-    %%tmp.8  = call sbyte* %%GC_malloc(uint %%nbytes)
-    ret sbyte* %%tmp.8
-}
-''' % (RINGBUFFER_ENTRY_MAXSIZE, RINGBUGGER_OVERSIZE, RINGBUGGER_SIZE-1)
-
     def __init__(self):
         raise Exception, 'ExceptionPolicy should not be used directly'
 
@@ -71,32 +49,6 @@
     def __init__(self):
         pass
 
-    def llvmcode(self, entrynode):
-        returntype, entrypointname =  entrynode.getdecl().split('%', 1)
-        noresult = self._noresult(returntype)
-        return '''
-%(returntype)s%%__entrypoint__%(entrypointname)s {
-    %%result = invoke %(returntype)s%%%(entrypointname)s to label %%no_exception except label %%exception
-
-no_exception:
-    store %%RPYTHON_EXCEPTION_VTABLE* null, %%RPYTHON_EXCEPTION_VTABLE** %%last_exception_type
-    ret %(returntype)s %%result
-
-exception:
-    ret %(noresult)s
-}
-
-int %%__entrypoint__raised_LLVMException() {
-    %%tmp    = load %%RPYTHON_EXCEPTION_VTABLE** %%last_exception_type
-    %%result = cast %%RPYTHON_EXCEPTION_VTABLE* %%tmp to int
-    ret int %%result
-}
-
-void %%unwind() {
-    unwind
-}
-''' % locals() + self.RINGBUFFER_LLVMCODE
-
     def invoke(self, codewriter, targetvar, returntype, functionref, args, label, except_label):
         labels = 'to label %%%s except label %%%s' % (label, except_label)
         if returntype == 'void':
@@ -113,7 +65,7 @@
         for i, arg in enumerate(inputargs):
             names = db.repr_arg_multi([link.args[i] for link in entrylinks])
             for name in names:  #These tests-by-name are a bit yikes, but I don't see a better way right now
-                if not name.startswith('%last_exception_') and not name.startswith('%last_exc_value_'):
+                if not name.startswith('last_exception_') and not name.startswith('last_exc_value_'):
                     is_raise_new = True
         return is_raise_new
 
@@ -124,33 +76,33 @@
         graph = funcnode.graph
 
         if self._is_raise_new_exception(db, graph, block):
-            funcnode.write_block_phi_nodes(codewriter, block)
-
             inputargs     = db.repr_arg_multi(block.inputargs)
             inputargtypes = db.repr_arg_type_multi(block.inputargs)
 
-            codewriter.store(inputargtypes[0], inputargs[0], '%last_exception_type')
-            codewriter.store(inputargtypes[1], inputargs[1], '%last_exception_value')
+            codewriter.store('last_exception_type' , [], inputargs[0])
+            codewriter.store('last_exception_value', [], inputargs[1])
         else:
             codewriter.comment('reraise last exception')
             #Reraising last_exception.
             #Which is already stored in the global variables.
             #So nothing needs to happen here!
 
-        codewriter.llvm('unwind')
+        codewriter.append('throw "Pypy exception"')
+        codewriter.skip_closeblock()
 
     def fetch_exceptions(self, codewriter, exc_found_labels, lltype_of_exception_type, lltype_of_exception_value):
         for label, target, last_exc_type_var, last_exc_value_var in exc_found_labels:
             codewriter.label(label)
             if last_exc_type_var:    
-                codewriter.load(last_exc_type_var, lltype_of_exception_type, '%last_exception_type')
+                codewriter.load(last_exc_type_var, lltype_of_exception_type, 'last_exception_type')
             if last_exc_value_var:   
-                codewriter.load(last_exc_value_var, lltype_of_exception_value, '%last_exception_value')
+                codewriter.load(last_exc_value_var, lltype_of_exception_value, 'last_exception_value')
             codewriter.br_uncond(target)
 
     def reraise(self, funcnode, codewriter):
         codewriter.comment('reraise when exception is not caught')
-        codewriter.llvm('unwind')
+        codewriter.append('throw "Pypy exception"')
+        codewriter.skip_closeblock()
 
     def llc_options(self):
         return '-enable-correct-eh-support'
@@ -160,35 +112,6 @@
     def __init__(self):
         self.invoke_count = 0
 
-    def llvmcode(self, entrynode):
-        returntype, entrypointname = entrynode.getdecl().split('%', 1)
-        noresult = self._noresult(returntype)
-        return '''
-%(returntype)s%%__entrypoint__%(entrypointname)s {
-    store %%RPYTHON_EXCEPTION_VTABLE* null, %%RPYTHON_EXCEPTION_VTABLE** %%last_exception_type
-    %%result = call %(returntype)s%%%(entrypointname)s
-    %%tmp    = load %%RPYTHON_EXCEPTION_VTABLE** %%last_exception_type
-    %%exc    = seteq %%RPYTHON_EXCEPTION_VTABLE* %%tmp, null
-    br bool %%exc, label %%no_exception, label %%exception
-
-no_exception:
-    ret %(returntype)s %%result
-
-exception:
-    ret %(noresult)s
-}
-
-int %%__entrypoint__raised_LLVMException() {
-    %%tmp    = load %%RPYTHON_EXCEPTION_VTABLE** %%last_exception_type
-    %%result = cast %%RPYTHON_EXCEPTION_VTABLE* %%tmp to int
-    ret int %%result
-}
-
-void %%unwind() {
-    ret void
-}
-''' % locals() + self.RINGBUFFER_LLVMCODE
-
     def transform(self, translator, graph=None):
         from pypy.translator.llvm.backendopt.exception import create_exception_handling
         if graph:
@@ -207,7 +130,7 @@
         tmp = '%%invoke.tmp.%d' % self.invoke_count
         exc = '%%invoke.exc.%d' % self.invoke_count
         self.invoke_count += 1
-        codewriter.llvm('%(tmp)s = load %%RPYTHON_EXCEPTION_VTABLE** %%last_exception_type' % locals())
+        codewriter.llvm('%(tmp)s = load %%RPYTHON_EXCEPTION_VTABLE** last_exception_type' % locals())
         codewriter.llvm('%(exc)s = seteq %%RPYTHON_EXCEPTION_VTABLE* %(tmp)s, null'         % locals())
         codewriter.llvm('br bool %(exc)s, label %%%(label)s, label %%%(except_label)s'      % locals())
 
@@ -221,19 +144,19 @@
         inputargs     = funcnode.db.repr_arg_multi(block.inputargs)
         inputargtypes = funcnode.db.repr_arg_type_multi(block.inputargs)
 
-        codewriter.store(inputargtypes[0], inputargs[0], '%last_exception_type')
-        codewriter.store(inputargtypes[1], inputargs[1], '%last_exception_value')
+        codewriter.store(inputargtypes[0], inputargs[0], 'last_exception_type')
+        codewriter.store(inputargtypes[1], inputargs[1], 'last_exception_value')
         codewriter.llvm('ret ' + noresult)
 
     def fetch_exceptions(self, codewriter, exc_found_labels, lltype_of_exception_type, lltype_of_exception_value):
         for label, target, last_exc_type_var, last_exc_value_var in exc_found_labels:
             codewriter.label(label)
             if last_exc_type_var:    
-                codewriter.load(last_exc_type_var, lltype_of_exception_type, '%last_exception_type')
+                codewriter.load(last_exc_type_var, lltype_of_exception_type, 'last_exception_type')
             if last_exc_value_var:   
-                codewriter.load(last_exc_value_var, lltype_of_exception_value, '%last_exception_value')
-            codewriter.store(lltype_of_exception_type , 'null', '%last_exception_type')
-            codewriter.store(lltype_of_exception_value, 'null', '%last_exception_value')
+                codewriter.load(last_exc_value_var, lltype_of_exception_value, 'last_exception_value')
+            codewriter.store(lltype_of_exception_type , 'null', 'last_exception_type')
+            codewriter.store(lltype_of_exception_value, 'null', 'last_exception_value')
             codewriter.br_uncond(target)
 
     def reraise(self, funcnode, codewriter):

Modified: pypy/dist/pypy/translator/js/js.py
==============================================================================
--- pypy/dist/pypy/translator/js/js.py	(original)
+++ pypy/dist/pypy/translator/js/js.py	Sat Oct 15 23:06:35 2005
@@ -143,6 +143,7 @@
         #codewriter.append(self.wrappercode, 0)
         codewriter.newline()
         codewriter.comment("EOF", 0)
+        f.close()
 
         log('Written:', self.filename)
         return self.filename

Modified: pypy/dist/pypy/translator/js/node.py
==============================================================================
--- pypy/dist/pypy/translator/js/node.py	(original)
+++ pypy/dist/pypy/translator/js/node.py	Sat Oct 15 23:06:35 2005
@@ -15,6 +15,7 @@
         " helper for creating names"
         if " " in name or "<" in name: 
             name = '"%s"' % name
+        name = name.replace('.', '_')
 
         global _nodename_count 
         if name in _nodename_count:

Modified: pypy/dist/pypy/translator/js/opwriter.py
==============================================================================
--- pypy/dist/pypy/translator/js/opwriter.py	(original)
+++ pypy/dist/pypy/translator/js/opwriter.py	Sat Oct 15 23:06:35 2005
@@ -295,7 +295,7 @@
 
         none_label  = self.node.blockindex[link.target]
         block_label = self.node.blockindex[self.block]
-        exc_label   = block_label + '_exception_handling'
+        exc_label   = 10000 + block_label   #_exception_label
 
         #if self.db.is_function_ptr(op.result):  #use longhand form
         #    returntype = "%s (%s)*" % (returntype, ", ".join(argtypes))
@@ -303,11 +303,12 @@
                              argtypes, none_label, exc_label)
 
         e = self.db.translator.rtyper.getexceptiondata()
-        ll_exception_match       = 'pypy_' + e.ll_exception_match.__name__
-        lltype_of_exception_type = ('structtype.' +
+        pypy_prefix              = '' #pypy_
+        ll_exception_match       = pypy_prefix + e.ll_exception_match.__name__
+        lltype_of_exception_type = ('structtype_' +
                                     e.lltype_of_exception_type.TO.__name__
                                     + '*')
-        lltype_of_exception_value = ('structtype.' +
+        lltype_of_exception_value = ('structtype_' +
                                     e.lltype_of_exception_value.TO.__name__
                                     + '*')
 
@@ -321,7 +322,8 @@
             etype = self.db.obj2node[link.llexitcase._obj]
             current_exception_type = etype.get_ref()
             target          = self.node.blockindex[link.target]
-            exc_found_label = block_label + '_exception_found_branchto_' + target
+            #exc_found_label = block_label + '_exception_found_branchto_' + target
+            exc_found_label = '%d_exception_found_branchto_%d' % (block_label, target)
             last_exc_type_var, last_exc_value_var = None, None
 
             for p in self.node.get_phi_data(link.target):



More information about the Pypy-commit mailing list