Backend support for function expression

This commit is contained in:
Stanislav Erokhin
2015-02-05 21:27:52 +03:00
parent 44895a23cf
commit a89b48c577
10 changed files with 159 additions and 25 deletions
@@ -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();
}