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

ericvrp at codespeak.net ericvrp at codespeak.net
Tue Oct 18 11:04:12 CEST 2005


Author: ericvrp
Date: Tue Oct 18 11:04:11 2005
New Revision: 18729

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/extfuncnode.py
   pypy/dist/pypy/translator/js/funcnode.py
   pypy/dist/pypy/translator/js/js.py
   pypy/dist/pypy/translator/js/node.py
   pypy/dist/pypy/translator/js/opwriter.py
   pypy/dist/pypy/translator/js/structnode.py
Log:
Working on exception handling. Some cleaning up.


Modified: pypy/dist/pypy/translator/js/arraynode.py
==============================================================================
--- pypy/dist/pypy/translator/js/arraynode.py	(original)
+++ pypy/dist/pypy/translator/js/arraynode.py	Tue Oct 18 11:04:11 2005
@@ -40,30 +40,9 @@
         else:
             codewriter.declare(self.ref + ' = new Array()')
 
-    def get_length(self):
-        """ returns logical length of array """
-        items = self.value.items
-        return len(items)
-
-    def get_arrayvalue(self):
-        items = self.value.items
-        l = len(items)
-        r = "[%s]" % ", ".join([self.db.repr_constant(v)[1] for v in items])
-        return l, r 
-
     def get_ref(self):
         return self.ref
 
-    #def get_pbcref(self, toptr):
-    #    return self.ref
-    #    #ref = self.ref
-    #    #p, c = lltype.parentlink(self.value)
-    #    #assert p is None, "child arrays are NOT needed by rtyper"
-    #    #
-    #    #fromptr = "%s*" % self.get_typerepr()
-    #    #ref = "cast(%s %s to %s)" % (fromptr, ref, toptr)
-    #    #return ref
-
     def get_childref(self, index):
         return "getelementptr(%s* %s, int 0, uint 1, int %s)" %(
             self.get_typerepr(),
@@ -71,8 +50,12 @@
             index)
     
     def constantvalue(self):
-        physicallen, arrayrepr = self.get_arrayvalue()
-        return arrayrepr
+        lines = []
+        for i, v in enumerate(self.value.items):
+            s = self.db.repr_constant(v)[1]
+            line = "%s[%d] = %s" % (self.ref, i, s)
+            lines.append(line)
+        return lines
 
 
 class StrArrayNode(ArrayNode):
@@ -83,21 +66,18 @@
        "ABCDEFGHIJKLMNOPQRSTUVWXYZ" +
        "!#$%&()*+,-./:;<=>?@[]^_`{|}~ '")])
 
-    def get_arrayvalue(self):
-        items = self.value.items
-        item_length = len(items)
-        s = []
-        for c in items:
+    def constantvalue(self):
+        s = '"'
+        for c in self.value.items:
             if ord(c) in StrArrayNode.printables:
-                s.append(c)
+                s += c
             else:
-                s.append("\\%02x" % ord(c))
-                
-        r = '"%s"' % "".join(s)
-        return item_length, r
+                s += "\\%02x" % ord(c)
+        s += '"'
+        return [self.ref + " = " + s]
 
 
-class VoidArrayNode(ConstantLLVMNode):
+class VoidArrayNode(ArrayNode):
     __slots__ = "db value ref".split()
 
     def __init__(self, db, value):
@@ -107,6 +87,3 @@
         prefix = 'arrayinstance_Void'
         name = ''
         self.ref = self.make_ref(prefix, name)
-
-    def constantvalue(self):
-        return "{ int } {int %s}" % len(self.value.items)

Modified: pypy/dist/pypy/translator/js/codewriter.py
==============================================================================
--- pypy/dist/pypy/translator/js/codewriter.py	(original)
+++ pypy/dist/pypy/translator/js/codewriter.py	Tue Oct 18 11:04:11 2005
@@ -36,9 +36,6 @@
     def newline(self):
         self.append("")
 
-    def label(self, name):
-        self.append("case %d:" % name, 3)
-
     def openblock(self, name):
         self.append("case %d:" % name, 3)
         self._currentblock = name
@@ -48,34 +45,13 @@
             self.append('break')
         self.skip_closeblock(False)
 
