Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3b0c419a1a | ||
|
|
67d9be8878 | ||
|
|
e1b9766a53 | ||
|
|
272d9fa586 | ||
|
|
32a01c500a |
No files matched your search
@@ -13,15 +13,15 @@ public sealed interface LazyList permits Empty, Cons {
|
|||||||
public Integer fst();
|
public Integer fst();
|
||||||
public LazyList rest();
|
public LazyList rest();
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
public class Filter {
|
public class Filter {
|
||||||
/*public LazyList filter(Fun1$$<Integer, Boolean> p, LazyList l) {
|
public LazyList filter(Fun1$$<Integer, Boolean> p, LazyList l) {
|
||||||
return switch(l) {
|
return switch(l) {
|
||||||
case Empty e -> e;
|
case Empty e -> e;
|
||||||
case Cons(Integer x, Supplier<LazyList> l1) ->
|
case Cons(Integer x, Supplier<LazyList> l1) ->
|
||||||
p.apply(x) ? new Cons(x, () -> filter(p, l1.get())) : filter(p, l1.get());
|
p.apply(x) ? new Cons(x, () -> filter(p, l1.get())) : filter(p, l1.get());
|
||||||
};
|
};
|
||||||
}*/
|
}
|
||||||
public LazyList filter(Fun1$$<Integer, Boolean> p, Empty()@l) {
|
public LazyList filter(Fun1$$<Integer, Boolean> p, Empty()@l) {
|
||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
@@ -31,6 +31,8 @@ public class Filter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
//Der Konstruktor Cons muss lazy sein, deshalb hier Supplier<...>
|
//Der Konstruktor Cons muss lazy sein, deshalb hier Supplier<...>
|
||||||
record Cons(Integer x, Fun0$$<LazyList> l) implements LazyList {
|
record Cons(Integer x, Fun0$$<LazyList> l) implements LazyList {
|
||||||
public Integer fst() { return this.x; }
|
public Integer fst() { return this.x; }
|
||||||
@@ -45,7 +47,7 @@ record Empty() implements LazyList {
|
|||||||
public LazyList rest() { return null; }
|
public LazyList rest() { return null; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
class Main {
|
class Main {
|
||||||
static LazyList Count(int i) { return new Cons(i, () -> Count(i+1)); }
|
static LazyList Count(int i) { return new Cons(i, () -> Count(i+1)); }
|
||||||
|
|
||||||
@@ -54,3 +56,4 @@ class Main {
|
|||||||
System.out.println(Count(1).rest().fst());
|
System.out.println(Count(1).rest().fst());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
@@ -7,9 +7,10 @@ import java.io.PrintStream;
|
|||||||
import LazyList;
|
import LazyList;
|
||||||
import Cons;
|
import Cons;
|
||||||
import Empty;
|
import Empty;
|
||||||
import Filter;
|
//import Filter;
|
||||||
|
|
||||||
public class Primzahlen {
|
public class Primzahlen {
|
||||||
|
/*
|
||||||
static LazyList from(Integer i) { return new Cons(i, () -> from(i+1)); }
|
static LazyList from(Integer i) { return new Cons(i, () -> from(i+1)); }
|
||||||
|
|
||||||
/*LazyList filter(Fun1$$<Integer, Boolean> p, LazyList l) {
|
/*LazyList filter(Fun1$$<Integer, Boolean> p, LazyList l) {
|
||||||
@@ -18,7 +19,7 @@ public class Primzahlen {
|
|||||||
case Cons(Integer x, Fun0$$<LazyList> l1) ->
|
case Cons(Integer x, Fun0$$<LazyList> l1) ->
|
||||||
p.apply(x) ? new Cons(x, () -> filter(p, l1.apply())) : filter(p, l1.apply());
|
p.apply(x) ? new Cons(x, () -> filter(p, l1.apply())) : filter(p, l1.apply());
|
||||||
};
|
};
|
||||||
}*/
|
}
|
||||||
|
|
||||||
LazyList dropMul(Integer x, LazyList xs) {
|
LazyList dropMul(Integer x, LazyList xs) {
|
||||||
return new Filter().filter(y -> (y % x != 0), xs);
|
return new Filter().filter(y -> (y % x != 0), xs);
|
||||||
@@ -40,13 +41,13 @@ public class Primzahlen {
|
|||||||
new Cons(x, () -> take(n-1, l1.apply()));
|
new Cons(x, () -> take(n-1, l1.apply()));
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
*/
|
||||||
public static void main(args) {
|
public static void main(args) {
|
||||||
System.out.println(new Cons(1, () -> new Cons(2, () -> new Empty())).fst());
|
//System.out.println(new Cons(1, () -> new Cons(2, () -> new Empty())).fst());
|
||||||
var l = new Cons(1, () -> new Cons(2, () -> new Cons(2, () -> new Empty())));
|
var l = new Cons(1, () -> new Cons(2, () -> new Cons(2, () -> new Empty())));
|
||||||
System.out.println(l);
|
//System.out.println(l);
|
||||||
var filtered = new Filter().filter(x -> x == 2, l);
|
//var filtered = new Filter().filter(x -> x == 2, l);
|
||||||
System.out.println(filtered);
|
//ystem.out.println(filtered);
|
||||||
//System.out.println(from(1).rest().fst());
|
//System.out.println(from(1).rest().fst());
|
||||||
//Primzahlen pz = new Primzahlen();
|
//Primzahlen pz = new Primzahlen();
|
||||||
//System.out.println(pz.take(10, pz.from(2)));
|
//System.out.println(pz.take(10, pz.from(2)));
|
||||||
|
|||||||
@@ -1111,7 +1111,7 @@ public class StatementGenerator {
|
|||||||
if (expression.lambdaBody().expression() != null) {
|
if (expression.lambdaBody().expression() != null) {
|
||||||
List<Statement> statements = new ArrayList<>();
|
List<Statement> statements = new ArrayList<>();
|
||||||
statements.add(new Return(lambdaGenerator.convert(expression.lambdaBody().expression()), expression.lambdaBody().expression().getStart()));
|
statements.add(new Return(lambdaGenerator.convert(expression.lambdaBody().expression()), expression.lambdaBody().expression().getStart()));
|
||||||
block = new Block(statements, expression.lambdaBody().getStart());
|
block = new Block(statements, expression.lambdaBody().getStart(), -1);
|
||||||
} else {
|
} else {
|
||||||
block = lambdaGenerator.convert(expression.lambdaBody().block(), true);
|
block = lambdaGenerator.convert(expression.lambdaBody().block(), true);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,11 @@ public class Block extends Statement {
|
|||||||
this.statements = statements;
|
this.statements = statements;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Block(List<Statement> statements, Token offset, int variance) {
|
||||||
|
super(TypePlaceholder.fresh(offset, variance, true), offset);
|
||||||
|
this.statements = statements;
|
||||||
|
}
|
||||||
|
|
||||||
public List<Statement> statements = new ArrayList<>();
|
public List<Statement> statements = new ArrayList<>();
|
||||||
|
|
||||||
public List<Statement> getStatements() {
|
public List<Statement> getStatements() {
|
||||||
|
|||||||
@@ -188,8 +188,10 @@ public class OutputGenerator implements ASTVisitor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(LambdaExpression lambdaExpression) {
|
public void visit(LambdaExpression lambdaExpression) {
|
||||||
lambdaExpression.params.accept(this);
|
out.append("(");
|
||||||
|
lambdaExpression.params.accept(this);
|
||||||
out.append(" -> ");
|
out.append(" -> ");
|
||||||
|
out.append("(");
|
||||||
lambdaExpression.methodBody.accept(this);
|
lambdaExpression.methodBody.accept(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ public class distributeVariance extends visitUnifyTypeVisitor<Integer> {
|
|||||||
List<UnifyType> param = new ArrayList<>(funnty.getTypeParams().get().length);
|
List<UnifyType> param = new ArrayList<>(funnty.getTypeParams().get().length);
|
||||||
param.addAll(Arrays.asList(funnty.getTypeParams().get()));
|
param.addAll(Arrays.asList(funnty.getTypeParams().get()));
|
||||||
UnifyType resultType = param.remove(param.size()-1);
|
UnifyType resultType = param.remove(param.size()-1);
|
||||||
|
ht = (ht == 0)? 1 : 0; //bei ht = 0 wird ht auf die Standardwerte für Functionstypes gesetzt
|
||||||
int htInverse = inverseVariance(ht);
|
int htInverse = inverseVariance(ht);
|
||||||
param = param.stream()
|
param = param.stream()
|
||||||
.map(x -> x.accept(this, htInverse))
|
.map(x -> x.accept(this, htInverse))
|
||||||
|
|||||||
@@ -257,6 +257,7 @@ public class TestComplete {
|
|||||||
@Test
|
@Test
|
||||||
//@Disabled("This is too complex")
|
//@Disabled("This is too complex")
|
||||||
public void matrixTest() throws Exception {
|
public void matrixTest() throws Exception {
|
||||||
|
//ConsoleInterface.logLevel = LogLevel.DEBUG;
|
||||||
var classFiles = generateClassFiles(createClassLoader(), "Matrix.jav");
|
var classFiles = generateClassFiles(createClassLoader(), "Matrix.jav");
|
||||||
var matrix = classFiles.get("Matrix");
|
var matrix = classFiles.get("Matrix");
|
||||||
|
|
||||||
@@ -1359,6 +1360,7 @@ public class TestComplete {
|
|||||||
@Disabled("See #405")
|
@Disabled("See #405")
|
||||||
@Test
|
@Test
|
||||||
public void testLazy() throws Exception {
|
public void testLazy() throws Exception {
|
||||||
|
ConsoleInterface.logLevel = LogLevel.DEBUG;
|
||||||
var classFiles = generateClassFiles(createClassLoader(), false, "LazyList.jav", "Primzahlen.jav");
|
var classFiles = generateClassFiles(createClassLoader(), false, "LazyList.jav", "Primzahlen.jav");
|
||||||
var clazz = classFiles.get("Primzahlen");
|
var clazz = classFiles.get("Primzahlen");
|
||||||
var main = clazz.getDeclaredMethod("main", List.class);
|
var main = clazz.getDeclaredMethod("main", List.class);
|
||||||
|
|||||||
Reference in new issue
Block a user