Backend support for function expression
This commit is contained in:
@@ -41,6 +41,11 @@ public class CodegenStatementVisitor extends JetVisitor<StackValue, StackValue>
|
||||
return codegen.generateTryExpression(expression, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public StackValue visitNamedFunction(@NotNull JetNamedFunction function, StackValue data) {
|
||||
return codegen.visitNamedFunction(function, data, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public StackValue visitWhenExpression(@NotNull JetWhenExpression expression, StackValue data) {
|
||||
return codegen.generateWhenExpression(expression, true);
|
||||
|
||||
@@ -1346,6 +1346,10 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
||||
|
||||
@Override
|
||||
public StackValue visitNamedFunction(@NotNull JetNamedFunction function, StackValue data) {
|
||||
return visitNamedFunction(function, data, false);
|
||||
}
|
||||
|
||||
public StackValue visitNamedFunction(@NotNull JetNamedFunction function, StackValue data, boolean isStatement) {
|
||||
assert data == StackValue.none();
|
||||
|
||||
if (JetPsiUtil.isScriptDeclaration(function)) {
|
||||
@@ -1353,11 +1357,16 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
||||
}
|
||||
|
||||
StackValue closure = genClosure(function, null, KotlinSyntheticClass.Kind.LOCAL_FUNCTION);
|
||||
DeclarationDescriptor descriptor = bindingContext.get(DECLARATION_TO_DESCRIPTOR, function);
|
||||
int index = lookupLocalIndex(descriptor);
|
||||
closure.put(OBJECT_TYPE, v);
|
||||
v.store(index, OBJECT_TYPE);
|
||||
return StackValue.none();
|
||||
if (isStatement) {
|
||||
DeclarationDescriptor descriptor = bindingContext.get(DECLARATION_TO_DESCRIPTOR, function);
|
||||
int index = lookupLocalIndex(descriptor);
|
||||
closure.put(OBJECT_TYPE, v);
|
||||
v.store(index, OBJECT_TYPE);
|
||||
return StackValue.none();
|
||||
}
|
||||
else {
|
||||
return closure;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -621,9 +621,6 @@ public class JetTypeMapper {
|
||||
|
||||
return isAccessor ? "access$" + accessorName : accessorName;
|
||||
}
|
||||
else if (isLocalNamedFun(descriptor)) {
|
||||
return "invoke";
|
||||
}
|
||||
else if (descriptor instanceof AnonymousFunctionDescriptor) {
|
||||
PsiElement element = DescriptorToSourceUtils.getSourceFromDescriptor(descriptor);
|
||||
if (element instanceof JetFunctionLiteral) {
|
||||
@@ -638,6 +635,9 @@ public class JetTypeMapper {
|
||||
|
||||
return "invoke";
|
||||
}
|
||||
else if (isLocalFunOrLambda(descriptor)) {
|
||||
return "invoke";
|
||||
}
|
||||
else {
|
||||
return descriptor.getName().asString();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user