Example #1
0
 private void putClosureParametersOnStack() {
   for (LambdaInfo next : expressionMap.values()) {
     activeLambda = next;
     codegen.pushClosureOnStack(next.getClassDescriptor(), true, this);
   }
   activeLambda = null;
 }
Example #2
0
  private SMAPAndMethodNode generateLambdaBody(LambdaInfo info) {
    JetExpression declaration = info.getFunctionWithBodyOrCallableReference();
    FunctionDescriptor descriptor = info.getFunctionDescriptor();

    MethodContext parentContext = codegen.getContext();

    MethodContext context =
        parentContext.intoClosure(descriptor, codegen, typeMapper).intoInlinedLambda(descriptor);

    JvmMethodSignature jvmMethodSignature = typeMapper.mapSignature(descriptor);
    Method asmMethod = jvmMethodSignature.getAsmMethod();
    MethodNode methodNode =
        new MethodNode(
            InlineCodegenUtil.API,
            getMethodAsmFlags(descriptor, context.getContextKind()),
            asmMethod.getName(),
            asmMethod.getDescriptor(),
            jvmMethodSignature.getGenericsSignature(),
            null);

    MethodVisitor adapter = InlineCodegenUtil.wrapWithMaxLocalCalc(methodNode);

    SMAP smap =
        generateMethodBody(adapter, descriptor, context, declaration, jvmMethodSignature, true);
    adapter.visitMaxs(-1, -1);
    return new SMAPAndMethodNode(methodNode, smap);
  }
Example #3
0
  private void putCapturedInLocal(
      @NotNull Type type,
      @Nullable StackValue stackValue,
      @Nullable ValueParameterDescriptor valueParameterDescriptor,
      int capturedParamIndex) {
    if (!asFunctionInline && Type.VOID_TYPE != type) {
      // TODO remap only inlinable closure => otherwise we could get a lot of problem
      boolean couldBeRemapped = !shouldPutValue(type, stackValue, valueParameterDescriptor);
      StackValue remappedIndex = couldBeRemapped ? stackValue : null;

      ParameterInfo info;
      if (capturedParamIndex >= 0) {
        CapturedParamDesc capturedParamInfoInLambda =
            activeLambda.getCapturedVars().get(capturedParamIndex);
        info =
            invocationParamBuilder.addCapturedParam(
                capturedParamInfoInLambda, capturedParamInfoInLambda.getFieldName());
        info.setRemapValue(remappedIndex);
      } else {
        info = invocationParamBuilder.addNextParameter(type, false, remappedIndex);
      }

      putParameterOnStack(info);
    }
  }
Example #4
0
 private void generateClosuresBodies() {
   for (LambdaInfo info : expressionMap.values()) {
     info.setNode(generateLambdaBody(info));
   }
 }