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

ericvrp at codespeak.net ericvrp at codespeak.net
Wed Oct 26 14:12:44 CEST 2005


Author: ericvrp
Date: Wed Oct 26 14:12:42 2005
New Revision: 19004

Modified:
   pypy/dist/pypy/translator/js/arraynode.py
   pypy/dist/pypy/translator/js/codewriter.py
   pypy/dist/pypy/translator/js/database.py
   pypy/dist/pypy/translator/js/exception.txt
   pypy/dist/pypy/translator/js/funcnode.py
   pypy/dist/pypy/translator/js/gc.txt
   pypy/dist/pypy/translator/js/js.py
   pypy/dist/pypy/translator/js/node.py
   pypy/dist/pypy/translator/js/opaquenode.py
   pypy/dist/pypy/translator/js/opwriter.py
Log:
* added ll_issubclass function

* added catch exception matching



Modified: pypy/dist/pypy/translator/js/arraynode.py
==============================================================================
--- pypy/dist/pypy/translator/js/arraynode.py	(original)
+++ pypy/dist/pypy/translator/js/arraynode.py	Wed Oct 26 14:12:42 2005
@@ -64,7 +64,11 @@
 
     def constantvalue(self):
         s = '"'
-        for c in self.value.items:
+        if len(self.value.items) > 0 and self.value.items[-1] == '\0':
+            items = self.value.items[:-1]   #remove string null terminator
+        else:
+            items = self.value.items
+        for c in items:
             if ord(c) in StrArrayNode.printables:
                 s += c
             else:

Modified: pypy/dist/pypy/translator/js/codewriter.py
==============================================================================
--- pypy/dist/pypy/translator/js/codewriter.py	(original)
+++ pypy/dist/pypy/translator/js/codewriter.py	Wed Oct 26 14:12:42 2005
@@ -17,7 +17,7 @@
         self._skip_closeblock = flag
 
     def append(self, line, indentation_level=4): 
-        if indentation_level:
+        if line and indentation_level:
             s = self.tabstring * indentation_level
         else:
             s = ''
@@ -131,8 +131,8 @@
     def neg(self, targetvar, source):
         self.append('%(targetvar)s = -%(source)s' % locals())
         
-    def call(self, targetvar, functionref, argrefs, label=None, exception_exits=[]):
-        if exception_exits:
+    def call(self, targetvar, functionref, argrefs, label=None, exceptions=[], ll_issubclass=None):
+        if exceptions:
             assert label is not None
             self.append('try {')
             indentation_level = 5
@@ -143,12 +143,18 @@
         args = ", ".join(argrefs)
         self.append('%s = %s(%s)' % (targetvar, functionref, args), indentation_level)
 
-        if exception_exits:
-            self.append('block = %d' % label, indentation_level)
+        if exceptions:
+            self._goto_block(label, indentation_level)
             self.append('} catch (e) {')
-            for exception in exception_exits:
-                self.comment('exception.target = %s' % str(exception.target), indentation_level)
-            self.append('block = %d' % label, indentation_level)    #XXX temp
+            for i, exception in enumerate(exceptions):
+                exception_match, exception_ref, exception_target = exception
+                if i:
+                    s = 'else '
+                else:
+                    s = ''
+                self.append('%sif (%s(e.typeptr, %s) == true) {' % (s, exception_match, exception_ref), indentation_level)
+                self._goto_block(exception_target, indentation_level+1)
+                self.append('}', indentation_level)
             self.append('}')
 
     def cast(self, targetvar, fromtype, fromvar, targettype):
@@ -187,3 +193,6 @@
         res += ''.join(['[%s]' % index for index in destindices])
         res += " = %(srcvar)s" % locals()
         self.append(res)
+
+    def throw(self, exc):
+        self.append('throw ' + exc)

Modified: pypy/dist/pypy/translator/js/database.py
==============================================================================
--- pypy/dist/pypy/translator/js/database.py	(original)
+++ pypy/dist/pypy/translator/js/database.py	Wed Oct 26 14:12:42 2005
@@ -24,8 +24,7 @@
             lltype.UniChar: "uint",
             lltype.Void: "void"}
 
-    def __init__(self, genllvm, translator): 
-        self.genllvm = genllvm
+    def __init__(self, translator): 
         self.translator = translator
         self.obj2node = {}
         self._pendingsetup = []