-    def globalinstance(self, name, typeanddata):
-        #self.append('%s = %s' % (name, typeanddata[1:].split('{')[1][:-1]), 0)
-        lines = typeanddata.split('\n')
-        #self.llvm("%s = global %s" % (name, lines[0]), 0)
-        self.append("%s = %s" % (name, lines[0]), 0)
-        for line in lines[1:]:
-            self.llvm(line, 0)
-
-    def structdef(self, name, typereprs):
-        #self.llvm("%s = type { %s }" %(name, ", ".join(typereprs)), 0)
-        pass
-
-    def arraydef(self, name, lentype, typerepr):
-        #self.llvm("%s = type { %s, [0 x %s] }" % (name, lentype, typerepr), 0)
-        pass
-
-    def funcdef(self, name, rettyperepr, argtypereprs):
-        #self.llvm("%s = type %s (%s)" % (name, rettyperepr,
-        #                                   ", ".join(argtypereprs)), 0)
-        pass
+    def globalinstance(self, lines=[]):
+        for line in lines:
+            self.append(line, 0)
 
     def declare(self, decl):
         self.append(decl, 0)
 
-    def startimpl(self):
-        #self.llvm("implementation", 0)
-        pass
-
     def _goto_block(self, block, indentation_level=4):
         if block == self._currentblock + 1:
             self._skip_closeblock = True
@@ -155,18 +131,25 @@
     def neg(self, targetvar, source):
         self.append('%(targetvar)s = -%(source)s' % locals())
         
-    def call(self, targetvar, returntype, functionref, argrefs, argtypes, label=None, except_label=None):
-        #args = ", ".join(["%s %s" % item for item in zip(argtypes, argrefs)])
-        args = ", ".join(argrefs)
-        if except_label:
-            self.js.exceptionpolicy.invoke(self, targetvar, returntype, functionref, args, label, except_label)
+    def call(self, targetvar, functionref, argrefs, label=None, exception_exits=[]):
+        if exception_exits:
+            assert label is not None
+            self.append('try {')
+            indentation_level = 5
         else:
