public void compile(ApplyExp applyexp, Compilation compilation, Target target) {
    Expression aexpression[] = applyexp.getArgs();
    CodeAttr codeattr = compilation.getCode();
    codeattr.pushScope();
    gnu.bytecode.Variable variable = codeattr.addLocal(Type.pointer_type);
    aexpression[0].compile(compilation, Target.pushObject);
    codeattr.emitStore(variable);
    for (int i = 1; i < aexpression.length; ) {
      if (i > 1) {
        codeattr.emitElse();
      }
      int k = i + 1;
      applyexp = aexpression[i];
      if (applyexp instanceof LambdaExp) {
        LambdaExp lambdaexp = (LambdaExp) applyexp;
        applyexp = lambdaexp.firstDecl();
        Type type = applyexp.getType();
        if (!applyexp.getCanRead()) {
          applyexp = null;
        } else {
          applyexp.allocateVariable(codeattr);
        }
        if (type instanceof TypeValue) {
          ((TypeValue) type).emitTestIf(variable, applyexp, compilation);
        } else {
          if (k < aexpression.length) {
            codeattr.emitLoad(variable);
            type.emitIsInstance(codeattr);
            codeattr.emitIfIntNotZero();
          }
          if (applyexp != null) {
            codeattr.emitLoad(variable);
            applyexp.compileStore(compilation);
          }
        }
        lambdaexp.allocChildClasses(compilation);
        lambdaexp.body.compileWithPosition(compilation, target);
        i = k;
      } else {
        throw new Error("not implemented: typeswitch arg not LambdaExp");
      }
    }

    int j = aexpression.length - 2;
    do {
      j--;
      if (j >= 0) {
        codeattr.emitFi();
      } else {
        codeattr.popScope();
        return;
      }
    } while (true);
  }
