Merged with bigRefactoring. Added method to generate signature to
FunN-Interfaces. Adapted jav-Files.
This commit is contained in:
parent
f6669f8c13
commit
b801e144c3
@ -842,6 +842,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
} else if(!helper.isInCurrPkg(clazz)){
|
} else if(!helper.isInCurrPkg(clazz)){
|
||||||
if(clazz.contains("$$")) {
|
if(clazz.contains("$$")) {
|
||||||
mDesc = helper.generateBCForFunN();
|
mDesc = helper.generateBCForFunN();
|
||||||
|
// mDesc = helper.generateBCForFunN(methCallType,typesOfParams);
|
||||||
}else {
|
}else {
|
||||||
try {
|
try {
|
||||||
cLoader2 = new URLClassLoader(new URL[] {new URL("file://"+path)});
|
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,
|
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, clazz.replace(".", "/"), methodCall.name,
|
||||||
mDesc, isInterface);
|
mDesc, isInterface);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: if called method is apply (from FI) then generate BC-instruction "CHECKCAST"
|
||||||
|
|
||||||
if(methodRefl != null && !methodRefl.getReturnType().isPrimitive()) {
|
if(methodRefl != null && !methodRefl.getReturnType().isPrimitive()) {
|
||||||
if(methodRefl.getReturnType().equals(Object.class)) {
|
if(methodRefl.getReturnType().equals(Object.class)) {
|
||||||
String checkCast = getResolvedType(methodCall.getType());
|
String checkCast = getResolvedType(methodCall.getType());
|
||||||
|
@ -84,6 +84,30 @@ public class Signature {
|
|||||||
sw = new SignatureWriter();
|
sw = new SignatureWriter();
|
||||||
createSignatureForFunN(numberOfParams);
|
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<numberOfParams;i++) {
|
||||||
|
int j = i+1;
|
||||||
|
sw.visitFormalTypeParameter("T"+ j);
|
||||||
|
// getBounds von Params
|
||||||
|
sw.visitClassBound().visitClassType(paramTypes[i]);
|
||||||
|
sw.visitClassBound().visitEnd();
|
||||||
|
}
|
||||||
|
|
||||||
|
sw.visitFormalTypeParameter("R");
|
||||||
|
// getBounds vom Return-Type
|
||||||
|
sw.visitClassBound().visitClassType(to);
|
||||||
|
sw.visitClassBound().visitEnd();
|
||||||
|
// TODO: prüfe ob Return-Type = void,
|
||||||
|
sw.visitSuperclass().visitClassType(Type.getInternalName(Object.class));;
|
||||||
|
sw.visitEnd();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private void createSignatureForFunN(int numberOfParams) {
|
private void createSignatureForFunN(int numberOfParams) {
|
||||||
|
|
||||||
|
@ -234,6 +234,37 @@ public class MethodCallHelper {
|
|||||||
writeClassFile(classWriter.toByteArray(), name);
|
writeClassFile(classWriter.toByteArray(), name);
|
||||||
return methDesc;
|
return methDesc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String generateBCForFunN(String returnType, String[] paramTypes) {
|
||||||
|
ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
|
||||||
|
|
||||||
|
SignatureWriter methSig = new SignatureWriter();
|
||||||
|
|
||||||
|
int numberOfParams = 0;
|
||||||
|
SignatureVisitor paramVisitor = methSig.visitParameterType();
|
||||||
|
Iterator<Expression> 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) {
|
private void writeClassFile(byte[] bytecode, String name) {
|
||||||
FileOutputStream output;
|
FileOutputStream output;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import java.lang.Integer;
|
import java.lang.Integer;
|
||||||
import java.lang.Long;
|
//import java.lang.Long;
|
||||||
import java.lang.Short;
|
//import java.lang.Short;
|
||||||
|
|
||||||
public class Faculty {
|
public class Faculty {
|
||||||
public fact;
|
public fact;
|
||||||
|
@ -7,17 +7,17 @@ public class Sorting{
|
|||||||
a.addAll(b);
|
a.addAll(b);
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
sort(in){
|
sort(in){
|
||||||
var firstHalf = in;
|
var firstHalf = in;
|
||||||
var secondHalf = in;
|
var secondHalf = in;
|
||||||
return merge(sort(firstHalf), sort(secondHalf));
|
return merge(sort(firstHalf), sort(secondHalf));
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
void sort(a){
|
void sort(a){
|
||||||
a = merge(a,a);
|
a = merge(a,a);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
@ -4,5 +4,12 @@ import java.util.Collection;
|
|||||||
class Sorting{
|
class Sorting{
|
||||||
void merge(a, b){
|
void merge(a, b){
|
||||||
a.addAll(b);
|
a.addAll(b);
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
|
sort(in){
|
||||||
|
var firstHalf = in;
|
||||||
|
var secondHalf = in;
|
||||||
|
return merge(sort(firstHalf), sort(secondHalf));
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user