-            if returntype == 'void':
-                #self.llvm("call void %s(%s)" % (functionref, args))
-                self.append('%s(%s)' % (functionref, args))
-            else:
-                #self.llvm("%s = call %s %s(%s)" % (targetvar, returntype, functionref, args))
-                self.append('%s = %s(%s)' % (targetvar, functionref, args))
+            assert label is None
+            indentation_level = 4
+
+        args = ", ".join(argrefs)
+        self.append('%s = %s(%s)' % (targetvar, functionref, args), indentation_level)
+
+        if exception_exits:
+            self.append('block = %d' % 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
+            self.append('}')
 
     def cast(self, targetvar, fromtype, fromvar, targettype):
         if fromtype == 'void' and targettype == 'void':
@@ -182,15 +165,14 @@
         else:
             self.llvm("%(targetvar)s = cast %(fromtype)s %(fromvar)s to %(targettype)s" % locals())
 
-    def malloc(self, targetvar, type_, size=1, atomic=False):
-        for s in self.js.gcpolicy.malloc(targetvar, type_, size, atomic, 'word', 'uword').split('\n'):
-            self.append(s)
+    def malloc(self, targetvar, type_):
+        self.append('%(targetvar)s = new %(type_)s()' % locals())
 
     def getelementptr(self, targetvar, type, typevar, *indices):
         res = "%(targetvar)s = getelementptr %(type)s %(typevar)s, word 0, " % locals()
         res += ", ".join(["%s %s" % (t, i) for t, i in indices])
         self.llvm(res)
-        
+
         #res = "%(targetvar)s = %(typevar)s" % locals()
         #res += ''.join(['[%s]' % i for t, i in indices])
         #self.append(res)
@@ -205,9 +187,3 @@
         res += ''.join(['[%s]' % index for index in destindices])
         res += " = %(srcvar)s" % locals()
         self.append(res)
-
-    def debugcomment(self, tempname, len, tmpname):
-        res = "%s = call %(word)s (sbyte*, ...)* printf(" % locals()
-        res += "sbyte* getelementptr ([%s x sbyte]* %s, word 0, word 0) )" % locals()
-        res = res % (tmpname, len, tmpname)
-        self.llvm(res)

Modified: pypy/dist/pypy/translator/js/database.py
==============================================================================
--- pypy/dist/pypy/translator/js/database.py	(original)
+++ pypy/dist/pypy/translator/js/database.py	Tue Oct 18 11:04:11 2005
@@ -31,42 +31,6 @@
         self._pendingsetup = []
         self._tmpcount = 1
 
-        # debug operation comments
-        self._opcomments = {}
-
-    #_______for debugging llvm code_________________________
-
-    def add_op2comment(self, lenofopstr, op):
-        """ internal method for adding comments on each operation """
-        tmpname = self.repr_tmpvar() + ".comment"
-        self._opcomments[op] = (lenofopstr, tmpname)
-        return tmpname
-        
-    def get_op2comment(self, op):
-        """ internal method for adding comments on each operation """
-        return self._opcomments.get(op, None)
-    
-    #_______debuggging______________________________________
-
-    def dump_pbcs(self):
-        r = ""
-        for k, v in self.obj2node.iteritems():
-            
-            if isinstance(k, lltype.LowLevelType):
-                continue
-
-            assert isinstance(lltype.typeOf(k), lltype.ContainerType)
-            # Only dump top levels
-            p, _ = lltype.parentlink(k)
-            if p is None:
-                ref = v.get_ref()
-                pbc_ref = v.get_ref()
-                
-                r += "\ndump_pbcs %s (%s)\n" \
-                     "getref -> %s \n" \
-                     "pbcref -> %s \n" % (v, k, ref, pbc_ref)
-            return r
-    
     #_______setting up and preperation______________________________
 
     def create_constant_node(self, type_, value):
@@ -110,40 +74,6 @@
         self.obj2node[key] = node 
         self._pendingsetup.append(node)
         
-    #def prepare_type(self, type_):
-    #    return  #forget about the types in Javascript
-    # 
-    #    #if type_ in self.obj2node:
-    #    #    return
-    #    #if isinstance(type_, lltype.Primitive):
-    #    #    pass
-    #    #elif isinstance(type_, lltype.Ptr): 
-    #    #    self.prepare_type(type_.TO)
-    #    #
-    #    #elif isinstance(type_, lltype.Struct):
-    #    #    if type_._arrayfld:
-    #    #        self.addpending(type_, StructVarsizeTypeNode(self, type_))
-    #    #    else:
-    #    #        self.addpending(type_, StructTypeNode(self, type_))                
-    #    #elif isinstance(type_, lltype.FuncType): 
-    #    #    self.addpending(type_, FuncTypeNode(self, type_))
-    #    #
-    #    #elif isinstance(type_, lltype.Array): 
-    #    #    if type_.OF is lltype.Void:
-    #    #        self.addpending(type_, VoidArrayTypeNode(self, type_))
-    #    #    else:
-    #    #        self.addpending(type_, ArrayTypeNode(self, type_))
-    #    #
-    #    #elif isinstance(type_, lltype.OpaqueType):
-    #    #    self.addpending(type_, OpaqueTypeNode(self, type_))            
-    #    #
-    #    #else:
-    #    #    assert False, "need to prepare typerepr %s %s" % (type_, type(type_))
-    #
-    #def prepare_type_multi(self, types):
-    #    for type_ in types:
-    #        self.prepare_type(type_)
-
     def prepare_constant(self, type_, value):
         if isinstance(type_, lltype.Primitive):
             #log.prepareconstant(value, "(is primitive)")
@@ -163,9 +93,6 @@
         # we can share data via pointers
         if value not in self.obj2node: 
             self.addpending(value, self.create_constant_node(type_, value))
-
-        # always add type (it is safe)
-        #self.prepare_type(type_)
         
     def prepare_arg_value(self, const_or_var):
         """if const_or_var is not already in a dictionary self.obj2node,
@@ -227,9 +154,18 @@
             assert isinstance(arg, Variable)
             return str(arg)
 
+    def repr_type(self, arg):
+        try:
+            node = self.obj2node.get(arg.value._obj)
+            if isinstance(node, ArrayNode):
+                return 'Array'
+        except:
+            pass
+        return 'Object'
+
     def repr_concretetype(self, ct): #used by casts
         try:
-             return self.obj2node[ct].ref 
+            return self.obj2node[ct].ref 
         except KeyError: 
             if isinstance(ct, lltype.Primitive):
                 return self.primitives[ct]
@@ -249,16 +185,14 @@
             return None, repr
 
         elif isinstance(type_, lltype.Ptr):
-            toptr = '' #self.repr_type(type_)
             value = value._obj
 
             # special case, null pointer
             if value is None:
-                return None, "%s null" % (toptr,)
+                return None, "null"
 
             node = self.obj2node[value]
-            ref = node.get_pbcref(toptr)
-            return node, "%s %s" % (toptr, ref)
+            return node, node.get_ref()
 
         elif isinstance(type_, lltype.Array) or isinstance(type_, lltype.Struct):
             node = self.obj2node[value]
@@ -319,6 +253,14 @@
     # __________________________________________________________
     # Other helpers
 
+    def is_function_ptr(self, arg):
+        if isinstance(arg, (Constant, Variable)): 
+            arg = arg.concretetype 
+            if isinstance(arg, lltype.Ptr):
+                if isinstance(arg.TO, lltype.FuncType):
+                    return True
+        return False
+     
     def get_childref(self, parent, child):
         node = self.obj2node[parent]
         return node.get_childref(child)

Modified: pypy/dist/pypy/translator/js/extfuncnode.py
==============================================================================
--- pypy/dist/pypy/translator/js/extfuncnode.py	(original)
+++ pypy/dist/pypy/translator/js/extfuncnode.py	Tue Oct 18 11:04:11 2005
@@ -12,19 +12,19 @@
         name = value._callable.__name__
         assert name.startswith("ll")
         name = "LL" + name[2:] 
-        self.ref = self.make_ref("%", name)
+        self.ref = self.make_ref("", name)
         self.used_external_functions[self.ref] = True
 
-    def getdecl(self):
-        T = self.value._TYPE
-        args = [self.db.repr_type(a) for a in T.ARGS]
-        decl = "%s %s(%s)" % (self.db.repr_type(T.RESULT),
-                              self.ref,
-                              ", ".join(args))
-        return decl
-
-    def writedecl(self, codewriter): 
-        codewriter.declare(self.getdecl())
-
-    def writeglobalconstants(self, codewriter):
-        pass
+    #def getdecl(self):
+    #    T = self.value._TYPE
+    #    args = [self.db.repr_type(a) for a in T.ARGS]
+    #    decl = "%s %s(%s)" % (self.db.repr_type(T.RESULT),
+    #                          self.ref,
+    #                          ", ".join(args))
+    #    return decl
+    #
+    #def writedecl(self, codewriter): 
+    #    codewriter.declare(self.getdecl())
+    #
+    #def writeglobalconstants(self, codewriter):
+    #    pass

Modified: pypy/dist/pypy/translator/js/funcnode.py
==============================================================================
--- pypy/dist/pypy/translator/js/funcnode.py	(original)
+++ pypy/dist/pypy/translator/js/funcnode.py	Tue Oct 18 11:04:11 2005
@@ -5,9 +5,6 @@
 from pypy.rpython import lltype
 from pypy.translator.js.node import LLVMNode, ConstantLLVMNode
 from pypy.translator.js.opwriter import OpWriter
-#from pypy.translator.js.backendopt.removeexcmallocs import remove_exception_mallocs
-#from pypy.translator.js.backendopt.mergemallocs import merge_mallocs
-from pypy.translator.unsimplify import remove_double_links
 from pypy.translator.js.log import log 
 log = log.funcnode
 
@@ -22,12 +19,6 @@
         self.ref   = self.make_ref(pypy_prefix, value.graph.name)
         self.graph = value.graph
 
-        self.db.genllvm.exceptionpolicy.transform(self.db.translator, self.graph)
-        #remove_exception_mallocs(self.db.translator, self.graph, self.ref)
-        #merge_mallocs(self.db.translator, self.graph, self.ref)
-
-        #remove_double_links(self.db.translator, self.graph)
-
     def __str__(self):
         return "<FuncNode %r>" %(self.ref,)
     
@@ -72,33 +63,6 @@
             codewriter.closeblock()
         codewriter.closefunc()
 
-    def writecomments(self, codewriter):
-        """ write operations strings for debugging purposes. """ 
-        blocks = [x for x in flatten(self.graph) if isinstance(x, Block)]
-        for block in blocks:
-            for op in block.operations:
-                strop = str(op) + "\n\x00"
-                l = len(strop)
-                if strop.find("direct_call") == -1:
-                    continue
-                tempname = self.db.add_op2comment(l, op)
-                printables = dict([(ord(i), None) for i in
-                                   ("0123456789abcdefghijklmnopqrstuvwxyz" +
-                                    "ABCDEFGHIJKLMNOPQRSTUVWXYZ" +
-                                    "!#$%&()*+,-./:;<=>?@[\\]^_`{|}~ '")])
-                s = []
-                for c in strop:
-                    if ord(c) in printables:
-                        s.append(c)
-                    else:
-                        s.append("\\%02x" % ord(c))
-                r = 'c"%s"' % "".join(s)
-                typeandata = '[%s x sbyte] %s' % (l, r)
-                codewriter.globalinstance(tempname, typeandata)
-
-    def writeglobalconstants(self, codewriter):
-        pass
-    
     # ______________________________________________________________________
     # writing helpers for entry points
 
@@ -134,15 +98,6 @@
         else:
             last_op_index = None
         for op_index, op in enumerate(block.operations):
-            if False:   # print out debug string
-                codewriter.newline()
-                codewriter.comment("** %s **" % str(op))
-                info = self.db.get_op2comment(op)
-                if info is not None:
-                    lenofopstr, opstrname = info
-                    codewriter.debugcomment(self.db.repr_tmpvar(),
-                                            lenofopstr,
-                                            opstrname)
             if op_index == last_op_index:
                 #could raise an exception and should therefor have a function
                 #implementation that can be invoked by the llvm-code.
@@ -164,4 +119,7 @@
         codewriter.ret( self.db.repr_arg(block.inputargs[0]) )
 
     def write_exceptblock(self, codewriter, block):
-        self.db.genllvm.exceptionpolicy.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"')
+        codewriter.skip_closeblock()

Modified: pypy/dist/pypy/translator/js/js.py
==============================================================================
--- pypy/dist/pypy/translator/js/js.py	(original)
+++ pypy/dist/pypy/translator/js/js.py	Tue Oct 18 11:04:11 2005
@@ -20,17 +20,13 @@
 from pypy.translator.js.node import LLVMNode
 from pypy.translator.js.database import Database 
 from pypy.translator.js.codewriter import CodeWriter
-from pypy.translator.js.gc import GcPolicy
-from pypy.translator.js.exception import ExceptionPolicy
 from pypy.translator.js.log import log
 
 
 class JS(object):   # JS = Javascript
-    def __init__(self, translator, function=None, gcpolicy=None, exceptionpolicy=None, debug=False):
+    def __init__(self, translator, function=None, debug=False):
         self.db = Database(self, translator)
         self.translator = translator
-        self.gcpolicy = GcPolicy.new(gcpolicy)
-        self.exceptionpolicy = ExceptionPolicy.new(exceptionpolicy)
         LLVMNode.reset_nodename_count()
         #extfuncnode.ExternalFuncNode.used_external_functions = {}
         self.debug = debug # for debug we create comments of every operation that may be executed

Modified: pypy/dist/pypy/translator/js/node.py
==============================================================================
--- pypy/dist/pypy/translator/js/node.py	(original)
+++ pypy/dist/pypy/translator/js/node.py	Tue Oct 18 11:04:11 2005
@@ -44,13 +44,11 @@
     def writedecl(self, codewriter):
         """ write function forward declarations. """ 
 
-    def writecomments(self, codewriter):
-        """ write operations strings for debugging purposes. """ 
-
     # __________________ after "implementation" ____________________
     def writeimpl(self, codewriter):
         """ write function implementations. """ 
 
+
 class ConstantLLVMNode(LLVMNode):
     __slots__ = "".split()
 
@@ -58,13 +56,9 @@
         """ Returns a reference as used for operations in blocks. """        
         return self.ref
 
-    def get_pbcref(self, toptr):
-        """ Returns a reference as a pointer used per pbc. """        
-        return self.ref
-
     def constantvalue(self):
         """ Returns the constant representation for this node. """
-        raise AttributeError("Must be implemented in subclass")
+        return []
 
     # ______________________________________________________________________
     # entry points from genllvm
@@ -72,4 +66,4 @@
     def writeglobalconstants(self, codewriter):
         p, c = lltype.parentlink(self.value)
         if p is None:
-            codewriter.globalinstance(self.ref, self.constantvalue())
+            codewriter.globalinstance( self.constantvalue() )

Modified: pypy/dist/pypy/translator/js/opwriter.py
==============================================================================
--- pypy/dist/pypy/translator/js/opwriter.py	(original)
+++ pypy/dist/pypy/translator/js/opwriter.py	Tue Oct 18 11:04:11 2005
@@ -132,10 +132,8 @@
     def int_abs(self, op):
         #ExternalFuncNode.used_external_functions[functionref] = True
         self.codewriter.call(self.db.repr_arg(op.result),
-                             self.db.repr_arg_type(op.result),
                              'Math.abs',
-                             [self.db.repr_arg(op.args[0])],
-                             [self.db.repr_arg_type(op.args[0])])
+                             [self.db.repr_arg(op.args[0])])
     float_abs = int_abs
 
     def int_pow(self, op):
@@ -240,11 +238,9 @@
                    if arg.concretetype is not lltype.Void]
         assert len(op_args) >= 1
         targetvar = self.db.repr_arg(op.result)
-        returntype = '' #self.db.repr_arg_type(op.result)
         functionref = self.db.repr_arg(op_args[0])
         argrefs = self.db.repr_arg_multi(op_args[1:])
-        argtypes = [] #self.db.repr_arg_type_multi(op_args[1:])
-        self.codewriter.call(targetvar,returntype,functionref,argrefs,argtypes)
+        self.codewriter.call(targetvar, functionref, argrefs)
 
     def invoke(self, op):
         op_args = [arg for arg in op.args
@@ -254,7 +250,7 @@
             functionref = self.db.repr_arg(op_args[0])
         else:   #operation
             opname = op.opname.split(':',1)[1]
-            op_args = ['%' + opname] + op_args
+            op_args = [opname] + op_args
             functionref = op_args[0]
             if functionref in extfunctions:
                 ExternalFuncNode.used_external_functions[functionref] = True
@@ -263,7 +259,7 @@
                 self.codewriter.comment('XXX: Error: ' + msg)
                 # XXX commented out for testing
                 #assert functionref in extfunctions, msg
-        
+
         assert len(op_args) >= 1
         # at least one label and one exception label
         assert len(self.block.exits) >= 2   
@@ -272,18 +268,16 @@
         assert link.exitcase is None
 
         targetvar   = self.db.repr_arg(op.result)
-        returntype  = self.db.repr_arg_type(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:])
+        #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   = 10000 + block_label   #_exception_label
+        #exc_label   = block_label   #_exception_label
 
-        #if self.db.is_function_ptr(op.result):  #use longhand form
-        #    returntype = "%s (%s)*" % (returntype, ", ".join(argtypes))
-        self.codewriter.call(targetvar, returntype, functionref, argrefs,
-                             argtypes, none_label, exc_label)
+        self.codewriter.call(targetvar, functionref, argrefs, none_label, self.block.exits[1:])
+        return
 
         e = self.db.translator.rtyper.getexceptiondata()
         pypy_prefix              = '' #pypy_
@@ -295,7 +289,7 @@
                                     e.lltype_of_exception_value.TO.__name__
                                     + '*')
 
-        self.codewriter.label(exc_label)
+        self.codewriter.openblock(exc_label)
 
         exc_found_labels, last_exception_type = [], None
         catch_all = False
@@ -306,27 +300,29 @@
             current_exception_type = etype.get_ref()
             target          = self.node.blockindex[link.target]
             #exc_found_label = block_label + '_exception_found_branchto_' + target
-            exc_found_label = '%d_exception_found_branchto_%d' % (block_label, target)
+            exc_found_label = target #'%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):
-                arg, type_, names, blocknames = p
-                for name, blockname in zip(names, blocknames):
-                    if blockname != exc_found_label:
-                        continue
-                    if name.startswith('last_exception_'):
-                        last_exc_type_var = name
-                    if name.startswith('last_exc_value_'):
-                        last_exc_value_var = name
+            #XXX refactor this
+            #for p in self.node.get_phi_data(link.target):
+            #    arg, type_, names, blocknames = p
+            #    for name, blockname in zip(names, blocknames):
+            #        if blockname != exc_found_label:
+            #            continue
+            #        if name.startswith('last_exception_'):
+            #            last_exc_type_var = name
+            #        if name.startswith('last_exc_value_'):
+            #            last_exc_value_var = name
 
             t = (exc_found_label,target,last_exc_type_var,last_exc_value_var)
             exc_found_labels.append(t)
 
-            not_this_exception_label = block_label + '_not_exception_' + etype.ref[1:]
+            not_this_exception_label = str(block_label) + '_not_exception_' + etype.ref[1:]
 
             if current_exception_type.find('getelementptr') == -1:  #catch all (except:)
                 catch_all = True
-                self.codewriter.br_uncond(exc_found_label)
+                self.codewriter.comment('br_uncond %s' % exc_found_label)
+                #self.codewriter.br_uncond(exc_found_label)
             else:   #catch specific exception (class) type
                 if not last_exception_type: #load pointer only once
                     last_exception_type = self.db.repr_tmpvar()
@@ -334,23 +330,22 @@
                     self.codewriter.newline()
                 ll_issubclass_cond = self.db.repr_tmpvar()
                 self.codewriter.call(ll_issubclass_cond,
-                                     'bool',
                                      ll_exception_match,
                                      [last_exception_type, current_exception_type],
                                      [lltype_of_exception_type, lltype_of_exception_type])
                 self.codewriter.br(ll_issubclass_cond, not_this_exception_label, exc_found_label)
-                self.codewriter.label(not_this_exception_label)
+                self.codewriter.openblock(not_this_exception_label)
 
-        ep = self.codewriter.genllvm.exceptionpolicy
+        ep = self.codewriter.js.exceptionpolicy
         if not catch_all:
             ep.reraise(self.node, self.codewriter)
-        ep.fetch_exceptions(self.codewriter, exc_found_labels, lltype_of_exception_type, lltype_of_exception_value)
+        ep.fetch_exceptions(self.codewriter,self.block,exc_found_labels,lltype_of_exception_type,lltype_of_exception_value)
 
     def malloc(self, op): 
         arg_type = op.args[0].value
         targetvar = self.db.repr_arg(op.result) 
-        type_ = '' #self.db.repr_type(arg_type)
-        self.codewriter.malloc(targetvar, type_, atomic=arg_type._is_atomic())
+        type_ = self.db.repr_type(arg_type)
+        self.codewriter.malloc(targetvar, type_)
     malloc_exception = malloc
     malloc_varsize = malloc
 

Modified: pypy/dist/pypy/translator/js/structnode.py
==============================================================================
--- pypy/dist/pypy/translator/js/structnode.py	(original)
+++ pypy/dist/pypy/translator/js/structnode.py	Tue Oct 18 11:04:11 2005
@@ -90,7 +90,13 @@
             name = _rename_reserved_keyword(name)
             var  = (name, str(value))
             vars.append(var)
-        return "({%s})" % ", ".join(["%s:%s" % var for var in vars])
+        lines = []
+        for var in vars:
+            name, value = var
+            #s = "({%s})" % ", ".join(["%s:%s" % var for var in vars])
+            line = "%s.%s = %s" % (self.ref, name, value)
+            lines.append(line)
+        return lines
 
         #values = self._getvalues()
         #all_values = ",\n  ".join(values)



More information about the Pypy-commit mailing list