diff --git a/src/main/java/de/dhbwstuttgart/bytecode/BytecodeGenMethod.java b/src/main/java/de/dhbwstuttgart/bytecode/BytecodeGenMethod.java index abf7237a..b7e6e6ea 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/BytecodeGenMethod.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/BytecodeGenMethod.java @@ -842,6 +842,7 @@ public class BytecodeGenMethod implements StatementVisitor { } else if(!helper.isInCurrPkg(clazz)){ if(clazz.contains("$$")) { mDesc = helper.generateBCForFunN(); +// mDesc = helper.generateBCForFunN(methCallType,typesOfParams); }else { try { cLoader2 = new URLClassLoader(new URL[] {new URL("file://"+path)}); @@ -902,7 +903,9 @@ public class BytecodeGenMethod implements StatementVisitor { mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, clazz.replace(".", "/"), methodCall.name, mDesc, isInterface); } - + + // TODO: if called method is apply (from FI) then generate BC-instruction "CHECKCAST" + if(methodRefl != null && !methodRefl.getReturnType().isPrimitive()) { if(methodRefl.getReturnType().equals(Object.class)) { String checkCast = getResolvedType(methodCall.getType()); diff --git a/src/main/java/de/dhbwstuttgart/bytecode/signature/Signature.java b/src/main/java/de/dhbwstuttgart/bytecode/signature/Signature.java index 62a55d12..fbbacdfa 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/signature/Signature.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/signature/Signature.java @@ -84,6 +84,30 @@ public class Signature { sw = new SignatureWriter(); createSignatureForFunN(numberOfParams); } + + public Signature(int numberOfParams, String to, String[] paramTypes) { + sw = new SignatureWriter(); + createSignatureForFunN(numberOfParams, to, paramTypes); + } + + private void createSignatureForFunN(int numberOfParams, String to, String[] paramTypes) { + for(int i = 0;i itr1 = methCall.arglist.getArguments().iterator(); + String methDesc = "("; + while(itr1.hasNext()) { + numberOfParams++; + // getBounds + paramVisitor.visitTypeVariable("T" + numberOfParams); + methDesc += "L" + paramTypes[numberOfParams-1] + ";"; + itr1.next(); + } + methDesc += ")L" + returnType + ";"; + + methSig.visitReturnType().visitTypeVariable("R"); + // ")"+lam.getReturn.getBounds + Signature sig = new Signature(numberOfParams,returnType,paramTypes); + String name = "Fun" + numberOfParams + "$$"; + classWriter.visit(Opcodes.V1_8, Opcodes.ACC_PUBLIC+Opcodes.ACC_INTERFACE + Opcodes.ACC_ABSTRACT, name, sig.toString(), + Type.getInternalName(Object.class), null); + MethodVisitor mvApply = classWriter.visitMethod(Opcodes.ACC_PUBLIC + Opcodes.ACC_ABSTRACT, "apply", methDesc, + methSig.toString(), null); + mvApply.visitEnd(); + writeClassFile(classWriter.toByteArray(), name); + return methDesc; + } private void writeClassFile(byte[] bytecode, String name) { FileOutputStream output; diff --git a/src/test/resources/bytecode/javFiles/Faculty.jav b/src/test/resources/bytecode/javFiles/Faculty.jav index 6d85bb05..6576b3da 100644 --- a/src/test/resources/bytecode/javFiles/Faculty.jav +++ b/src/test/resources/bytecode/javFiles/Faculty.jav @@ -1,6 +1,6 @@ import java.lang.Integer; -import java.lang.Long; -import java.lang.Short; +//import java.lang.Long; +//import java.lang.Short; public class Faculty { public fact; diff --git a/src/test/resources/bytecode/javFiles/Sorting.jav b/src/test/resources/bytecode/javFiles/Sorting.jav index 486bfd71..345819d7 100644 --- a/src/test/resources/bytecode/javFiles/Sorting.jav +++ b/src/test/resources/bytecode/javFiles/Sorting.jav @@ -7,17 +7,17 @@ public class Sorting{ a.addAll(b); return a; } -/* + sort(in){ var firstHalf = in; var secondHalf = in; return merge(sort(firstHalf), sort(secondHalf)); } -*/ - + + /* void sort(a){ a = merge(a,a); } - + */ } diff --git a/src/test/resources/javFiles/Sorting.jav b/src/test/resources/javFiles/Sorting.jav index 04ef23e5..e5897914 100644 --- a/src/test/resources/javFiles/Sorting.jav +++ b/src/test/resources/javFiles/Sorting.jav @@ -4,5 +4,12 @@ import java.util.Collection; class Sorting{ void merge(a, b){ a.addAll(b); + return a; + } + + sort(in){ + var firstHalf = in; + var secondHalf = in; + return merge(sort(firstHalf), sort(secondHalf)); } } \ No newline at end of file