Closure and boxing return value

This commit is contained in:
Maxim Shafirov
2011-06-22 21:26:01 +04:00
parent 3619e411a7
commit 90038fda02
4 changed files with 18 additions and 1 deletions
@@ -104,6 +104,7 @@ public class ClosureCodegen {
private void generateBridge(String className, FunctionDescriptor funDescriptor, ClassVisitor cv) {
final Method bridge = erasedInvokeSignature(funDescriptor);
final Method delegate = invokeSignature(funDescriptor);
final MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC, "invoke", bridge.getDescriptor(), typeMapper.genericSignature(funDescriptor), new String[0]);
mv.visitCode();
@@ -120,7 +121,9 @@ public class ClosureCodegen {
count++;
}
iv.invokespecial(className, "invoke", invokeSignature(funDescriptor).getDescriptor());
iv.invokespecial(className, "invoke", delegate.getDescriptor());
StackValue.onStack(delegate.getReturnType()).put(JetTypeMapper.TYPE_OBJECT, iv);
iv.areturn(JetTypeMapper.TYPE_OBJECT);
mv.visitMaxs(0, 0);
@@ -140,6 +140,9 @@ public abstract class StackValue {
box(this.type, type, v);
}
else if (this.type.getSort() == Type.OBJECT && type.getSort() <= Type.DOUBLE) {
if (this.type.equals(JetTypeMapper.TYPE_OBJECT)) {
v.checkcast(Type.getObjectType("java/lang/Number"));
}
unbox(type, v);
}
else {
@@ -0,0 +1,7 @@
fun box() : String {
return if (int_invoker( { 7 } ) == 7) "OK" else "fail"
}
fun int_invoker(gen : {() : Int}) : Int {
return gen()
}
@@ -7,4 +7,8 @@ public class ClosuresGenTest extends CodegenTestCase {
public void testSimplestClosure() throws Exception {
blackBoxFile("classes/simplestClosure.jet");
}
public void testSimplestClosureAndBoxing() throws Exception {
blackBoxFile("classes/simplestClosureAndBoxing.jet");
}
}