modified: ../../src/de/dhbwstuttgart/core/JavaTXCompiler.java

modified:   ../../src/de/dhbwstuttgart/typeinference/unify/TypeUnify.java
	modified:   ../../src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java
compare(Matrix, Vector<gen_ab>, ? extends Vector<? extends Integer>> <.? gen_ab
funktioniert nicht
This commit is contained in:
Martin Plümicke 2018-03-10 01:04:19 +01:00
parent b5b5b5d9c9
commit 0315a1f144
3 changed files with 37 additions and 27 deletions

View File

@ -18,11 +18,13 @@ import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
import de.dhbwstuttgart.typeinference.constraints.Pair; import de.dhbwstuttgart.typeinference.constraints.Pair;
import de.dhbwstuttgart.typeinference.result.ResultSet; import de.dhbwstuttgart.typeinference.result.ResultSet;
import de.dhbwstuttgart.typeinference.typeAlgo.TYPE; import de.dhbwstuttgart.typeinference.typeAlgo.TYPE;
import de.dhbwstuttgart.typeinference.unify.RuleSet;
import de.dhbwstuttgart.typeinference.unify.TypeUnify; import de.dhbwstuttgart.typeinference.unify.TypeUnify;
import de.dhbwstuttgart.typeinference.unify.model.FiniteClosure; import de.dhbwstuttgart.typeinference.unify.model.FiniteClosure;
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair; import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
import java.io.File; import java.io.File;
import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -94,21 +96,28 @@ public class JavaTXCompiler {
TypeUnify unify = new TypeUnify(); TypeUnify unify = new TypeUnify();
Set<Set<UnifyPair>> results = new HashSet<>(); Set<Set<UnifyPair>> results = new HashSet<>();
for (List<Constraint<UnifyPair>> xCons : unifyCons.cartesianProduct()) { try {
Set<UnifyPair> xConsSet = new HashSet<>(); FileWriter logFile = new FileWriter(new File(System.getProperty("user.dir")+"/test/logFiles/"+"log"));
for (Constraint<UnifyPair> constraint : xCons) { for (List<Constraint<UnifyPair>> xCons : unifyCons.cartesianProduct()) {
xConsSet.addAll(constraint); Set<UnifyPair> xConsSet = new HashSet<>();
} for (Constraint<UnifyPair> constraint : xCons) {
xConsSet.addAll(constraint);
}
System.out.println(xConsSet); System.out.println(xConsSet);
Set<Set<UnifyPair>> result = unify.unifySequential(xConsSet, finiteClosure); Set<Set<UnifyPair>> result = unify.unifySequential(xConsSet, finiteClosure, logFile);
//Set<Set<UnifyPair>> result = unify.unify(xConsSet, finiteClosure); //Set<Set<UnifyPair>> result = unify.unify(xConsSet, finiteClosure);
System.out.println("RESULT: " + result); System.out.println("RESULT: " + result);
results.addAll(result); logFile.write("RES: " + result.toString()+"\n");
logFile.flush();
results.addAll(result);
}
}
catch (IOException e) { }
return results.stream().map((unifyPairs ->
new ResultSet(UnifyTypeFactory.convert(unifyPairs, generateTPHMap(cons))))).collect(Collectors.toList());
} }
return results.stream().map((unifyPairs ->
new ResultSet(UnifyTypeFactory.convert(unifyPairs, generateTPHMap(cons))))).collect(Collectors.toList());
}
private Map<String, TypePlaceholder> generateTPHMap(ConstraintSet<Pair> constraints) { private Map<String, TypePlaceholder> generateTPHMap(ConstraintSet<Pair> constraints) {
HashMap<String, TypePlaceholder> ret = new HashMap<>(); HashMap<String, TypePlaceholder> ret = new HashMap<>();

View File

@ -1,5 +1,6 @@
package de.dhbwstuttgart.typeinference.unify; package de.dhbwstuttgart.typeinference.unify;
import java.io.FileWriter;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ForkJoinPool; import java.util.concurrent.ForkJoinPool;
@ -7,16 +8,16 @@ import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair; import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
public class TypeUnify { public class TypeUnify {
public Set<Set<UnifyPair>> unify(Set<UnifyPair> eq, IFiniteClosure fc) { public Set<Set<UnifyPair>> unify(Set<UnifyPair> eq, IFiniteClosure fc, FileWriter logFile) {
TypeUnifyTask unifyTask = new TypeUnifyTask(eq, fc, true); TypeUnifyTask unifyTask = new TypeUnifyTask(eq, fc, true, logFile);
ForkJoinPool pool = new ForkJoinPool(); ForkJoinPool pool = new ForkJoinPool();
pool.invoke(unifyTask); pool.invoke(unifyTask);
Set<Set<UnifyPair>> res = unifyTask.join(); Set<Set<UnifyPair>> res = unifyTask.join();
return res; return res;
} }
public Set<Set<UnifyPair>> unifySequential(Set<UnifyPair> eq, IFiniteClosure fc) { public Set<Set<UnifyPair>> unifySequential(Set<UnifyPair> eq, IFiniteClosure fc, FileWriter logFile) {
TypeUnifyTask unifyTask = new TypeUnifyTask(eq, fc, false); TypeUnifyTask unifyTask = new TypeUnifyTask(eq, fc, false, logFile);
Set<Set<UnifyPair>> res = unifyTask.compute(); Set<Set<UnifyPair>> res = unifyTask.compute();
return res; return res;
} }

View File

@ -75,18 +75,13 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
rules = new RuleSet(); rules = new RuleSet();
} }
public TypeUnifyTask(Set<UnifyPair> eq, IFiniteClosure fc, boolean parallel) { public TypeUnifyTask(Set<UnifyPair> eq, IFiniteClosure fc, boolean parallel, FileWriter logFile) {
this.eq = eq; this.eq = eq;
this.fc = fc; this.fc = fc;
this.oup = new OrderingUnifyPair(fc); this.oup = new OrderingUnifyPair(fc);
this.parallel = parallel; this.parallel = parallel;
try { this.logFile = logFile;
logFile = new FileWriter(new File(rootDirectory+"log")); rules = new RuleSet(logFile);
logFile.write("xxx");
logFile.flush();
rules = new RuleSet(logFile);
}
catch (IOException e) { }
} }
@Override @Override
@ -105,6 +100,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
* Step 1: Repeated application of reduce, adapt, erase, swap * Step 1: Repeated application of reduce, adapt, erase, swap
*/ */
writeLog("Unifikation: " + eq.toString()); writeLog("Unifikation: " + eq.toString());
eq = eq.stream().map(x -> {x.setVariance((byte)-1); return x;}).collect(Collectors.toCollection(HashSet::new));
Set<UnifyPair> eq0 = applyTypeUnificationRules(eq, fc); Set<UnifyPair> eq0 = applyTypeUnificationRules(eq, fc);
/* /*
@ -245,13 +241,13 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
eqPrimePrimeSet.add(eqPrime); eqPrimePrimeSet.add(eqPrime);
else if(eqPrimePrime.isPresent()) { else if(eqPrimePrime.isPresent()) {
//System.out.println("nextStep: " + eqPrimePrime.get()); //System.out.println("nextStep: " + eqPrimePrime.get());
TypeUnifyTask fork = new TypeUnifyTask(eqPrimePrime.get(), fc, true); TypeUnifyTask fork = new TypeUnifyTask(eqPrimePrime.get(), fc, true, logFile);
forks.add(fork); forks.add(fork);
fork.fork(); fork.fork();
} }
else { else {
//System.out.println("nextStep: " + eqPrime); //System.out.println("nextStep: " + eqPrime);
TypeUnifyTask fork = new TypeUnifyTask(eqPrime, fc, true); TypeUnifyTask fork = new TypeUnifyTask(eqPrime, fc, true, logFile);
forks.add(fork); forks.add(fork);
fork.fork(); fork.fork();
} }
@ -314,6 +310,8 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
int i = 0; int i = 0;
byte variance = nextSetasList.iterator().next().iterator().next().getVariance(); byte variance = nextSetasList.iterator().next().iterator().next().getVariance();
Set<UnifyPair> a_next = null; Set<UnifyPair> a_next = null;
if (nextSetasList.iterator().next().iterator().next().getLhsType().getName().equals("A"))
System.out.print("");
if (nextSetasList.size()>1) { if (nextSetasList.size()>1) {
if (variance == 1) { if (variance == 1) {
a_next = oup.max(nextSetasList.iterator()); a_next = oup.max(nextSetasList.iterator());
@ -373,6 +371,8 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
} }
} }
else { if (variance == -1) { else { if (variance == -1) {
if (a.iterator().next().getLhsType().getName().equals("A"))
System.out.print("");
if (a.equals(a_next) || (oup.compare(a, a_next) == -1)) { if (a.equals(a_next) || (oup.compare(a, a_next) == -1)) {
System.out.print(""); System.out.print("");
break; break;