forked from JavaTX/JavaCompilerCore
modified: src/de/dhbwstuttgart/core/JavaTXCompiler.java
modified: src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java modified: test/bytecode/MatrixTest.java src/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java
This commit is contained in:
parent
c43d9ab9f5
commit
421169a72d
@ -176,7 +176,7 @@ public class JavaTXCompiler {
|
|||||||
.collect(Collectors.toCollection(HashSet::new));
|
.collect(Collectors.toCollection(HashSet::new));
|
||||||
varianceInheritance(xConsSet);
|
varianceInheritance(xConsSet);
|
||||||
Set<Set<UnifyPair>> result = unify.unifySequential(xConsSet, finiteClosure, logFile, log);
|
Set<Set<UnifyPair>> result = unify.unifySequential(xConsSet, finiteClosure, logFile, log);
|
||||||
//Set<Set<UnifyPair>> result = unify.unify(xConsSet, finiteClosure);
|
//Set<Set<UnifyPair>> result = unify.unify(xConsSet, finiteClosure, logFile, log);
|
||||||
System.out.println("RESULT: " + result);
|
System.out.println("RESULT: " + result);
|
||||||
logFile.write("RES: " + result.toString()+"\n");
|
logFile.write("RES: " + result.toString()+"\n");
|
||||||
logFile.flush();
|
logFile.flush();
|
||||||
|
@ -49,6 +49,8 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
private static int i = 0;
|
private static int i = 0;
|
||||||
private boolean printtag = false;
|
private boolean printtag = false;
|
||||||
Boolean log = true; //gibt an ob ein Log-File nach System.getProperty("user.dir")+"/test/logFiles/log" geschrieben werden soll?
|
Boolean log = true; //gibt an ob ein Log-File nach System.getProperty("user.dir")+"/test/logFiles/log" geschrieben werden soll?
|
||||||
|
private static int noOfThread = 0;
|
||||||
|
private int thNo;
|
||||||
|
|
||||||
public static final String rootDirectory = System.getProperty("user.dir")+"/test/logFiles/";
|
public static final String rootDirectory = System.getProperty("user.dir")+"/test/logFiles/";
|
||||||
FileWriter logFile;
|
FileWriter logFile;
|
||||||
@ -96,6 +98,10 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
this.logFile = logFile;
|
this.logFile = logFile;
|
||||||
this.log = log;
|
this.log = log;
|
||||||
rules = new RuleSet(logFile);
|
rules = new RuleSet(logFile);
|
||||||
|
noOfThread++;
|
||||||
|
thNo = noOfThread;
|
||||||
|
//System.out.println(noOfThread);
|
||||||
|
//System.out.println(eq);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -451,9 +457,19 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
writeLog("nextSetasList: " + nextSetasList.toString());
|
writeLog("nextSetasList: " + nextSetasList.toString());
|
||||||
while (nextSetasList.size() > 0) { //(nextSetasList.size() != 0) {
|
while (nextSetasList.size() > 0) { //(nextSetasList.size() != 0) {
|
||||||
Set<UnifyPair> a = null;
|
Set<UnifyPair> a = null;
|
||||||
|
List<Set<UnifyPair>> nextSetasListRest= new ArrayList<>();
|
||||||
if (variance == 1) {
|
if (variance == 1) {
|
||||||
a = oup.max(nextSetasList.iterator());
|
a = oup.max(nextSetasList.iterator());
|
||||||
nextSetasList.remove(a);
|
//nextSetasList.remove(a);
|
||||||
|
nextSetasListRest = new ArrayList<>(nextSetasList);
|
||||||
|
Iterator<Set<UnifyPair>> nextSetasListItRest = new ArrayList<Set<UnifyPair>>(nextSetasListRest).iterator();
|
||||||
|
while (nextSetasListItRest.hasNext()) {
|
||||||
|
Set<UnifyPair> a_next = nextSetasListItRest.next();
|
||||||
|
if (//a.equals(a_next) ||
|
||||||
|
(oup.compare(a, a_next) == 1)) {
|
||||||
|
nextSetasListRest.remove(a_next);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (variance == -1) {
|
else if (variance == -1) {
|
||||||
a = oup.min(nextSetasList.iterator());
|
a = oup.min(nextSetasList.iterator());
|
||||||
@ -491,7 +507,21 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
elems.add(a);
|
elems.add(a);
|
||||||
//if (remainingSets.isEmpty()) {//muss immer gegeben sein, weil nur 1 Element der topLevelSets mehr als ein Elemet enthaelt
|
//if (remainingSets.isEmpty()) {//muss immer gegeben sein, weil nur 1 Element der topLevelSets mehr als ein Elemet enthaelt
|
||||||
//writeLog("Vor unify2 Aufruf: " + eq.toString());
|
//writeLog("Vor unify2 Aufruf: " + eq.toString());
|
||||||
Set<Set<UnifyPair>> res = unify2(elems, eq, fc, parallel);
|
Set<Set<UnifyPair>> res = new HashSet<>();
|
||||||
|
if(parallel) {
|
||||||
|
Set<TypeUnifyTask> forks = new HashSet<>();
|
||||||
|
for(Set<UnifyPair> nSaL : nextSetasListRest) {
|
||||||
|
TypeUnify2Task fork = new TypeUnify2Task(elems, eq, fc, true, logFile, log);
|
||||||
|
forks.add(fork);
|
||||||
|
fork.fork();
|
||||||
|
}
|
||||||
|
for(TypeUnifyTask fork : forks) {
|
||||||
|
res.addAll(fork.join());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
res = unify2(elems, eq, fc, parallel);
|
||||||
|
}
|
||||||
if (!isUndefinedPairSetSet(res) && isUndefinedPairSetSet(result)) {
|
if (!isUndefinedPairSetSet(res) && isUndefinedPairSetSet(result)) {
|
||||||
//wenn korrektes Ergebnis gefunden alle Fehlerfaelle loeschen
|
//wenn korrektes Ergebnis gefunden alle Fehlerfaelle loeschen
|
||||||
result = res;
|
result = res;
|
||||||
@ -522,6 +552,9 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
System.out.print("");
|
System.out.print("");
|
||||||
Iterator<Set<UnifyPair>> nextSetasListIt = new ArrayList<Set<UnifyPair>>(nextSetasList).iterator();
|
Iterator<Set<UnifyPair>> nextSetasListIt = new ArrayList<Set<UnifyPair>>(nextSetasList).iterator();
|
||||||
if (variance == 1) {
|
if (variance == 1) {
|
||||||
|
/* nextSetasList = nextSetasListRest; */
|
||||||
|
/* wird bereits vor den unify2-Aufruf durchgefuehrt und nextSetasListRest zugeordnet
|
||||||
|
*/
|
||||||
System.out.println("");
|
System.out.println("");
|
||||||
while (nextSetasListIt.hasNext()) {
|
while (nextSetasListIt.hasNext()) {
|
||||||
Set<UnifyPair> a_next = nextSetasListIt.next();
|
Set<UnifyPair> a_next = nextSetasListIt.next();
|
||||||
@ -530,6 +563,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
nextSetasList.remove(a_next);
|
nextSetasList.remove(a_next);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else { if (variance == -1) {
|
else { if (variance == -1) {
|
||||||
System.out.println("");
|
System.out.println("");
|
||||||
@ -1242,6 +1276,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
void writeLog(String str) {
|
void writeLog(String str) {
|
||||||
if (log) {
|
if (log) {
|
||||||
try {
|
try {
|
||||||
|
logFile.write("Thread no.:" + thNo + "\n");
|
||||||
logFile.write(str+"\n");
|
logFile.write(str+"\n");
|
||||||
logFile.flush();
|
logFile.flush();
|
||||||
|
|
||||||
|
@ -36,55 +36,57 @@ public class MatrixTest {
|
|||||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||||
classToTest = loader.loadClass("Matrix");
|
classToTest = loader.loadClass("Matrix");
|
||||||
|
|
||||||
Vector<Vector<Integer>> vv = new Vector<Vector<Integer>>();
|
instanceOfClass_m1 = classToTest.getDeclaredConstructor().newInstance(); //Matrix m1 = new Matrix();
|
||||||
Vector<Integer> v1 = new Vector<Integer> ();
|
//Vector<Vector<Integer>> vv = new Vector<Vector<Integer>>();
|
||||||
v1.addElement(2);
|
Vector<Integer> v1 = new Vector<Integer> ();
|
||||||
v1.addElement(2);
|
v1.addElement(2);
|
||||||
Vector<Integer> v2 = new Vector<Integer> ();
|
v1.addElement(2);
|
||||||
v2.addElement(3);
|
Vector<Integer> v2 = new Vector<Integer> ();
|
||||||
v2.addElement(3);
|
v2.addElement(3);
|
||||||
//Matrix m1 = new Matrix();
|
v2.addElement(3);
|
||||||
//m1.addElement(v1);
|
//Method[] ms = classToTest.getSuperclass().getDeclaredMethods();
|
||||||
//m1.addElement(v2);
|
Method addElement = classToTest.getSuperclass().getDeclaredMethod("addElement", Object.class);
|
||||||
vv.addElement(v1);
|
addElement.invoke(instanceOfClass_m1, v1); //m1.addElement(v1);
|
||||||
vv.addElement(v2);
|
addElement.invoke(instanceOfClass_m1, v2); //m1.addElement(v2);
|
||||||
instanceOfClass_m1 = classToTest.getDeclaredConstructor(Vector.class).newInstance(vv); //Matrix m1 = new Matrix(vv);
|
//vv.addElement(v1);
|
||||||
|
//vv.addElement(v2);
|
||||||
|
//instanceOfClass_m1 = classToTest.getDeclaredConstructor(Vector.class).newInstance(vv); //Matrix m1 = new Matrix(vv);
|
||||||
|
|
||||||
Vector<Vector<Integer>> vv1 = new Vector<Vector<Integer>>();
|
Vector<Vector<Integer>> vv1 = new Vector<Vector<Integer>>();
|
||||||
Vector<Integer> v3 = new Vector<Integer> ();
|
Vector<Integer> v3 = new Vector<Integer> ();
|
||||||
v3.addElement(2);
|
v3.addElement(2);
|
||||||
v3.addElement(2);
|
v3.addElement(2);
|
||||||
Vector<Integer> v4 = new Vector<Integer> ();
|
Vector<Integer> v4 = new Vector<Integer> ();
|
||||||
v4.addElement(3);
|
v4.addElement(3);
|
||||||
v4.addElement(3);
|
v4.addElement(3);
|
||||||
//Matrix m2 = new Matrix();
|
//Matrix m2 = new Matrix();
|
||||||
//m2.addElement(v3);
|
//m2.addElement(v3);
|
||||||
//m2.addElement(v4);
|
//m2.addElement(v4);
|
||||||
vv1.addElement(v3);
|
vv1.addElement(v3);
|
||||||
vv1.addElement(v4);
|
vv1.addElement(v4);
|
||||||
instanceOfClass_m2 = classToTest.getDeclaredConstructor(Vector.class).newInstance(vv1);//Matrix m2 = new Matrix(vv1);
|
instanceOfClass_m2 = classToTest.getDeclaredConstructor(Vector.class).newInstance(vv1);//Matrix m2 = new Matrix(vv1);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//Matrix m3 = m1.mul(vv1);
|
//Matrix m3 = m1.mul(vv1);
|
||||||
Method mul = classToTest.getDeclaredMethod("mul", Vector.class);
|
Method mul = classToTest.getDeclaredMethod("mul", Vector.class);
|
||||||
Object result = mul.invoke(instanceOfClass_m1, instanceOfClass_m2);
|
Object result = mul.invoke(instanceOfClass_m1, instanceOfClass_m2);
|
||||||
System.out.println(instanceOfClass_m1.toString() + " * " + instanceOfClass_m1.toString() + " = " + result.toString());
|
System.out.println(instanceOfClass_m1.toString() + " * " + instanceOfClass_m1.toString() + " = " + result.toString());
|
||||||
|
|
||||||
Vector<Vector<Integer>> res = new Vector<Vector<Integer>>();
|
Vector<Vector<Integer>> res = new Vector<Vector<Integer>>();
|
||||||
Vector<Integer> v5 = new Vector<Integer> ();
|
Vector<Integer> v5 = new Vector<Integer> ();
|
||||||
v5.addElement(10);
|
v5.addElement(10);
|
||||||
v5.addElement(10);
|
v5.addElement(10);
|
||||||
Vector<Integer> v6 = new Vector<Integer> ();
|
Vector<Integer> v6 = new Vector<Integer> ();
|
||||||
v6.addElement(15);
|
v6.addElement(15);
|
||||||
v6.addElement(15);
|
v6.addElement(15);
|
||||||
//Matrix m2 = new Matrix();
|
//Matrix m2 = new Matrix();
|
||||||
//m2.addElement(v3);
|
//m2.addElement(v3);
|
||||||
//m2.addElement(v4);
|
//m2.addElement(v4);
|
||||||
res.addElement(v5);
|
res.addElement(v5);
|
||||||
res.addElement(v6);
|
res.addElement(v6);
|
||||||
instanceOfClass_m3 = classToTest.getDeclaredConstructor(Vector.class).newInstance(res);
|
instanceOfClass_m3 = classToTest.getDeclaredConstructor(Vector.class).newInstance(res);
|
||||||
assertEquals(result, instanceOfClass_m3);
|
assertEquals(result, instanceOfClass_m3);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user