Modified: pypy/dist/pypy/translator/js/exception.txt
==============================================================================
--- pypy/dist/pypy/translator/js/exception.txt	(original)
+++ pypy/dist/pypy/translator/js/exception.txt	Wed Oct 26 14:12:42 2005
@@ -8,7 +8,6 @@
     def new(exceptionpolicy=None):  #factory
         exceptionpolicy = exceptionpolicy or 'invokeunwind'
         if exceptionpolicy == 'invokeunwind':
-            from pypy.translator.js.exception import InvokeUnwindExceptionPolicy
             exceptionpolicy = InvokeUnwindExceptionPolicy()
         else:
             raise Exception, 'unknown exceptionpolicy: ' + str(exceptionpolicy)

Modified: pypy/dist/pypy/translator/js/funcnode.py
==============================================================================
--- pypy/dist/pypy/translator/js/funcnode.py	(original)
+++ pypy/dist/pypy/translator/js/funcnode.py	Wed Oct 26 14:12:42 2005
@@ -110,14 +110,9 @@
 
     def write_returnblock(self, codewriter, block):
         assert len(block.inputargs) == 1
-        # #self.write_block_phi_nodes(codewriter, block)
-        # inputargtype = self.db.repr_arg_type(block.inputargs[0])
-        # inputarg = self.db.repr_arg(block.inputargs[0])
-        # codewriter.ret(inputargtype, inputarg)
         codewriter.ret( self.db.repr_arg(block.inputargs[0]) )
 
     def write_exceptblock(self, codewriter, block):
-        #self.db.genllvm.exceptionpolicy.write_exceptblock(self, codewriter, block)
-        codewriter.comment('XXX TODO write_exceptblock')
-        codewriter.append('throw "Pypy exception"')
+        assert len(block.inputargs) == 2
+        codewriter.throw( str(block.inputargs[1]) )
         codewriter.skip_closeblock()

Modified: pypy/dist/pypy/translator/js/gc.txt
==============================================================================
--- pypy/dist/pypy/translator/js/gc.txt	(original)
+++ pypy/dist/pypy/translator/js/gc.txt	Wed Oct 26 14:12:42 2005
@@ -28,13 +28,10 @@
             gcpolicy = 'none'
 
         if gcpolicy == 'boehm':
-            from pypy.translator.js.gc import BoehmGcPolicy
             gcpolicy = BoehmGcPolicy()
         elif gcpolicy == 'ref':
-            from pypy.translator.js.gc import RefcountingGcPolicy
             gcpolicy = RefcountingGcPolicy()
         elif gcpolicy == 'none':
-            from pypy.translator.js.gc import NoneGcPolicy
             gcpolicy = NoneGcPolicy()
         else:
             raise Exception, 'unknown gcpolicy: ' + str(gcpolicy)

Modified: pypy/dist/pypy/translator/js/js.py
==============================================================================
--- pypy/dist/pypy/translator/js/js.py	(original)
+++ pypy/dist/pypy/translator/js/js.py	Wed Oct 26 14:12:42 2005
@@ -25,7 +25,7 @@
 
 class JS(object):   # JS = Javascript
     def __init__(self, translator, function=None, debug=False):
-        self.db = Database(self, translator)
+        self.db = Database(translator)
         self.translator = translator
         LLVMNode.reset_nodename_count()
         #extfuncnode.ExternalFuncNode.used_external_functions = {}
@@ -41,11 +41,16 @@
 
     def write_source(self):
         func = self.entrypoint
-        ptr = getfunctionptr(self.translator, func)
-        c = inputconst(lltype.typeOf(ptr), ptr)
-        entry_point = c.value._obj
+        ptr  = getfunctionptr(self.translator, func)
+        c    = inputconst(lltype.typeOf(ptr), ptr)
         self.db.prepare_arg_value(c)
 
+        #add functions
+        e          = self.db.translator.rtyper.getexceptiondata()
+        matchptr   = getfunctionptr(self.db.translator, e.ll_exception_match)
+        matchconst = inputconst(lltype.typeOf(matchptr), matchptr)
+        self.db.prepare_arg_value(matchconst)
+
         # set up all nodes
         self.db.setup_all()
         #self.entrynode = self.db.set_entrynode(entry_point)