Example #2
0
 // Recursive helper function.
 private static void popParams(
     CodeAttr code, int paramNo, int count, int[] incValues, Declaration decl, Variable vars) {
   if (count > 0) {
     count--;
     popParams(
         code,
         paramNo + 1,
         count,
         incValues,
         decl.nextDecl(),
         decl.getVariable() == null ? vars : vars.nextVar());
     if (!decl.ignorable()) {
       if (incValues != null && incValues[paramNo] != SetExp.BAD_SHORT)
         code.emitInc(vars, (short) incValues[paramNo]);
       else code.emitStore(vars);
     }
   }
 }
 public static void emitLoadModuleMethod(LambdaExp paramLambdaExp, Compilation paramCompilation)
 {
   Object localObject3 = paramLambdaExp.nameDecl;
   Object localObject1;
   CodeAttr localCodeAttr;
   Object localObject2;
   label61:
   label129:
   label150:
   label178:
   int i;
   if (localObject3 == null)
   {
     localObject1 = paramLambdaExp.getName();
     localCodeAttr = null;
     localObject2 = localCodeAttr;
     if (paramCompilation.immediate)
     {
       localObject2 = localCodeAttr;
       if (localObject1 != null)
       {
         localObject2 = localCodeAttr;
         if (localObject3 != null)
         {
           localObject3 = Environment.getCurrent();
           if (!(localObject1 instanceof Symbol)) {
             break label353;
           }
           localObject2 = (Symbol)localObject1;
           localObject3 = ((Environment)localObject3).get((Symbol)localObject2, paramCompilation.getLanguage().getEnvPropertyFor(paramLambdaExp.nameDecl), null);
           localObject2 = localCodeAttr;
           if ((localObject3 instanceof ModuleMethod)) {
             localObject2 = (ModuleMethod)localObject3;
           }
         }
       }
     }
     localCodeAttr = paramCompilation.getCode();
     localObject3 = Compilation.typeModuleMethod;
     if (localObject2 != null) {
       break label369;
     }
     localCodeAttr.emitNew((ClassType)localObject3);
     localCodeAttr.emitDup(1);
     localObject2 = "<init>";
     localObject3 = ((ClassType)localObject3).getDeclaredMethod((String)localObject2, 4);
     if (!paramLambdaExp.getNeedsClosureEnv()) {
       break label385;
     }
     localObject2 = paramLambdaExp.getOwningLambda();
     if ((!(localObject2 instanceof ClassExp)) || (((LambdaExp)localObject2).staticLinkField == null)) {
       break label393;
     }
     localCodeAttr.emitLoad(localCodeAttr.getCurrentScope().getVariable(1));
     localCodeAttr.emitPushInt(paramLambdaExp.getSelectorValue(paramCompilation));
     paramCompilation.compileConstant(localObject1, Target.pushObject);
     int j = paramLambdaExp.min_args;
     if (paramLambdaExp.keywords != null) {
       break label583;
     }
     i = paramLambdaExp.max_args;
     label215:
     localCodeAttr.emitPushInt(i << 12 | j);
     localCodeAttr.emitInvoke((Method)localObject3);
     if (paramLambdaExp.properties == null) {
       return;
     }
     j = paramLambdaExp.properties.length;
     i = 0;
     label252:
     if (i >= j) {
       return;
     }
     localObject2 = paramLambdaExp.properties[i];
     if ((localObject2 != null) && (localObject2 != PropertySet.nameKey))
     {
       localObject1 = paramLambdaExp.properties[(i + 1)];
       localCodeAttr.emitDup(1);
       paramCompilation.compileConstant(localObject2);
       localObject2 = Target.pushObject;
       if (!(localObject1 instanceof Expression)) {
         break label589;
       }
       ((Expression)localObject1).compile(paramCompilation, (Target)localObject2);
     }
   }
   for (;;)
   {
     localCodeAttr.emitInvokeVirtual(ClassType.make("gnu.mapping.PropertySet").getDeclaredMethod("setProperty", 2));
     i += 2;
     break label252;
     localObject1 = ((Declaration)localObject3).getSymbol();
     break;
     label353:
     localObject2 = Symbol.make("", localObject1.toString().intern());
     break label61;
     label369:
     paramCompilation.compileConstant(localObject2, Target.pushValue((Type)localObject3));
     localObject2 = "init";
     break label129;
     label385:
     localObject2 = paramCompilation.getModule();
     break label150;
     label393:
     if ((!(localObject2 instanceof ModuleExp)) || ((paramCompilation.moduleClass == paramCompilation.mainClass) && (!paramCompilation.method.getStaticFlag())))
     {
       localCodeAttr.emitPushThis();
       break label178;
     }
     if (paramCompilation.moduleInstanceVar == null)
     {
       paramCompilation.moduleInstanceVar = localCodeAttr.locals.current_scope.addVariable(localCodeAttr, paramCompilation.moduleClass, "$instance");
       if ((paramCompilation.moduleClass == paramCompilation.mainClass) || (paramCompilation.isStatic())) {
         break label571;
       }
       localCodeAttr.emitNew(paramCompilation.moduleClass);
       localCodeAttr.emitDup(paramCompilation.moduleClass);
       localCodeAttr.emitInvokeSpecial(paramCompilation.moduleClass.constructor);
       paramCompilation.moduleInstanceMainField = paramCompilation.moduleClass.addField("$main", paramCompilation.mainClass, 0);
       localCodeAttr.emitDup(paramCompilation.moduleClass);
       localCodeAttr.emitPushThis();
       localCodeAttr.emitPutField(paramCompilation.moduleInstanceMainField);
     }
     for (;;)
     {
       localCodeAttr.emitStore(paramCompilation.moduleInstanceVar);
       localCodeAttr.emitLoad(paramCompilation.moduleInstanceVar);
       break;
       label571:
       localCodeAttr.emitGetStatic(paramCompilation.moduleInstanceMainField);
     }
     label583:
     i = -1;
     break label215;
     label589:
     paramCompilation.compileConstant(localObject1, (Target)localObject2);
   }
 }