Changeset 3852

Show
Ignore:
Timestamp:
06/15/09 13:01:43 (8 months ago)
Author:
chf
Message:

alphabetize codegen, ParallelismAnallyzer? isn't working yet.

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

Legend:

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

    r3850 r3852  
    7676    Component component; 
    7777    private final ComponentIndex ci; 
    78  
    79  
    80  
    81     private void generateMainMethod() { 
    82  
    83         // We generate two methods.  First a springboard method that creates an 
    84         // instance of the class we are generating, and then the real main method 
    85         // which takes the instance and uses it to pass to the primordial task. 
    86  
    87         mv = cw.visitMethod(Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC, "main", 
    88                             NamingCzar.stringArrayToVoid, null, null); 
    89         mv.visitCode(); 
    90         mv.visitVarInsn(Opcodes.ALOAD, 0); 
    91         mv.visitMethodInsn(Opcodes.INVOKESTATIC, "com/sun/fortress/nativeHelpers/systemHelper", 
    92                            "registerArgs", NamingCzar.stringArrayToVoid); 
    93  
    94         mv.visitTypeInsn(Opcodes.NEW, packageAndClassName); 
    95         mv.visitInsn(Opcodes.DUP); 
    96         mv.visitMethodInsn(Opcodes.INVOKESPECIAL, packageAndClassName, "<init>", "()V"); 
    97  
    98         mv.visitMethodInsn(Opcodes.INVOKESTATIC, packageAndClassName, "main", 
    99                            "(Lcom/sun/fortress/runtimeSystem/FortressComponent;)V"); 
    100  
    101         mv.visitInsn(Opcodes.RETURN); 
    102         mv.visitMaxs(NamingCzar.ignore,NamingCzar.ignore); 
    103         mv.visitEnd(); 
    104  
    105         mv = cw.visitMethod(Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC, "main", 
    106                             "(Lcom/sun/fortress/runtimeSystem/FortressComponent;)V", 
    107                             null, null); 
    108         mv.visitVarInsn(Opcodes.ALOAD, 0); 
    109         mv.visitMethodInsn(Opcodes.INVOKESTATIC, NamingCzar.primordialTask, "startFortress", 
    110                            "(Lcom/sun/fortress/runtimeSystem/FortressComponent;)Lcom/sun/fortress/runtimeSystem/PrimordialTask;"); 
    111  
    112         mv.visitInsn(Opcodes.RETURN); 
    113         mv.visitMaxs(NamingCzar.ignore,NamingCzar.ignore); 
    114         mv.visitEnd(); 
    115     } 
    116  
    117     private void generateInitMethod() { 
    118         mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", NamingCzar.voidToVoid, null, null); 
    119         mv.visitCode(); 
    120         mv.visitVarInsn(Opcodes.ALOAD, 0); 
    121         mv.visitMethodInsn(Opcodes.INVOKESPECIAL, NamingCzar.internalObject, "<init>", NamingCzar.voidToVoid); 
    122         mv.visitInsn(Opcodes.RETURN); 
    123         mv.visitMaxs(NamingCzar.ignore, NamingCzar.ignore); 
    124         mv.visitEnd(); 
    125     } 
    12678 
    12779    public CodeGen(Component c, Symbols s, TypeAnalyzer ta, ComponentIndex ci) { 
     
    164116    } 
    165117 
     118    private void generateMainMethod() { 
     119 
     120        // We generate two methods.  First a springboard method that creates an 
     121        // instance of the class we are generating, and then the real main method 
     122        // which takes the instance and uses it to pass to the primordial task. 
     123 
     124        mv = cw.visitMethod(Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC, "main", 
     125                            NamingCzar.stringArrayToVoid, null, null); 
     126        mv.visitCode(); 
     127        mv.visitVarInsn(Opcodes.ALOAD, 0); 
     128        mv.visitMethodInsn(Opcodes.INVOKESTATIC, "com/sun/fortress/nativeHelpers/systemHelper", 
     129                           "registerArgs", NamingCzar.stringArrayToVoid); 
     130 
     131        mv.visitTypeInsn(Opcodes.NEW, packageAndClassName); 
     132        mv.visitInsn(Opcodes.DUP); 
     133        mv.visitMethodInsn(Opcodes.INVOKESPECIAL, packageAndClassName, "<init>", "()V"); 
     134 
     135        mv.visitMethodInsn(Opcodes.INVOKESTATIC, packageAndClassName, "main", 
     136                           "(Lcom/sun/fortress/runtimeSystem/FortressComponent;)V"); 
     137 
     138        mv.visitInsn(Opcodes.RETURN); 
     139        mv.visitMaxs(NamingCzar.ignore,NamingCzar.ignore); 
     140        mv.visitEnd(); 
     141 
     142        mv = cw.visitMethod(Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC, "main", 
     143                            "(Lcom/sun/fortress/runtimeSystem/FortressComponent;)V", 
     144                            null, null); 
     145        mv.visitVarInsn(Opcodes.ALOAD, 0); 
     146        mv.visitMethodInsn(Opcodes.INVOKESTATIC, NamingCzar.primordialTask, "startFortress", 
     147                           "(Lcom/sun/fortress/runtimeSystem/FortressComponent;)Lcom/sun/fortress/runtimeSystem/PrimordialTask;"); 
     148 
     149        mv.visitInsn(Opcodes.RETURN); 
     150        mv.visitMaxs(NamingCzar.ignore,NamingCzar.ignore); 
     151        mv.visitEnd(); 
     152    } 
     153 
     154    private void generateInitMethod() { 
     155        mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", NamingCzar.voidToVoid, null, null); 
     156        mv.visitCode(); 
     157        mv.visitVarInsn(Opcodes.ALOAD, 0); 
     158        mv.visitMethodInsn(Opcodes.INVOKESPECIAL, NamingCzar.internalObject, "<init>", NamingCzar.voidToVoid); 
     159        mv.visitInsn(Opcodes.RETURN); 
     160        mv.visitMaxs(NamingCzar.ignore, NamingCzar.ignore); 
     161        mv.visitEnd(); 
     162    } 
     163 
     164 
    166165    private void cgWithNestedScope(ASTNode n) { 
    167166        CodeGen cg = new CodeGen(this); 
     
    200199    } 
    201200 
     201    private void popAll(int onStack) { 
     202        if (onStack > 0) { 
     203            for (; onStack > 1; onStack -= 2) { 
     204                mv.visitInsn(Opcodes.POP2); 
     205            } 
     206            if (onStack==1) { 
     207                mv.visitInsn(Opcodes.POP); 
     208            } 
     209        } 
     210    } 
     211 
     212    private void dumpDecls(List<Decl> decls) { 
     213        debug("dumpDecls", decls); 
     214        for (Decl d : decls) { 
     215            if (!(d instanceof FnDecl)) { 
     216                sayWhat(d); 
     217                return; 
     218            } 
     219            d.accept(this); 
     220        } 
     221    } 
     222 
     223 
     224    private void addLineNumberInfo(ASTNode x) { 
     225        addLineNumberInfo(mv, x); 
     226    } 
     227 
     228    private void addLineNumberInfo(MethodVisitor m, ASTNode x) { 
     229        org.objectweb.asm.Label bogus_label = new org.objectweb.asm.Label(); 
     230        m.visitLabel(bogus_label); 
     231        Span span = NodeUtil.getSpan(x); 
     232        SourceLoc begin = span.getBegin(); 
     233        SourceLoc end = span.getEnd(); 
     234        String fileName = span.getFileName(); 
     235        m.visitLineNumber(begin.getLine(), bogus_label); 
     236    } 
     237 
     238    public static String jvmSignatureFor(Function f) { 
     239        String sig; 
     240        List<Param> params = f.parameters(); 
     241        sig = "("; 
     242        for (Param p : params ) {                 
     243            Type ty = p.getIdType().unwrap(); 
     244            String toType = NamingCzar.only.boxedImplDesc(ty); 
     245            sig += toType; 
     246        } 
     247        sig += ")"; 
     248        sig += NamingCzar.only.boxedImplDesc(f.getReturnType()); 
     249        return sig; 
     250    } 
     251     
     252 
     253    /** 
     254     * @param x 
     255     * @param arrow 
     256     * @param pkgAndClassName 
     257     * @param methodName 
     258     */ 
     259    private void callStaticSingleOrOverloaded(FnRef x, 
     260            com.sun.fortress.nodes.Type arrow, String pkgAndClassName, 
     261            String methodName) { 
     262        { 
     263            debug("class = " + pkgAndClassName + " method = " + methodName ); 
     264 
     265            if ( arrow instanceof ArrowType ) { 
     266                addLineNumberInfo(x); 
     267                mv.visitMethodInsn(Opcodes.INVOKESTATIC, pkgAndClassName, 
     268                                   methodName, Naming.emitDesc(arrow)); 
     269            } else if (arrow instanceof IntersectionType) { 
     270                addLineNumberInfo(x); 
     271                IntersectionType it = (IntersectionType) arrow; 
     272                mv.visitMethodInsn(Opcodes.INVOKESTATIC, pkgAndClassName, 
     273                                   OverloadSet.actuallyOverloaded(it, paramCount) ? 
     274                                   OverloadSet.oMangle(methodName) :methodName, 
     275                                   OverloadSet.getSignature(it, paramCount, ta)); 
     276            } else { 
     277                    sayWhat( x, "Neither arrow nor intersection type: " + arrow ); 
     278            } 
     279        } 
     280 
     281    } 
     282 
     283    // paramCount communicates this information from call to function reference, 
     284    // as it's needed to determine type descriptors for methods. 
     285    private int paramCount = -1; 
     286 
     287    /** 
     288     * @param y 
     289     */ 
     290    private void pushInteger(int y) { 
     291        switch (y) { 
     292        case 0: 
     293            mv.visitInsn(Opcodes.ICONST_0); 
     294            break; 
     295        case 1: 
     296            mv.visitInsn(Opcodes.ICONST_1); 
     297            break; 
     298        case 2: 
     299            mv.visitInsn(Opcodes.ICONST_2); 
     300            break; 
     301        case 3: 
     302            mv.visitInsn(Opcodes.ICONST_3); 
     303            break; 
     304        case 4: 
     305            mv.visitInsn(Opcodes.ICONST_4); 
     306            break; 
     307        case 5: 
     308            mv.visitInsn(Opcodes.ICONST_5); 
     309            break; 
     310        default: 
     311            mv.visitLdcInsn(y); 
     312            break; 
     313        } 
     314 
     315    } 
    202316    private <T> T sayWhat(ASTNode x) { 
    203317        throw new CompilerError(NodeUtil.getSpan(x), "Can't compile " + x); 
     
    217331    } 
    218332 
    219     public void forComponent(Component x) { 
    220         debug("forComponent ",x.getName(),NodeUtil.getSpan(x)); 
    221         cw = new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES ); 
    222         cw.visitSource(packageAndClassName, null); 
    223         boolean exportsExecutable = false; 
    224         boolean exportsDefaultLibrary = false; 
    225  
    226         for ( APIName export : x.getExports() ) { 
    227             if ( WellKnownNames.exportsMain(export.getText()) ) 
    228                 exportsExecutable = true; 
    229             if ( WellKnownNames.exportsDefaultLibrary(export.getText()) ) 
    230                 exportsDefaultLibrary = true; 
    231         } 
    232  
    233         cw.visit(Opcodes.V1_5, Opcodes.ACC_PUBLIC + Opcodes.ACC_SUPER, 
    234                  packageAndClassName, null, NamingCzar.fortressComponent, 
    235                  null); 
    236  
    237         // Always generate the init method 
    238         generateInitMethod(); 
    239  
    240         // If this component exports an executable API, 
    241         // generate a main method. 
    242         if ( exportsExecutable ) { 
    243             generateMainMethod(); 
    244         } 
    245         for ( Import i : x.getImports() ) { 
    246             i.accept(this); 
    247         } 
    248  
    249         // determineOverloadedNames(x.getDecls() ); 
    250          
    251         // Must do this first, to get local decls right. 
    252         generateTopLevelOverloads(); 
    253          
    254         for ( Decl d : x.getDecls() ) { 
    255             d.accept(this); 
    256         } 
    257          
    258          
    259  
    260         dumpClass( packageAndClassName ); 
    261     } 
    262     
    263     /** 
    264      * Creates overloaded functions for any overloads present at the top level 
    265      * of this component.  Top level overloads are those that might be exported; 
    266      * Reference overloads are rewritten into _RewriteFnOverloadDecl nodes 
    267      * and generated in the normal visits. 
    268      */ 
    269     private void generateTopLevelOverloads() { 
    270                  
    271         for (Map.Entry<IdOrOpOrAnonymousName, MultiMap<Integer, Function>> entry1 : topLevelOverloads.entrySet()) { 
    272             IdOrOpOrAnonymousName  name = entry1.getKey(); 
    273             MultiMap<Integer, Function> partitionedByArgCount = entry1.getValue(); 
    274              
    275             for (Map.Entry<Integer, Set<Function>> entry : partitionedByArgCount 
    276                     .entrySet()) { 
    277                int i = entry.getKey(); 
    278                Set<Function> fs = entry.getValue(); 
    279  
    280                OverloadSet os = 
    281                    new OverloadSet.Local(ci.ast().getName(), name, 
    282                                          ta, fs, i); 
    283  
    284                os.split(true); 
    285                 
    286                String s = name.stringName(); 
    287                 
    288                os.generateAnOverloadDefinition(s, cw); 
    289                 
    290                for (Map.Entry<String, OverloadSet> o_entry : os.getOverloadSubsets().entrySet()) { 
    291                    String ss = o_entry.getKey(); 
    292                    ss = s + ss; 
    293                    overloadedNamesAndSigs.add(ss); 
    294                } 
    295            } 
    296         } 
    297     } 
    298  
    299     Map<IdOrOpOrAnonymousName, MultiMap<Integer, Function>> 
    300        sizePartitionedOverloads(Relation<IdOrOpOrAnonymousName, Function> fns) { 
    301          
    302         Map<IdOrOpOrAnonymousName, MultiMap<Integer, Function>> result =  
    303             new HashMap<IdOrOpOrAnonymousName, MultiMap<Integer, Function>>(); 
    304          
    305         for (IdOrOpOrAnonymousName name : fns.firstSet()) { 
    306             Set<Function> defs = fns.matchFirst(name); 
    307             if (defs.size() <= 1) continue; 
    308  
    309             MultiMap<Integer, Function> partitionedByArgCount = 
    310                 new MultiMap<Integer, Function>(); 
    311  
    312             for (Function d : defs) { 
    313                 partitionedByArgCount.putItem(d.parameters().size(), d); 
    314             } 
    315              
    316             for (Function d : defs) { 
    317                 Set<Function> sf = partitionedByArgCount.get(d.parameters().size()); 
    318                 if (sf != null && sf.size() <= 1) 
    319                     partitionedByArgCount.remove(d.parameters().size()); 
    320             } 
    321             if (partitionedByArgCount.size() > 0) 
    322                 result.put(name, partitionedByArgCount); 
    323         } 
    324          
    325         return result; 
    326     } 
    327  
    328     public void forImportNames(ImportNames x) { 
    329         debug("forImportNames", x); 
    330         Option<String> foreign = x.getForeignLanguage(); 
    331         if ( !foreign.isSome() ) return; 
    332         if ( !foreign.unwrap().equals("java") ) { 
    333             sayWhat(x, "Unrecognized foreign import type (only recognize java): "+ 
    334                        foreign.unwrap()); 
    335             return; 
    336         } 
    337         String apiName = x.getApiName().getText(); 
    338         for ( AliasedSimpleName n : x.getAliasedNames() ) { 
    339             Option<IdOrOpOrAnonymousName> aliasId = n.getAlias(); 
    340             if (!(aliasId.isSome())) continue; 
    341             debug("forImportNames ", x, 
    342                   " aliasing ", NodeUtil.nameString(aliasId.unwrap()), 
    343                   " to ", NodeUtil.nameString(n.getName())); 
    344             aliasTable.put(NodeUtil.nameString(aliasId.unwrap()), 
    345                            apiName + "." + NodeUtil.nameString(n.getName())); 
    346         } 
    347     } 
    348  
     333    public void forBlock(Block x) { 
     334        boolean oldInABlock = inABlock; 
     335        inABlock = true; 
     336        int onStack = 0; 
     337        debug("forBlock ", x); 
     338        for ( Expr e : x.getExprs() ) { 
     339            popAll(onStack); 
     340            e.accept(this); 
     341            onStack = 1; 
     342            // TODO: can we have multiple values on stack in future? 
     343            // Whither primitive types? 
     344            // May require some tracking of abstract stack state. 
     345            // For now we always have 1 pointer on stack and this doesn't 
     346            // matter. 
     347        } 
     348        inABlock=oldInABlock; 
     349    } 
    349350    public void forChainExpr(ChainExpr x) { 
    350351        debug( "forChainExpr" + x); 
     
    367368    } 
    368369 
     370    public void forComponent(Component x) { 
     371        debug("forComponent ",x.getName(),NodeUtil.getSpan(x)); 
     372        cw = new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES ); 
     373        cw.visitSource(packageAndClassName, null); 
     374        boolean exportsExecutable = false; 
     375        boolean exportsDefaultLibrary = false; 
     376 
     377        for ( APIName export : x.getExports() ) { 
     378            if ( WellKnownNames.exportsMain(export.getText()) ) 
     379                exportsExecutable = true; 
     380            if ( WellKnownNames.exportsDefaultLibrary(export.getText()) ) 
     381                exportsDefaultLibrary = true; 
     382        } 
     383 
     384        cw.visit(Opcodes.V1_5, Opcodes.ACC_PUBLIC + Opcodes.ACC_SUPER, 
     385                 packageAndClassName, null, NamingCzar.fortressComponent, 
     386                 null); 
     387 
     388        // Always generate the init method 
     389        generateInitMethod(); 
     390 
     391        // If this component exports an executable API, 
     392        // generate a main method. 
     393        if ( exportsExecutable ) { 
     394            generateMainMethod(); 
     395        } 
     396        for ( Import i : x.getImports() ) { 
     397            i.accept(this); 
     398        } 
     399 
     400        // determineOverloadedNames(x.getDecls() ); 
     401         
     402        // Must do this first, to get local decls right. 
     403        generateTopLevelOverloads(); 
     404         
     405        for ( Decl d : x.getDecls() ) { 
     406            d.accept(this); 
     407        } 
     408         
     409         
     410 
     411        dumpClass( packageAndClassName ); 
     412    } 
     413 
    369414    public void forDecl(Decl x) { 
    370415        sayWhat(x, "forDecl"); 
    371416    } 
    372417 
    373     private void dumpSigs(List<Decl> decls) { 
    374         debug("dumpSigs", decls); 
    375         for (Decl d : decls) { 
    376             debug("dumpSigs decl =", d); 
    377             if (!(d instanceof FnDecl)) { 
    378                 sayWhat(d); 
    379                 return; 
    380             } 
    381  
    382             FnDecl f = (FnDecl) d; 
    383             FnHeader h = f.getHeader(); 
    384             IdOrOpOrAnonymousName xname = h.getName(); 
    385             IdOrOp name = (IdOrOp) xname; 
    386             String desc = Naming.generateTypeDescriptor(f); 
    387             debug("about to call visitMethod with", name.getText(), 
    388                   " and desc ", desc); 
    389             mv = cw.visitMethod(Opcodes.ACC_ABSTRACT + Opcodes.ACC_PUBLIC, 
    390                                 NamingCzar.mangleIdentifier(name.getText()), desc, null, null); 
     418 
     419    public void forDo(Do x) { 
     420        debug("forDo ", x); 
     421        int onStack = 0; 
     422        for ( Block b : x.getFronts() ) { 
     423            popAll(onStack); 
     424            b.accept(this); 
     425            onStack = 1; 
     426        } 
     427    } 
     428 
     429    public void forFnDecl(FnDecl x) { 
     430        debug("forFnDecl ", x ); 
     431        FnHeader header = x.getHeader(); 
     432        boolean canCompile = 
     433            header.getStaticParams().isEmpty() && // no static parameter 
     434            header.getWhereClause().isNone() &&   // no where clause 
     435            header.getThrowsClause().isNone() &&  // no throws clause 
     436            header.getContract().isNone() &&      // no contract 
     437            header.getMods().isEmpty() &&         // no modifiers 
     438            !inABlock;                            // no local functions 
     439 
     440        if ( !canCompile ) sayWhat(x); 
     441 
     442        Option<Expr> body = x.getBody(); 
     443        IdOrOpOrAnonymousName name = header.getName(); 
     444        List<Param> params = header.getParams(); 
     445        boolean functionalMethod = false; 
     446        boolean emitUnambiguous = false; 
     447 
     448        for (Param p : params) { 
     449            debug("iterating params looking for self : param = ", p); 
     450            if (p.getName().getText() == "self") 
     451                functionalMethod = true; 
     452        } 
     453 
     454        Option<com.sun.fortress.nodes.Type> returnType = header.getReturnType(); 
     455 
     456        // For now every Fortress entity is made public, with 
     457        // namespace management happening in Fortress-land.  Right? 
     458        int modifiers = Opcodes.ACC_PUBLIC; 
     459 
     460        if ( body.isNone() ) 
     461            sayWhat(x, "Abstract function declarations are not supported."); 
     462        if ( returnType.isNone() ) 
     463            sayWhat(x, "Return type is not inferred."); 
     464        if ( !( name instanceof IdOrOp )) 
     465            sayWhat(x, "Unhandled function name."); 
     466 
     467        String nameString = ((IdOrOp)name).getText(); 
     468        if ( name instanceof Id ) { 
     469            Id id = (Id) name; 
     470            debug("forId ", id, 
     471                  " class = ", Naming.getJavaClassForSymbol(id)); 
     472        } else if ( name instanceof Op ) { 
     473            Op op = (Op) name; 
     474            Fixity fixity = op.getFixity(); 
     475            boolean isEnclosing = op.isEnclosing(); 
     476            Option<APIName> maybe_apiName = op.getApiName(); 
     477            debug("forOp ", op, " fixity = ", fixity, 
     478                  " isEnclosing = ", isEnclosing, 
     479                  " class = ", Naming.getJavaClassForSymbol(op)); 
     480        } else { 
     481            sayWhat(x); 
     482        } 
     483 
     484        CodeGen cg = new CodeGen(this); 
     485        cg.localsDepth = 0; 
     486 
     487        if (!functionalMethod && (inAnObject || inATrait)) { 
     488            // TODO: Add proper type information here based on the 
     489            // enclosing trait/object decl.  For now we can get away 
     490            // with just stashing a null as we're not using it to 
     491            // determine stack sizing or anything similarly crucial. 
     492            cg.addLocalVar(new VarCodeGen.SelfVar(NodeUtil.getSpan(name), null)); 
     493        } else if (!nameString.equals("run")) { 
     494            // Top-level function or functional method 
     495             
     496            // I'm a little puzzled about how else "run" might be called, 
     497            // if it is not static.  (DRC) 
     498            modifiers += Opcodes.ACC_STATIC; 
     499        } 
     500 
     501        String mname = NamingCzar.mangleIdentifier(nameString); 
     502        String sig = Naming.emitFnDeclDesc(NodeUtil.getParamType(x), 
     503                returnType.unwrap()); 
     504         
     505        if (overloadedNamesAndSigs.contains(mname+sig)) { 
     506            mname = NamingCzar.only.mangleAwayFromOverload(mname); 
     507        } 
     508         
     509        cg.mv = cw.visitMethod(modifiers, 
     510                               mname, 
     511                               sig, 
     512                               null, null); 
     513 
     514        // Now inside method body.  Generate code for the method body. 
     515        for (Param p : params) { 
     516            VarCodeGen v = cg.addParam(p); 
     517            // v.pushValue(cg.mv); 
     518        } 
     519        body.unwrap().accept(cg); 
     520 
     521        // Method body is complete except for returning final result if any. 
     522        // TODO: Fancy footwork here later on if we need to return a non-pointer; 
     523        // for now every fortress functional returns a single pointer result. 
     524        cg.mv.visitInsn(Opcodes.ARETURN); 
     525        cg.mv.visitMaxs(NamingCzar.ignore,NamingCzar.ignore); 
     526        cg.mv.visitEnd(); 
     527        // Method body complete, cg now invalid. 
     528         
     529        // Check to see if a wrapper is needed. 
     530        if (topLevelOverloads.containsKey(name)) { 
     531             
     532        } 
     533         
     534        Option<IdOrOp> iun = x.getImplementsUnambiguousName(); 
     535         
     536        if (iun.isSome()) { 
     537             
     538        } 
     539    } 
     540 
     541 
     542    // Setting up the alias table which we will refer to at runtime. 
     543    public void forFnRef(FnRef x) { 
     544        debug("forFnRef ", x); 
     545        String name = x.getOriginalName().getText(); 
     546        Option<com.sun.fortress.nodes.Type> type = x.getInfo().getExprType(); 
     547        if ( type.isNone() ) { 
     548            sayWhat( x, "The type of this expression is not inferred." ); 
     549        } 
     550        /* Arrow, or perhaps an intersection if it is an overloaded function. */ 
     551        com.sun.fortress.nodes.Type arrow = type.unwrap(); 
     552 
     553        List<IdOrOp> names = x.getNames(); 
     554 
     555        /* Note that after pre-processing in the overload rewriter, there is 
     556         * only one name here; this is not an overload check. 
     557         */ 
     558        if ( names.size() == 1) { 
     559            IdOrOp fnName = names.get(0); 
     560            Option<APIName> apiName = fnName.getApiName(); 
     561            if (apiName.isSome() && ForeignJava.only.definesApi(apiName.unwrap())) { 
     562 
     563                if ( aliasTable.containsKey(name) ) { 
     564                    String n = aliasTable.get(name); 
     565                    // Cheating by assuming class is everything before the dot. 
     566                    int lastDot = n.lastIndexOf("."); 
     567                    String calleePackageAndClass = n.substring(0, lastDot).replace(".", "/"); 
     568                    String _method = n.substring(lastDot+1); 
     569 
     570 
     571                   callStaticSingleOrOverloaded(x, arrow, calleePackageAndClass, _method); 
     572                } else { 
     573                 sayWhat(x, "Should be a foreign function in Alias table"); 
     574                } 
     575 
     576            } else { 
     577                // NOT Foreign 
     578 
     579                // deal with in component, or in imported api. 
     580                String calleePackageAndClass = apiName.isSome() ? 
     581                        NamingCzar.fortressPackage + "/" + apiName.unwrap().getText() 
     582                        : packageAndClassName; 
     583                String _method = fnName.getText(); 
     584 
     585                callStaticSingleOrOverloaded(x, arrow, calleePackageAndClass, _method); 
     586 
     587 
     588            } 
     589        } else { 
     590//             sayWhat(x, "Expected to see only one name here"); 
     591//         } 
     592//     } 
     593        } 
     594    } 
     595 
     596    public void forIf(If x) { 
     597        Debug.debug( Debug.Type.CODEGEN, 1,"forIf " + x); 
     598        List<IfClause> clauses = x.getClauses(); 
     599        Option<Block> elseClause = x.getElseClause(); 
     600        if (clauses.size() > 1) throw new CompilerError(NodeUtil.getSpan(x), "Don't know how to compile multiple if clauses yet"); 
     601 
     602        org.objectweb.asm.Label action = new org.objectweb.asm.Label(); 
     603        org.objectweb.asm.Label done = new org.objectweb.asm.Label(); 
     604        IfClause ifclause = clauses.get(0); 
     605        GeneratorClause cond = ifclause.getTestClause(); 
     606 
     607        if (!cond.getBind().isEmpty()) 
     608            sayWhat(x, "Undesugared generalized if expression."); 
     609 
     610        Expr testExpr = cond.getInit(); 
     611        debug( "about to accept " + testExpr + " of class " + testExpr.getClass()); 
     612        testExpr.accept(this); 
     613        addLineNumberInfo(x); 
     614        mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, NamingCzar.internalFortressBoolean, "getValue", 
     615                           NamingCzar.makeMethodDesc("", NamingCzar.descBoolean)); 
     616 
     617        mv.visitJumpInsn(Opcodes.IFNE, action); 
     618        Option<Block> maybe_else = x.getElseClause(); 
     619        if (maybe_else.isSome()) { 
     620            maybe_else.unwrap().accept(this); 
     621        } 
     622        mv.visitJumpInsn(Opcodes.GOTO, done); 
     623        mv.visitLabel(action); 
     624        ifclause.getBody().accept(this); 
     625        mv.visitLabel(done); 
     626    } 
     627 
     628    public void forImportNames(ImportNames x) { 
     629        debug("forImportNames", x); 
     630        Option<String> foreign = x.getForeignLanguage(); 
     631        if ( !foreign.isSome() ) return; 
     632        if ( !foreign.unwrap().equals("java") ) { 
     633            sayWhat(x, "Unrecognized foreign import type (only recognize java): "+ 
     634                       foreign.unwrap()); 
     635            return; 
     636        } 
     637        String apiName = x.getApiName().getText(); 
     638        for ( AliasedSimpleName n : x.getAliasedNames() ) { 
     639            Option<IdOrOpOrAnonymousName> aliasId = n.getAlias(); 
     640            if (!(aliasId.isSome())) continue; 
     641            debug("forImportNames ", x, 
     642                  " aliasing ", NodeUtil.nameString(aliasId.unwrap()), 
     643                  " to ", NodeUtil.nameString(n.getName())); 
     644            aliasTable.put(NodeUtil.nameString(aliasId.unwrap()), 
     645                           apiName + "." + NodeUtil.nameString(n.getName())); 
     646        } 
     647    } 
     648 
     649    public void forIntLiteralExpr(IntLiteralExpr x) { 
     650        debug("forIntLiteral ", x); 
     651        BigInteger bi = x.getIntVal(); 
     652        // This might not work. 
     653        int l = bi.bitLength(); 
     654        if (l < 32) { 
     655            int y = bi.intValue(); 
     656            addLineNumberInfo(x); 
     657            pushInteger(y); 
     658            addLineNumberInfo(x); 
     659 
     660            mv.visitMethodInsn(Opcodes.INVOKESTATIC, 
     661                    NamingCzar.internalFortressZZ32, NamingCzar.make, 
     662                    NamingCzar.makeMethodDesc(NamingCzar.descInt, 
     663                                              NamingCzar.descFortressZZ32)); 
     664        } else if (l < 64) { 
     665            long yy = bi.longValue(); 
     666            addLineNumberInfo(x); 
     667            mv.visitLdcInsn(yy); 
     668            addLineNumberInfo(x); 
     669            mv.visitMethodInsn(Opcodes.INVOKESTATIC, 
     670                    NamingCzar.internalFortressZZ64, NamingCzar.make, 
     671                    NamingCzar.makeMethodDesc(NamingCzar.descLong, 
     672                                              NamingCzar.descFortressZZ64)); 
     673        } 
     674    } 
     675 
     676    public void forObjectDecl(ObjectDecl x) { 
     677        debug("forObjectDecl", x); 
     678        TraitTypeHeader header = x.getHeader(); 
     679        List<TraitTypeWhere> extendsC = header.getExtendsClause(); 
     680        boolean canCompile = 
     681            x.getParams().isNone() &&             // no parameters 
     682            header.getStaticParams().isEmpty() && // no static parameter 
     683            header.getWhereClause().isNone() &&   // no where clause 
     684            header.getThrowsClause().isNone() &&  // no throws clause 
     685            header.getContract().isNone() &&      // no contract 
     686            //            header.getDecls().isEmpty() &&        // no members 
     687            header.getMods().isEmpty()         && // no modifiers 
     688            ( extendsC.size() <= 1 ); // 0 or 1 super trait 
     689        if ( !canCompile ) sayWhat(x); 
     690        inAnObject = true; 
     691        String [] superInterfaces = NamingCzar.extendsClauseToInterfaces(extendsC); 
     692 
     693        if (!header.getDecls().isEmpty()) { 
     694            debug("header.getDecls:", header.getDecls()); 
     695 
     696            cw.visitField(Opcodes.ACC_STATIC + Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL, 
     697                          "default_args", 
     698                          "LCompilerSystem$args;", 
     699                          null, 
     700                          null); 
     701 
     702            mv = cw.visitMethod(Opcodes.ACC_STATIC, 
     703                                "<clinit>", 
     704                                "()V", 
     705                                null, 
     706                                null); 
     707 
     708            mv.visitTypeInsn(Opcodes.NEW, "CompilerSystem$args"); 
     709            mv.visitInsn(Opcodes.DUP); 
     710            mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "CompilerSystem$args", "<init>", NamingCzar.voidToVoid); 
     711            mv.visitFieldInsn(Opcodes.PUTSTATIC, "CompilerSystem", "default_args", "LCompilerSystem$args;"); 
     712            mv.visitInsn(Opcodes.RETURN); 
    391713            mv.visitMaxs(NamingCzar.ignore, NamingCzar.ignore); 
    392714            mv.visitEnd(); 
    393715        } 
    394     } 
    395  
    396     private void dumpDecls(List<Decl> decls) { 
    397         debug("dumpDecls", decls); 
    398         for (Decl d : decls) { 
    399             if (!(d instanceof FnDecl)) { 
    400                 sayWhat(d); 
    401                 return; 
    402             } 
     716 
     717        String classFile = Naming.makeClassName(packageAndClassName, x); 
     718        ClassWriter prev = cw; 
     719        cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES); 
     720        cw.visitSource(classFile, null); 
     721        // Until we resolve the directory hierarchy problem. 
     722        //            cw.visit( Opcodes.V1_5, Opcodes.ACC_PUBLIC + Opcodes.ACC_SUPER+ Opcodes.ACC_FINAL, 
     723        //                      classFile, null, NamingCzar.internalObject, new String[] { parent }); 
     724        cw.visit( Opcodes.V1_5, Opcodes.ACC_PUBLIC + Opcodes.ACC_SUPER+ Opcodes.ACC_FINAL, 
     725                  classFile, null, NamingCzar.internalObject, superInterfaces); 
     726 
     727        generateInitMethod(); 
     728 
     729        for (Decl d : header.getDecls()) { 
    403730            d.accept(this); 
    404         } 
     731            // If we have a singleton object we can create a default_xxx accessor for it. 
     732            if (d instanceof ObjectDecl) { 
     733            } 
     734        } 
     735        dumpClass( classFile ); 
     736        cw = prev; 
     737        inAnObject = false; 
     738    } 
     739 
     740    public void forOpExpr(OpExpr x) { 
     741        debug("forOpExpr ", x, " op = ", x.getOp(), 
     742                     " of class ", x.getOp().getClass(),  " args = ", x.getArgs()); 
     743        FunctionalRef op = x.getOp(); 
     744 
     745        List<Expr> args = x.getArgs(); 
     746        for (Expr arg : args) { 
     747            arg.accept(this); 
     748        } 
     749        op.accept(this); 
     750    } 
     751 
     752    public void forOpRef(OpRef x) { 
     753        debug("forOpRef " + x ); 
     754        ExprInfo info = x.getInfo(); 
     755        Option<com.sun.fortress.nodes.Type> exprType = info.getExprType(); 
     756        List<StaticArg> staticArgs = x.getStaticArgs(); 
     757        int lexicalDepth = x.getLexicalDepth(); 
     758        IdOrOp originalName = x.getOriginalName(); 
     759        List<IdOrOp> names = x.getNames(); 
     760        Option<List<FunctionalRef>> overloadings = x.getOverloadings(); 
     761        Option<com.sun.fortress.nodes.Type> overloadingType = x.getOverloadingType(); 
     762        debug("forOpRef ", x, 
     763                     " info = ", info, "staticArgs = ", staticArgs, " exprType = ", exprType, 
     764                     " lexicalDepth = ", lexicalDepth, " originalName = ", originalName, 
     765                     " overloadings = ", overloadings, 
     766                     " overloadingType = ", overloadingType, " names = ", names); 
     767 
     768        boolean canCompile = 
     769            x.getStaticArgs().isEmpty() && 
     770            x.getOverloadings().isNone() && 
     771            names.size() == 1; 
     772 
     773        if (canCompile) { 
     774            String name = NamingCzar.mangleIdentifier(originalName.getText()); 
     775            IdOrOp newName = names.get(0); 
     776            Option<APIName> api = newName.getApiName(); 
     777 
     778            addLineNumberInfo(x); 
     779 
     780            if (api.isSome()) { 
     781                APIName apiName = api.unwrap(); 
     782                debug("forOpRef name = ", name, 
     783                             " api = ", apiName); 
     784                if (exprType.isSome()) 
     785                    mv.visitMethodInsn(Opcodes.INVOKESTATIC, Naming.getJavaClassForSymbol(newName), 
     786                                       NamingCzar.mangleIdentifier(newName.getText()), 
     787                                       Naming.emitDesc(exprType.unwrap())); 
     788                else 
     789                    mv.visitMethodInsn(Opcodes.INVOKESTATIC, 
     790                                       NamingCzar.fortressPackage + "/" + api.unwrap().getText(), 
     791                                       NamingCzar.mangleIdentifier(newName.getText()), 
     792                                       symbols.getTypeSignatureForIdOrOp(newName, component)); 
     793 
     794            } else { 
     795                if (exprType.isSome()) 
     796                    mv.visitMethodInsn(Opcodes.INVOKESTATIC, packageAndClassName, NamingCzar.mangleIdentifier(name), 
     797                                       Naming.emitDesc(exprType.unwrap())); 
     798                else 
     799                    mv.visitMethodInsn(Opcodes.INVOKESTATIC, packageAndClassName, 
     800                                       NamingCzar.mangleIdentifier(name), symbols.getTypeSignatureForIdOrOp(newName, component)); 
     801            } 
     802        } else 
     803            debug("forOpRef can't compile staticArgs ", 
     804                        x.getStaticArgs().isEmpty(), " overloadings ", 
     805                        x.getOverloadings().isNone()); 
     806 
     807    } 
     808 
     809    public void forStringLiteralExpr(StringLiteralExpr x) { 
     810        // This is cheating, but the best we can do for now. 
     811        // We make a FString and push it on the stack. 
     812        debug("forStringLiteral ", x); 
     813        addLineNumberInfo(x); 
     814        mv.visitLdcInsn(x.getText()); 
     815        addLineNumberInfo(x); 
     816        mv.visitMethodInsn(Opcodes.INVOKESTATIC, NamingCzar.internalFortressString, NamingCzar.make, 
     817                           NamingCzar.makeMethodDesc(NamingCzar.descString, NamingCzar.descFortressString)); 
     818    } 
     819 
     820    public void forSubscriptExpr(SubscriptExpr x) { 
     821        debug("forSubscriptExpr ", x); 
     822        Expr obj = x.getObj(); 
     823        List<Expr> subs = x.getSubs(); 
     824        Option<Op> maybe_op = x.getOp(); 
     825        List<StaticArg> staticArgs = x.getStaticArgs(); 
     826        boolean canCompile = staticArgs.isEmpty() && maybe_op.isSome() && (obj instanceof VarRef); 
     827        if (!canCompile) { sayWhat(x); return; } 
     828        Op op = maybe_op.unwrap(); 
     829        VarRef var = (VarRef) obj; 
     830        Id id = var.getVarId(); 
     831 
     832        debug("ForSubscriptExpr  ", x, "obj = ", obj, 
     833              " subs = ", subs, " op = ", op, " static args = ", staticArgs, 
     834              " varRef = ", id.getText()); 
     835 
     836        addLineNumberInfo(x); 
     837        mv.visitFieldInsn(Opcodes.GETSTATIC, Naming.getJavaClassForSymbol(id) , "default_" + id.getText(), 
     838                          "L" + Naming.getJavaClassForSymbol(id) + "$" + id.getText() + ";"); 
     839 
     840 
     841 
     842        for (Expr e : subs) { 
     843            debug("calling accept on ", e); 
     844            e.accept(this); 
     845        } 
     846        addLineNumberInfo(x); 
     847        mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, 
     848                           Naming.getJavaClassForSymbol(id) + "$" + id.getText(), 
     849                           NamingCzar.mangleIdentifier(op.getText()), 
     850                           "(Lcom/sun/fortress/compiler/runtimeValues/FZZ32;)Lcom/sun/fortress/compiler/runtimeValues/FString;"); 
    405851    } 
    406852 
     
    459905    } 
    460906 
    461     public void forObjectDecl(ObjectDecl x) { 
    462         debug("forObjectDecl", x); 
    463         TraitTypeHeader header = x.getHeader(); 
    464         List<TraitTypeWhere> extendsC = header.getExtendsClause(); 
    465         boolean canCompile = 
    466             x.getParams().isNone() &&             // no parameters 
    467             header.getStaticParams().isEmpty() && // no static parameter 
    468             header.getWhereClause().isNone() &&   // no where clause 
    469             header.getThrowsClause().isNone() &&  // no throws clause 
    470             header.getContract().isNone() &&      // no contract 
    471             //            header.getDecls().isEmpty() &&        // no members 
    472             header.getMods().isEmpty()         && // no modifiers 
    473             ( extendsC.size() <= 1 ); // 0 or 1 super trait 
    474         if ( !canCompile ) sayWhat(x); 
    475         inAnObject = true; 
    476         String [] superInterfaces = NamingCzar.extendsClauseToInterfaces(extendsC); 
    477  
    478         if (!header.getDecls().isEmpty()) { 
    479             debug("header.getDecls:", header.getDecls()); 
    480  
    481             cw.visitField(Opcodes.ACC_STATIC + Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL, 
    482                           "default_args", 
    483                           "LCompilerSystem$args;", 
    484                           null, 
    485                           null); 
    486  
    487             mv = cw.visitMethod(Opcodes.ACC_STATIC, 
    488                                 "<clinit>", 
    489                                 "()V", 
    490                                 null, 
    491                                 null); 
    492  
    493             mv.visitTypeInsn(Opcodes.NEW, "CompilerSystem$args"); 
    494             mv.visitInsn(Opcodes.DUP); 
    495             mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "CompilerSystem$args", "<init>", NamingCzar.voidToVoid); 
    496             mv.visitFieldInsn(Opcodes.PUTSTATIC, "CompilerSystem", "default_args", "LCompilerSystem$args;"); 
    497             mv.visitInsn(Opcodes.RETURN); 
    498             mv.visitMaxs(NamingCzar.ignore, NamingCzar.ignore); 
    499             mv.visitEnd(); 
    500         } 
    501  
    502         String classFile = Naming.makeClassName(packageAndClassName, x); 
    503         ClassWriter prev = cw; 
    504         cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES); 
    505         cw.visitSource(classFile, null); 
    506         // Until we resolve the directory hierarchy problem. 
    507         //            cw.visit( Opcodes.V1_5, Opcodes.ACC_PUBLIC + Opcodes.ACC_SUPER+ Opcodes.ACC_FINAL, 
    508         //                      classFile, null, NamingCzar.internalObject, new String[] { parent }); 
    509         cw.visit( Opcodes.V1_5, Opcodes.ACC_PUBLIC + Opcodes.ACC_SUPER+ Opcodes.ACC_FINAL, 
    510                   classFile, null, NamingCzar.internalObject, superInterfaces); 
    511  
    512         generateInitMethod(); 
    513  
    514         for (Decl d : header.getDecls()) { 
    515             d.accept(this); 
    516             // If we have a singleton object we can create a default_xxx accessor for it. 
    517             if (d instanceof ObjectDecl) { 
    518             } 
    519         } 
    520         dumpClass( classFile ); 
    521         cw = prev; 
    522         inAnObject = false; 
    523     } 
    524  
    525     public void forOpExpr(OpExpr x) { 
    526         debug("forOpExpr ", x, " op = ", x.getOp(), 
    527                      " of class ", x.getOp().getClass(),  " args = ", x.getArgs()); 
    528         FunctionalRef op = x.getOp(); 
    529  
    530         List<Expr> args = x.getArgs(); 
    531         for (Expr arg : args) { 
    532             arg.accept(this); 
    533         } 
    534         op.accept(this); 
    535     } 
    536  
    537     private void addLineNumberInfo(ASTNode x) { 
    538         addLineNumberInfo(mv, x); 
    539     } 
    540  
    541     private void addLineNumberInfo(MethodVisitor m, ASTNode x) { 
    542         org.objectweb.asm.Label bogus_label = new org.objectweb.asm.Label(); 
    543         m.visitLabel(bogus_label); 
    544         Span span = NodeUtil.getSpan(x); 
    545         SourceLoc begin = span.getBegin(); 
    546         SourceLoc end = span.getEnd(); 
    547         String fileName = span.getFileName(); 
    548         m.visitLineNumber(begin.getLine(), bogus_label); 
    549     } 
    550  
    551     public static String jvmSignatureFor(Function f) { 
    552         String sig; 
    553         List<Param> params = f.parameters(); 
    554         sig = "("; 
    555         for (Param p : params ) {                 
    556             Type ty = p.getIdType().unwrap(); 
    557             String toType = NamingCzar.only.boxedImplDesc(ty); 
    558             sig += toType; 
    559         } 
    560         sig += ")"; 
    561         sig += NamingCzar.only.boxedImplDesc(f.getReturnType()); 
    562         return sig; 
    563     } 
    564      
    565     public void forOpRef(OpRef x) { 
    566         debug("forOpRef " + x ); 
    567         ExprInfo info = x.getInfo(); 
    568         Option<com.sun.fortress.nodes.Type> exprType = info.getExprType(); 
    569         List<StaticArg> staticArgs = x.getStaticArgs(); 
    570         int lexicalDepth = x.getLexicalDepth(); 
    571         IdOrOp originalName = x.getOriginalName(); 
    572         List<IdOrOp> names = x.getNames(); 
    573         Option<List<FunctionalRef>> overloadings = x.getOverloadings(); 
    574         Option<com.sun.fortress.nodes.Type> overloadingType = x.getOverloadingType(); 
    575         debug("forOpRef ", x, 
    576                      " info = ", info, "staticArgs = ", staticArgs, " exprType = ", exprType, 
    577                      " lexicalDepth = ", lexicalDepth, " originalName = ", originalName, 
    578                      " overloadings = ", overloadings, 
    579                      " overloadingType = ", overloadingType, " names = ", names); 
    580  
    581         boolean canCompile = 
    582             x.getStaticArgs().isEmpty() && 
    583             x.getOverloadings().isNone() && 
    584             names.size() == 1; 
    585  
    586         if (canCompile) { 
    587             String name = NamingCzar.mangleIdentifier(originalName.getText()); 
    588             IdOrOp newName = names.get(0); 
    589             Option<APIName> api = newName.getApiName(); 
    590  
    591             addLineNumberInfo(x); 
    592  
    593             if (api.isSome()) { 
    594                 APIName apiName = api.unwrap(); 
    595                 debug("forOpRef name = ", name, 
    596                              " api = ", apiName); 
    597                 if (exprType.isSome()) 
    598                     mv.visitMethodInsn(Opcodes.INVOKESTATIC, Naming.getJavaClassForSymbol(newName), 
    599                                        NamingCzar.mangleIdentifier(newName.getText()), 
    600                                        Naming.emitDesc(exprType.unwrap())); 
    601                 else 
    602                     mv.visitMethodInsn(Opcodes.INVOKESTATIC, 
    603                                        NamingCzar.fortressPackage + "/" + api.unwrap().getText(), 
    604                                        NamingCzar.mangleIdentifier(newName.getText()), 
    605                                        symbols.getTypeSignatureForIdOrOp(newName, component)); 
    606  
    607             } else { 
    608                 if (exprType.isSome()) 
    609                     mv.visitMethodInsn(Opcodes.INVOKESTATIC, packageAndClassName, NamingCzar.mangleIdentifier(name), 
    610                                        Naming.emitDesc(exprType.unwrap())); 
    611                 else 
    612                     mv.visitMethodInsn(Opcodes.INVOKESTATIC, packageAndClassName, 
    613                                        NamingCzar.mangleIdentifier(name), symbols.getTypeSignatureForIdOrOp(newName, component)); 
    614             } 
    615         } else 
    616             debug("forOpRef can't compile staticArgs ", 
    617                         x.getStaticArgs().isEmpty(), " overloadings ", 
    618                         x.getOverloadings().isNone()); 
    619  
    620     } 
    621  
    622     public void for_RewriteFnOverloadDecl(_RewriteFnOverloadDecl x) { 
    623         /* Note for refactoring -- this code does it the "right" way. 
    624          * And also, this code NEEDS refactoring. 
    625          */ 
    626         List<IdOrOp> fns = x.getFns(); 
    627         IdOrOp name = x.getName(); 
    628         Option<com.sun.fortress.nodes.Type> ot = x.getType(); 
    629         Relation<IdOrOpOrAnonymousName, Function> fnrl = ci.functions(); 
    630  
    631         MultiMap<Integer, OverloadSet.TaggedFunctionName> byCount = 
    632             new MultiMap<Integer,OverloadSet.TaggedFunctionName>(); 
    633  
    634         for (IdOrOp fn : fns) { 
    635  
    636             Option<APIName> fnapi = fn.getApiName(); 
    637             PredicateSet<Function> set_of_f; 
    638             APIName apiname; 
    639  
    640             if (fnapi.isNone()) { 
    641                 apiname = ci.ast().getName(); 
    642                 set_of_f = fnrl.matchFirst(fn); 
    643             } else { 
    644                 apiname = fnapi.unwrap(); 
    645                 ApiIndex ai = symbols.apis.get(apiname); 
    646                 IdOrOp fnnoapi = NodeFactory.makeLocalIdOrOp(fn); 
    647                 set_of_f = ai.functions().matchFirst(fnnoapi); 
    648             } 
    649  
    650             for (Function f : set_of_f) { 
    651                 OverloadSet.TaggedFunctionName tagged_f = new OverloadSet.TaggedFunctionName(apiname, f); 
    652                 byCount.putItem(f.parameters().size(), tagged_f); 
    653             } 
    654  
    655             for (Map.Entry<Integer, Set<OverloadSet.TaggedFunctionName>> entry : byCount 
    656                     .entrySet()) { 
    657                 int i = entry.getKey(); 
    658                 Set<OverloadSet.TaggedFunctionName> fs = entry.getValue(); 
    659                 if (fs.size() > 1) { 
    660                     OverloadSet os = new OverloadSet.AmongApis(name, 
    661                             ta, fs, i); 
    662  
    663                     os.split(false); 
    664                     os.generateAnOverloadDefinition(name.stringName(), cw); 
    665  
    666                 } 
    667             } 
    668         } 
    669     } 
    670  
    671     public void forFnDecl(FnDecl x) { 
    672         debug("forFnDecl ", x ); 
    673         FnHeader header = x.getHeader(); 
    674         boolean canCompile = 
    675             header.getStaticParams().isEmpty() && // no static parameter 
    676             header.getWhereClause().isNone() &&   // no where clause 
    677             header.getThrowsClause().isNone() &&  // no throws clause 
    678             header.getContract().isNone() &&      // no contract 
    679             header.getMods().isEmpty() &&         // no modifiers 
    680             !inABlock;                            // no local functions 
    681  
    682         if ( !canCompile ) sayWhat(x); 
    683  
    684         Option<Expr> body = x.getBody(); 
    685         IdOrOpOrAnonymousName name = header.getName(); 
    686         List<Param> params = header.getParams(); 
    687         boolean functionalMethod = false; 
    688         boolean emitUnambiguous = false; 
    689  
    690         for (Param p : params) { 
    691             debug("iterating params looking for self : param = ", p); 
    692             if (p.getName().getText() == "self") 
    693                 functionalMethod = true; 
    694         } 
    695  
    696         Option<com.sun.fortress.nodes.Type> returnType = header.getReturnType(); 
    697  
    698         // For now every Fortress entity is made public, with 
    699         // namespace management happening in Fortress-land.  Right? 
    700         int modifiers = Opcodes.ACC_PUBLIC; 
    701  
    702         if ( body.isNone() ) 
    703             sayWhat(x, "Abstract function declarations are not supported."); 
    704         if ( returnType.isNone() ) 
    705             sayWhat(x, "Return type is not inferred."); 
    706         if ( !( name instanceof IdOrOp )) 
    707             sayWhat(x, "Unhandled function name."); 
    708  
    709         String nameString = ((IdOrOp)name).getText(); 
    710         if ( name instanceof Id ) { 
    711             Id id = (Id) name; 
    712             debug("forId ", id, 
    713                   " class = ", Naming.getJavaClassForSymbol(id)); 
    714         } else if ( name instanceof Op ) { 
    715             Op op = (Op) name; 
    716             Fixity fixity = op.getFixity(); 
    717             boolean isEnclosing = op.isEnclosing(); 
    718             Option<APIName> maybe_apiName = op.getApiName(); 
    719             debug("forOp ", op, " fixity = ", fixity, 
    720                   " isEnclosing = ", isEnclosing, 
    721                   " class = ", Naming.getJavaClassForSymbol(op)); 
    722         } else { 
    723             sayWhat(x); 
    724         } 
    725  
    726         CodeGen cg = new CodeGen(this); 
    727         cg.localsDepth = 0; 
    728  
    729         if (!functionalMethod && (inAnObject || inATrait)) { 
    730             // TODO: Add proper type information here based on the 
    731             // enclosing trait/object decl.  For now we can get away 
    732             // with just stashing a null as we're not using it to 
    733             // determine stack sizing or anything similarly crucial. 
    734             cg.addLocalVar(new VarCodeGen.SelfVar(NodeUtil.getSpan(name), null)); 
    735         } else if (!nameString.equals("run")) { 
    736             // Top-level function or functional method 
    737              
    738             // I'm a little puzzled about how else "run" might be called, 
    739             // if it is not static.  (DRC) 
    740             modifiers += Opcodes.ACC_STATIC; 
    741         } 
    742  
    743         String mname = NamingCzar.mangleIdentifier(nameString); 
    744         String sig = Naming.emitFnDeclDesc(NodeUtil.getParamType(x), 
    745                 returnType.unwrap()); 
    746          
    747         if (overloadedNamesAndSigs.contains(mname+sig)) { 
    748             mname = NamingCzar.only.mangleAwayFromOverload(mname); 
    749         } 
    750          
    751         cg.mv = cw.visitMethod(modifiers, 
    752                                mname, 
    753                                sig, 
    754                                null, null); 
    755  
    756         // Now inside method body.  Generate code for the method body. 
    757         for (Param p : params) { 
    758             VarCodeGen v = cg.addParam(p); 
    759             // v.pushValue(cg.mv); 
    760         } 
    761         body.unwrap().accept(cg); 
    762  
    763         // Method body is complete except for returning final result if any. 
    764         // TODO: Fancy footwork here later on if we need to return a non-pointer; 
    765         // for now every fortress functional returns a single pointer result. 
    766         cg.mv.visitInsn(Opcodes.ARETURN); 
    767         cg.mv.visitMaxs(NamingCzar.ignore,NamingCzar.ignore); 
    768         cg.mv.visitEnd(); 
    769         // Method body complete, cg now invalid. 
    770          
    771         // Check to see if a wrapper is needed. 
    772         if (topLevelOverloads.containsKey(name)) { 
    773              
    774         } 
    775          
    776         Option<IdOrOp> iun = x.getImplementsUnambiguousName(); 
    777          
    778         if (iun.isSome()) { 
    779              
    780         } 
    781     } 
    782  
    783     public void forIf(If x) { 
    784         Debug.debug( Debug.Type.CODEGEN, 1,"forIf " + x); 
    785         List<IfClause> clauses = x.getClauses(); 
    786         Option<Block> elseClause = x.getElseClause(); 
    787         if (clauses.size() > 1) throw new CompilerError(NodeUtil.getSpan(x), "Don't know how to compile multiple if clauses yet"); 
    788  
    789         org.objectweb.asm.Label action = new org.objectweb.asm.Label(); 
    790         org.objectweb.asm.Label done = new org.objectweb.asm.Label(); 
    791         IfClause ifclause = clauses.get(0); 
    792         GeneratorClause cond = ifclause.getTestClause(); 
    793  
    794         if (!cond.getBind().isEmpty()) 
    795             sayWhat(x, "Undesugared generalized if expression."); 
    796  
    797         Expr testExpr = cond.getInit(); 
    798         debug( "about to accept " + testExpr + " of class " + testExpr.getClass()); 
    799         testExpr.accept(this); 
     907    public void forVarRef(VarRef v) { 
     908        debug("forVarRef ", v, " which had better be local (for the moment)"); 
     909        if (v.getStaticArgs().size() > 0) { 
     910            sayWhat(v,"varRef with static args!  That requires non-local VarRefs"); 
     911        } 
     912        VarCodeGen vcg = getLocalVar(v.getVarId()); 
     913        vcg.pushValue(mv); 
     914    } 
     915 
     916    public void forVoidLiteralExpr(VoidLiteralExpr x) { 
     917        debug("forVoidLiteral ", x); 
    800918        addLineNumberInfo(x); 
    801         mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, NamingCzar.internalFortressBoolean, "getValue", 
    802                            NamingCzar.makeMethodDesc("", NamingCzar.descBoolean)); 
    803  
    804         mv.visitJumpInsn(Opcodes.IFNE, action); 
    805         Option<Block> maybe_else = x.getElseClause(); 
    806         if (maybe_else.isSome()) { 
    807             maybe_else.unwrap().accept(this); 
    808         } 
    809         mv.visitJumpInsn(Opcodes.GOTO, done); 
    810         mv.visitLabel(action); 
    811         ifclause.getBody().accept(this); 
    812         mv.visitLabel(done); 
    813     } 
    814  
    815     private void popAll(int onStack) { 
    816         if (onStack > 0) { 
    817             for (; onStack > 1; onStack -= 2) { 
    818                 mv.visitInsn(Opcodes.POP2); 
    819             } 
    820             if (onStack==1) { 
    821                 mv.visitInsn(Opcodes.POP); 
    822             } 
    823         } 
    824     } 
    825  
    826     public void forDo(Do x) { 
    827         debug("forDo ", x); 
    828         int onStack = 0; 
    829         for ( Block b : x.getFronts() ) { 
    830             popAll(onStack); 
    831             b.accept(this); 
    832             onStack = 1; 
    833         } 
    834     } 
    835  
    836     public void forBlock(Block x) { 
    837         boolean oldInABlock = inABlock; 
    838         inABlock = true; 
    839         int onStack = 0; 
    840         debug("forBlock ", x); 
    841         for ( Expr e : x.getExprs() ) { 
    842             popAll(onStack); 
    843             e.accept(this); 
    844             onStack = 1; 
    845             // TODO: can we have multiple values on stack in future? 
    846             // Whither primitive types? 
    847             // May require some tracking of abstract stack state. 
    848             // For now we always have 1 pointer on stack and this doesn't 
    849             // matter. 
    850         } 
    851         inABlock=oldInABlock; 
    852     } 
    853  
    854     // Setting up the alias table which we will refer to at runtime. 
    855     public void forFnRef(FnRef x) { 
    856         debug("forFnRef ", x); 
    857         String name = x.getOriginalName().getText(); 
    858         Option<com.sun.fortress.nodes.Type> type = x.getInfo().getExprType(); 
    859         if ( type.isNone() ) { 
    860             sayWhat( x, "The type of this expression is not inferred." ); 
    861         } 
    862         /* Arrow, or perhaps an intersection if it is an overloaded function. */ 
    863         com.sun.fortress.nodes.Type arrow = type.unwrap(); 
    864  
    865         List<IdOrOp> names = x.getNames(); 
    866  
    867         /* Note that after pre-processing in the overload rewriter, there is 
    868          * only one name here; this is not an overload check. 
    869          */ 
    870         if ( names.size() == 1) { 
    871             IdOrOp fnName = names.get(0); 
    872             Option<APIName> apiName = fnName.getApiName(); 
    873             if (apiName.isSome() && ForeignJava.only.definesApi(apiName.unwrap())) { 
    874  
    875                 if ( aliasTable.containsKey(name) ) { 
    876                     String n = aliasTable.get(name); 
    877                     // Cheating by assuming class is everything before the dot. 
    878                     int lastDot = n.lastIndexOf("."); 
    879                     String calleePackageAndClass = n.substring(0, lastDot).replace(".", "/"); 
    880                     String _method = n.substring(lastDot+1); 
    881  
    882  
    883                    callStaticSingleOrOverloaded(x, arrow, calleePackageAndClass, _method); 
    884                 } else { 
    885                  sayWhat(x, "Should be a foreign function in Alias table"); 
    886                 } 
    887  
    888             } else { 
    889                 // NOT Foreign 
    890  
    891                 // deal with in component, or in imported api. 
    892                 String calleePackageAndClass = apiName.isSome() ? 
    893                         NamingCzar.fortressPackage + "/" + apiName.unwrap().getText() 
    894                         : packageAndClassName; 
    895                 String _method = fnName.getText(); 
    896  
    897                 callStaticSingleOrOverloaded(x, arrow, calleePackageAndClass, _method); 
    898  
    899  
    900             } 
    901         } else { 
    902             sayWhat(x, "Expected to see only one name here"); 
    903         } 
    904     } 
    905  
    906     /** 
    907      * @param x 
    908      * @param arrow 
    909      * @param pkgAndClassName 
    910      * @param methodName 
    911      */ 
    912     private void callStaticSingleOrOverloaded(FnRef x, 
    913             com.sun.fortress.nodes.Type arrow, String pkgAndClassName, 
    914             String methodName) { 
    915         { 
    916             debug("class = " + pkgAndClassName + " method = " + methodName ); 
    917  
    918             if ( arrow instanceof ArrowType ) { 
    919                 addLineNumberInfo(x); 
    920                 mv.visitMethodInsn(Opcodes.INVOKESTATIC, pkgAndClassName, 
    921                                    methodName, Naming.emitDesc(arrow)); 
    922             } else if (arrow instanceof IntersectionType) { 
    923                 addLineNumberInfo(x); 
    924                 IntersectionType it = (IntersectionType) arrow; 
    925                 mv.visitMethodInsn(Opcodes.INVOKESTATIC, pkgAndClassName, 
    926                                    OverloadSet.actuallyOverloaded(it, paramCount) ? 
    927                                    OverloadSet.oMangle(methodName) :methodName, 
    928                                    OverloadSet.getSignature(it, paramCount, ta)); 
    929             } else { 
    930                     sayWhat( x, "Neither arrow nor intersection type: " + arrow ); 
    931             } 
    932         } 
    933  
    934     } 
    935  
    936     // paramCount communicates this information from call to function reference, 
    937     // as it's needed to determine type descriptors for methods. 
    938     private int paramCount = -1; 
     919        mv.visitMethodInsn(Opcodes.INVOKESTATIC, NamingCzar.internalFortressVoid, NamingCzar.make, 
     920                           NamingCzar.makeMethodDesc("", NamingCzar.descFortressVoid)); 
     921 
     922    } 
    939923 
    940924    public void for_RewriteFnApp(_RewriteFnApp x) { 
     
    965949    } 
    966950 
    967     public void forSubscriptExpr(SubscriptExpr x) { 
    968         debug("forSubscriptExpr ", x); 
    969         Expr obj = x.getObj(); 
    970         List<Expr> subs = x.getSubs(); 
    971         Option<Op> maybe_op = x.getOp(); 
    972         List<StaticArg> staticArgs = x.getStaticArgs(); 
    973         boolean canCompile = staticArgs.isEmpty() && maybe_op.isSome() && (obj instanceof VarRef); 
    974         if (!canCompile) { sayWhat(x); return; } 
    975         Op op = maybe_op.unwrap(); 
    976         VarRef var = (VarRef) obj; 
    977         Id id = var.getVarId(); 
    978  
    979         debug("ForSubscriptExpr  ", x, "obj = ", obj, 
    980               " subs = ", subs, " op = ", op, " static args = ", staticArgs, 
    981               " varRef = ", id.getText()); 
    982  
    983         addLineNumberInfo(x); 
    984         mv.visitFieldInsn(Opcodes.GETSTATIC, Naming.getJavaClassForSymbol(id) , "default_" + id.getText(), 
    985                           "L" + Naming.getJavaClassForSymbol(id) + "$" + id.getText() + ";"); 
    986  
    987  
    988  
    989         for (Expr e : subs) { 
    990             debug("calling accept on ", e); 
    991             e.accept(this); 
    992         } 
    993         addLineNumberInfo(x); 
    994         mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, 
    995                            Naming.getJavaClassForSymbol(id) + "$" + id.getText(), 
    996                            NamingCzar.mangleIdentifier(op.getText()), 
    997                            "(Lcom/sun/fortress/compiler/runtimeValues/FZZ32;)Lcom/sun/fortress/compiler/runtimeValues/FString;"); 
    998     } 
    999  
    1000  
    1001     public void forIntLiteralExpr(IntLiteralExpr x) { 
    1002         debug("forIntLiteral ", x); 
    1003         BigInteger bi = x.getIntVal(); 
    1004         // This might not work. 
    1005         int l = bi.bitLength(); 
    1006         if (l < 32) { 
    1007             int y = bi.intValue(); 
    1008             addLineNumberInfo(x); 
    1009             pushInteger(y); 
    1010             addLineNumberInfo(x); 
    1011  
    1012             mv.visitMethodInsn(Opcodes.INVOKESTATIC, 
    1013                     NamingCzar.internalFortressZZ32, NamingCzar.make, 
    1014                     NamingCzar.makeMethodDesc(NamingCzar.descInt, 
    1015                                               NamingCzar.descFortressZZ32)); 
    1016         } else if (l < 64) { 
    1017             long yy = bi.longValue(); 
    1018             addLineNumberInfo(x); 
    1019             mv.visitLdcInsn(yy); 
    1020             addLineNumberInfo(x); 
    1021             mv.visitMethodInsn(Opcodes.INVOKESTATIC, 
    1022                     NamingCzar.internalFortressZZ64, NamingCzar.make, 
    1023                     NamingCzar.makeMethodDesc(NamingCzar.descLong, 
    1024                                               NamingCzar.descFortressZZ64)); 
    1025         } 
    1026     } 
    1027  
     951    public void for_RewriteFnOverloadDecl(_RewriteFnOverloadDecl x) { 
     952        /* Note for refactoring -- this code does it the "right" way. 
     953         * And also, this code NEEDS refactoring. 
     954         */ 
     955        List<IdOrOp> fns = x.getFns(); 
     956        IdOrOp name = x.getName(); 
     957        Option<com.sun.fortress.nodes.Type> ot = x.getType(); 
     958        Relation<IdOrOpOrAnonymousName, Function> fnrl = ci.functions(); 
     959 
     960        MultiMap<Integer, OverloadSet.TaggedFunctionName> byCount = 
     961            new MultiMap<Integer,OverloadSet.TaggedFunctionName>(); 
     962 
     963        for (IdOrOp fn : fns) { 
     964 
     965            Option<APIName> fnapi = fn.getApiName(); 
     966            PredicateSet<Function> set_of_f; 
     967            APIName apiname; 
     968 
     969            if (fnapi.isNone()) { 
     970                apiname = ci.ast().getName(); 
     971                set_of_f = fnrl.matchFirst(fn); 
     972            } else { 
     973                apiname = fnapi.unwrap(); 
     974                ApiIndex ai = symbols.apis.get(apiname); 
     975                IdOrOp fnnoapi = NodeFactory.makeLocalIdOrOp(fn); 
     976                set_of_f = ai.functions().matchFirst(fnnoapi); 
     977            } 
     978 
     979            for (Function f : set_of_f) { 
     980                OverloadSet.TaggedFunctionName tagged_f = new OverloadSet.TaggedFunctionName(apiname, f); 
     981                byCount.putItem(f.parameters().size(), tagged_f); 
     982            } 
     983 
     984            for (Map.Entry<Integer, Set<OverloadSet.TaggedFunctionName>> entry : byCount 
     985                    .entrySet()) { 
     986                int i = entry.getKey(); 
     987                Set<OverloadSet.TaggedFunctionName> fs = entry.getValue(); 
     988                if (fs.size() > 1) { 
     989                    OverloadSet os = new OverloadSet.AmongApis(name, 
     990                            ta, fs, i); 
     991 
     992                    os.split(false); 
     993                    os.generateAnOverloadDefinition(name.stringName(), cw); 
     994 
     995                } 
     996            } 
     997        } 
     998    } 
     999 
     1000    
    10281001    /** 
    1029      * @param y 
     1002     * Creates overloaded functions for any overloads present at the top level 
     1003     * of this component.  Top level overloads are those that might be exported; 
     1004     * Reference overloads are rewritten into _RewriteFnOverloadDecl nodes 
     1005     * and generated in the normal visits. 
    10301006     */ 
    1031     private void pushInteger(int y) { 
    1032         switch (y) { 
    1033         case 0: 
    1034             mv.visitInsn(Opcodes.ICONST_0); 
    1035             break; 
    1036         case 1: 
    1037             mv.visitInsn(Opcodes.ICONST_1); 
    1038             break; 
    1039         case 2: 
    1040             mv.visitInsn(Opcodes.ICONST_2); 
    1041             break; 
    1042         case 3: 
    1043             mv.visitInsn(Opcodes.ICONST_3); 
    1044             break; 
    1045         case 4: 
    1046             mv.visitInsn(Opcodes.ICONST_4); 
    1047             break; 
    1048         case 5: 
    1049             mv.visitInsn(Opcodes.ICONST_5); 
    1050             break; 
    1051         default: 
    1052             mv.visitLdcInsn(y); 
    1053             break; 
    1054         } 
    1055  
    1056     } 
    1057  
    1058  
    1059     public void forStringLiteralExpr(StringLiteralExpr x) { 
    1060         // This is cheating, but the best we can do for now. 
    1061         // We make a FString and push it on the stack. 
    1062         debug("forStringLiteral ", x); 
    1063         addLineNumberInfo(x); 
    1064         mv.visitLdcInsn(x.getText()); 
    1065         addLineNumberInfo(x); 
    1066         mv.visitMethodInsn(Opcodes.INVOKESTATIC, NamingCzar.internalFortressString, NamingCzar.make, 
    1067                            NamingCzar.makeMethodDesc(NamingCzar.descString, NamingCzar.descFortressString)); 
    1068     } 
    1069  
    1070     public void forVoidLiteralExpr(VoidLiteralExpr x) { 
    1071         debug("forVoidLiteral ", x); 
    1072         addLineNumberInfo(x); 
    1073         mv.visitMethodInsn(Opcodes.INVOKESTATIC, NamingCzar.internalFortressVoid, NamingCzar.make, 
    1074                            NamingCzar.makeMethodDesc("", NamingCzar.descFortressVoid)); 
    1075  
    1076     } 
    1077  
    1078     public void forVarRef(VarRef v) { 
    1079         debug("forVarRef ", v, " which had better be local (for the moment)"); 
    1080         if (v.getStaticArgs().size() > 0) { 
    1081             sayWhat(v,"varRef with static args!  That requires non-local VarRefs"); 
    1082         } 
    1083         VarCodeGen vcg = getLocalVar(v.getVarId()); 
    1084         vcg.pushValue(mv); 
    1085     } 
    1086  
     1007    private void generateTopLevelOverloads() { 
     1008                 
     1009        for (Map.Entry<IdOrOpOrAnonymousName, MultiMap<Integer, Function>> entry1 : topLevelOverloads.entrySet()) { 
     1010            IdOrOpOrAnonymousName  name = entry1.getKey(); 
     1011            MultiMap<Integer, Function> partitionedByArgCount = entry1.getValue(); 
     1012             
     1013            for (Map.Entry<Integer, Set<Function>> entry : partitionedByArgCount 
     1014                    .entrySet()) { 
     1015               int i = entry.getKey(); 
     1016               Set<Function> fs = entry.getValue(); 
     1017 
     1018               OverloadSet os = 
     1019                   new OverloadSet.Local(ci.ast().getName(), name, 
     1020                                         ta, fs, i); 
     1021 
     1022               os.split(true); 
     1023                
     1024               String s = name.stringName(); 
     1025                
     1026               os.generateAnOverloadDefinition(s, cw); 
     1027                
     1028               for (Map.Entry<String, OverloadSet> o_entry : os.getOverloadSubsets().entrySet()) { 
     1029                   String ss = o_entry.getKey(); 
     1030                   ss = s + ss; 
     1031                   overloadedNamesAndSigs.add(ss); 
     1032               } 
     1033           } 
     1034        } 
     1035    } 
     1036 
     1037    Map<IdOrOpOrAnonymousName, MultiMap<Integer, Function>> 
     1038       sizePartitionedOverloads(Relation<IdOrOpOrAnonymousName, Function> fns) { 
     1039         
     1040        Map<IdOrOpOrAnonymousName, MultiMap<Integer, Function>> result =  
     1041            new HashMap<IdOrOpOrAnonymousName, MultiMap<Integer, Function>>(); 
     1042         
     1043        for (IdOrOpOrAnonymousName name : fns.firstSet()) { 
     1044            Set<Function> defs = fns.matchFirst(name); 
     1045            if (defs.size() <= 1) continue; 
     1046 
     1047            MultiMap<Integer, Function> partitionedByArgCount = 
     1048                new MultiMap<Integer, Function>(); 
     1049 
     1050            for (Function d : defs) { 
     1051                partitionedByArgCount.putItem(d.parameters().size(), d); 
     1052            } 
     1053             
     1054            for (Function d : defs) { 
     1055                Set<Function> sf = partitionedByArgCount.get(d.parameters().size()); 
     1056                if (sf != null && sf.size() <= 1) 
     1057                    partitionedByArgCount.remove(d.parameters().size()); 
     1058            } 
     1059            if (partitionedByArgCount.size() > 0) 
     1060                result.put(name, partitionedByArgCount); 
     1061        } 
     1062         
     1063        return result; 
     1064    } 
     1065 
     1066 
     1067 
     1068    private void dumpSigs(List<Decl> decls) { 
     1069        debug("dumpSigs", decls); 
     1070        for (Decl d : decls) { 
     1071            debug("dumpSigs decl =", d); 
     1072            if (!(d instanceof FnDecl)) { 
     1073                sayWhat(d); 
     1074                return; 
     1075            } 
     1076 
     1077            FnDecl f = (FnDecl) d; 
     1078            FnHeader h = f.getHeader(); 
     1079            IdOrOpOrAnonymousName xname = h.getName(); 
     1080            IdOrOp name = (IdOrOp) xname; 
     1081            String desc = Naming.generateTypeDescriptor(f); 
     1082            debug("about to call visitMethod with", name.getText(), 
     1083                  " and desc ", desc); 
     1084            mv = cw.visitMethod(Opcodes.ACC_ABSTRACT + Opcodes.ACC_PUBLIC, 
     1085                                NamingCzar.mangleIdentifier(name.getText()), desc, null, null); 
     1086            mv.visitMaxs(NamingCzar.ignore, NamingCzar.ignore); 
     1087            mv.visitEnd(); 
     1088        } 
     1089    } 
    10871090} 
     1091 
  • trunk/ProjectFortress/src/com/sun/fortress/compiler/phases/CodeGenerationPhase.java

    r3849 r3852  
    111111            Relation<IdOrOpOrAnonymousName, Function>  fns = ci.functions(); 
    112112            TypeAnalyzer ta = new TypeAnalyzer(new TraitTable(ci, getEnv())); 
     113             
     114            // Temporary code 
     115            ParallelismAnalyzer pa = new ParallelismAnalyzer(); 
     116            component.accept(pa); 
     117            pa.printTable(); 
    113118 
    114119            CodeGen c = new CodeGen(component, symbolTable, ta, ci);