@@ -125,6 +130,7 @@
         #    codewriter.comment("External Function Implementation", 0)
         #    codewriter.append(llexterns_functions)
 
+        entry_point= c.value._obj
         graph      = self.db.obj2node[entry_point].graph
         startblock = graph.startblock
         args       = ','.join(['arguments[%d]' % i for i,v in enumerate(startblock.inputargs)])

Modified: pypy/dist/pypy/translator/js/node.py
==============================================================================
--- pypy/dist/pypy/translator/js/node.py	(original)
+++ pypy/dist/pypy/translator/js/node.py	Wed Oct 26 14:12:42 2005
@@ -56,9 +56,6 @@
         """ Returns the constant representation for this node. """
         return []
 
-    # ______________________________________________________________________
-    # entry points from genllvm
-
     def writeglobalconstants(self, codewriter):
         p, c = lltype.parentlink(self.value)
         if p is None:

Modified: pypy/dist/pypy/translator/js/opaquenode.py
==============================================================================
--- pypy/dist/pypy/translator/js/opaquenode.py	(original)
+++ pypy/dist/pypy/translator/js/opaquenode.py	Wed Oct 26 14:12:42 2005
@@ -7,8 +7,6 @@
         self.db = db
         self.value = value
         self.ref = "null"
-    # ______________________________________________________________________
-    # main entry points from genllvm 
 
     def writeglobalconstants(self, codewriter):
         # XXX Dummy - not sure what what we want

Modified: pypy/dist/pypy/translator/js/opwriter.py
==============================================================================
--- pypy/dist/pypy/translator/js/opwriter.py	(original)
+++ pypy/dist/pypy/translator/js/opwriter.py	Wed Oct 26 14:12:42 2005
@@ -1,7 +1,7 @@
 import py
 from pypy.objspace.flow.model import Constant
 from pypy.rpython.lltypesystem import lltype
-#from pypy.translator.js.module.extfunction import extfunctions
+from pypy.rpython.rmodel import inputconst, getfunctionptr
 from pypy.translator.js.extfuncnode import ExternalFuncNode
 from pypy.translator.js.log import log 
 log = log.opwriter
@@ -204,7 +204,8 @@
         targettype = self.db.repr_concretetype(op.result.concretetype)
         fromvar = self.db.repr_arg(op.args[0])
         fromtype = self.db.repr_concretetype(op.args[0].concretetype)
-        self.codewriter.comment('next line=%s, from %s to %s' % (op.opname, fromtype, targettype))
+        if op.opname not in ('cast_pointer',):
+            self.codewriter.comment('next line=%s, from %s to %s' % (op.opname, fromtype, targettype))
         self.codewriter.cast(targetvar, fromtype, fromvar, targettype)
     same_as = cast_primitive
 
@@ -267,18 +268,25 @@
         link = self.block.exits[0]
         assert link.exitcase is None
 
-        targetvar   = self.db.repr_arg(op.result)
-        #returntype  = self.db.repr_arg_type(op.result)
-        argrefs     = self.db.repr_arg_multi(op_args[1:])
-        #argtypes    = self.db.repr_arg_type_multi(op_args[1:])
-
-        none_label  = self.node.blockindex[link.target]
-        block_label = self.node.blockindex[self.block]
-        #exc_label   = block_label   #_exception_label
+        targetvar  = self.db.repr_arg(op.result)
+        argrefs    = self.db.repr_arg_multi(op_args[1:])
+        none_label = self.node.blockindex[link.target]
+
+        exceptions = []
+        for exit in self.block.exits[1:]:
+            assert issubclass(exit.exitcase, Exception)
+            exception_match  = self.db.translator.rtyper.getexceptiondata().ll_exception_match.__name__
+            exception_ref    = self.db.obj2node[exit.llexitcase._obj].get_ref()
+            exception_target = self.node.blockindex[exit.target]
+            exception        = (exception_match, exception_ref, exception_target)
+            exceptions.append(exception)
 
-        self.codewriter.call(targetvar, functionref, argrefs, none_label, self.block.exits[1:])
+        self.codewriter.call(targetvar, functionref, argrefs, none_label, exceptions)
         return
 
+
+
+
         e = self.db.translator.rtyper.getexceptiondata()
         pypy_prefix              = '' #pypy_
         ll_exception_match       = pypy_prefix + e.ll_exception_match.__name__



More information about the Pypy-commit mailing list