Changeset 3916

Show
Ignore:
Timestamp:
07/02/09 14:57:49 (5 months ago)
Author:
chf
Message:

cleanups

Location:
trunk/ProjectFortress/src/com/sun/fortress/compiler/codegen
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/ProjectFortress/src/com/sun/fortress/compiler/codegen/CodeGen.java

    r3914 r3916  
    840840    //          We create separate taskClasses for every task       
    841841    public String delegate(ASTNode x) { 
     842 
     843        if (! (x instanceof _RewriteFnApp)) { 
     844            sayWhat(x); 
     845        } 
     846 
     847        _RewriteFnApp _rewriteFnApp = (_RewriteFnApp) x; 
     848 
     849        Expr function = _rewriteFnApp.getFunction(); 
     850         
     851        System.out.println("BBBBBBB: function = " + function); 
     852        ExprInfo info = function.getInfo(); 
     853        Option<Type> exprType = info.getExprType(); 
     854 
     855 
     856        if (!exprType.isSome()) { 
     857            sayWhat(x, "Missing type information for delegate " + x); 
     858        } 
     859         
     860        String desc = NamingCzar.jvmTypeDesc(exprType.unwrap(), component.getName()); 
     861         
     862        List<String> args = CodeGenMethodVisitor.parseArgs(desc); 
     863        String result = CodeGenMethodVisitor.parseResult(desc); 
     864 
    842865        String className = NamingCzar.gensymTaskName(packageAndClassName); 
    843866        debug("delegate creating class " + className + " node = " + x); 
     
    846869        cg.localsDepth = 0; 
    847870        cg.cw = new CodeGenClassWriter(ClassWriter.COMPUTE_FRAMES); 
    848          
    849871        cg.cw.visitSource(className,null); 
    850872 
     
    854876                    className,null, NamingCzar.fortressBaseTask, null); 
    855877 
    856         // FIXME, this assumes we only take a ZZ32 argument. 
    857         cg.mv = cg.cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>",  
    858                                   "(" + NamingCzar.descFortressZZ32 + ")V", null, null); 
     878        String initDesc = "("; 
     879 
     880        for (String arg : args) { 
     881            initDesc = initDesc + arg; 
     882        } 
     883        initDesc = initDesc + ")V"; 
     884 
     885        System.out.println("initDesc = " + initDesc + "should be (ZZ32)V"); 
     886             
     887        cg.mv = cg.cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", initDesc, null, null); 
    859888        cg.mv.visitCode(); 
     889 
    860890        cg.mv.visitVarInsn(Opcodes.ALOAD, cg.mv.getLocalVariable("instance")); 
    861891        cg.mv.visitMethodInsn(Opcodes.INVOKESPECIAL, NamingCzar.fortressBaseTask,  
    862892                              "<init>", NamingCzar.voidToVoid); 
    863893        cg.mv.visitVarInsn(Opcodes.ALOAD, cg.mv.getLocalVariable("instance")); 
     894 
     895        // Fib specific 
    864896        cg.mv.visitVarInsn(Opcodes.ALOAD, 1); 
    865         cg.mv.visitFieldInsn(Opcodes.PUTFIELD, className, "n", NamingCzar.descFortressZZ32); 
     897        cg.mv.visitFieldInsn(Opcodes.PUTFIELD, className, "n", args.get(0));             
    866898 
    867899        cg.mv.visitInsn(Opcodes.RETURN); 
     
    881913 
    882914        // Fixme, not all results are ZZ32 
    883         cg.mv.visitFieldInsn(Opcodes.PUTFIELD, className, "result", NamingCzar.descFortressZZ32); 
     915        cg.mv.visitFieldInsn(Opcodes.PUTFIELD, className, "result", result); 
    884916 
    885917        cg.mv.visitInsn(Opcodes.RETURN);         
  • trunk/ProjectFortress/src/com/sun/fortress/compiler/codegen/CodeGenMethodVisitor.java

    r3914 r3916  
    4343    int localVariableCount; 
    4444 
    45     static void error(String s) {throw new RuntimeException("Bad Signature " + s);}     
     45    static void error(String s) {throw new RuntimeException("Bad Signature " + s);}    
    4646 
    47     private void parseDescriptor(String desc) { 
    48         argumentTypes = new ArrayList<String>(); 
     47    // Move these to their own class 
    4948 
    50         System.out.println("parseDescriptor: " + desc); 
    51          
     49    public static List<String> parseArgs(String desc) { 
     50        List<String> args = new ArrayList<String>(); 
    5251        if (desc.charAt(0) != '(') error(desc); 
    5352        int i = 1; 
     
    5756 
    5857        while (ch != ')') { 
    59             System.out.println("parseDescriptor: desc = " + desc +  
    60                                " i = " + i + " argumentTypes = " + argumentTypes); 
    61  
    6258            switch(ch) { 
    6359            case 'B':  
     
    6965            case 'J':  
    7066            case 'Z':  
    71                 argumentTypes.add(Character.toString(desc.charAt(i))); ch = desc.charAt(++i); break; 
     67                args.add(Character.toString(desc.charAt(i))); ch = desc.charAt(++i); break; 
    7268            case '[':  
    7369            case 'L':  
     
    7672                    ch = desc.charAt(++i); 
    7773                } 
    78                 argumentTypes.add(desc.substring(start, ++i)); 
     74                args.add(desc.substring(start, ++i)); 
    7975                ch = desc.charAt(i); 
    8076                break; 
     
    8278            } 
    8379        } 
    84         ch = desc.charAt(++i); 
     80        return args; 
     81    } 
    8582 
     83    public static String parseResult(String desc) { 
     84        int i = desc.indexOf(')') + 1; 
     85        int ch = desc.charAt(i); 
     86        int start; 
    8687        switch(ch) { 
    8788        case 'B':  
     
    9495        case 'Z':  
    9596        case 'V': 
    96             resultType = Character.toString(desc.charAt(i)); break; 
     97            return Character.toString(desc.charAt(i));  
    9798        case '[':  
    9899            start = i; 
     
    100101                ch = desc.charAt(++i); 
    101102            } 
    102             resultType = new String(desc.substring(start, ++i)); 
    103             break; 
     103            return new String(desc.substring(start, ++i)); 
    104104        case 'L':  
    105105            start = i; 
     
    107107                ch = desc.charAt(++i); 
    108108            } 
    109             resultType = new String(desc.substring(start, ++i)); 
    110             break; 
     109            return new String(desc.substring(start, ++i)); 
    111110        default: error(desc); 
    112111        } 
    113         System.out.println("parseDescriptor: desc = " + desc +  
    114                            " i = " + i + " argumentTypes = " + argumentTypes +  
    115                            " resultType = " + resultType); 
     112        return ("Shouln't happen"); 
    116113    } 
     114 
    117115 
    118116    public CodeGenMethodVisitor(int access, String name, String desc,  
     
    125123        this.signature = signature; 
    126124        this.exceptions = exceptions; 
     125        this.argumentTypes = parseArgs(desc); 
     126        this.resultType = parseResult(desc); 
    127127         
    128128        this.localVariableTable = new HashMap<String, Integer>(); 
     
    133133            createLocalVariable("instance", name);             
    134134        } 
    135  
    136         parseDescriptor(desc); 
    137135 
    138136        System.out.println("MethodVisitor: name = " + name + " desc = " + desc +