Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
db040d590e | ||
|
f496ff13b8 | ||
|
642ecc9a50 | ||
|
a0e59eebe8 |
9
resources/KPSPresentation/AddEle.jav
Normal file
9
resources/KPSPresentation/AddEle.jav
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
import java.util.Vector;
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
class AddEle {
|
||||||
|
addEle(x, y) {
|
||||||
|
x.add(y);
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
}
|
15
resources/KPSPresentation/Fac.jav
Normal file
15
resources/KPSPresentation/Fac.jav
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
import java.lang.Double;
|
||||||
|
import java.lang.Integer;
|
||||||
|
|
||||||
|
public class Fac {
|
||||||
|
|
||||||
|
getFac(n){
|
||||||
|
var res = 1;
|
||||||
|
var i = 1;
|
||||||
|
while(i<=n) {
|
||||||
|
res = res * i;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
}
|
18
resources/KPSPresentation/Faculty.jav
Normal file
18
resources/KPSPresentation/Faculty.jav
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
import java.lang.Integer;
|
||||||
|
import java.lang.Float;
|
||||||
|
|
||||||
|
public class Faculty {
|
||||||
|
public Fun1$$<Integer, Integer> fact = (x) -> {
|
||||||
|
if (x == 1) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return x * (fact.apply(x-1));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public getFact(x) {
|
||||||
|
return fact.apply(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
18
resources/KPSPresentation/FacultyBug.jav
Normal file
18
resources/KPSPresentation/FacultyBug.jav
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
import java.lang.Integer;
|
||||||
|
import java.lang.Float;
|
||||||
|
|
||||||
|
public class FacultyBug {
|
||||||
|
public Fun1$$<Float, Float> fact = (x) -> {
|
||||||
|
if (x == 1) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return x * (fact.apply(x-1));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public getFact(x) {
|
||||||
|
return fact.apply(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
11
resources/KPSPresentation/Id.jav
Normal file
11
resources/KPSPresentation/Id.jav
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
class Id {
|
||||||
|
id2 = x -> x;
|
||||||
|
|
||||||
|
id(x) {
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
|
id3(x) {
|
||||||
|
return id(x);
|
||||||
|
}
|
||||||
|
}
|
11
resources/KPSPresentation/Lambda.jav
Normal file
11
resources/KPSPresentation/Lambda.jav
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
import java.lang.Integer;
|
||||||
|
|
||||||
|
public class Lambda {
|
||||||
|
|
||||||
|
m () {
|
||||||
|
var lam1 = (x) -> {
|
||||||
|
return x * x;
|
||||||
|
};
|
||||||
|
return lam1;
|
||||||
|
}
|
||||||
|
}
|
105
resources/KPSPresentation/Main.jav
Normal file
105
resources/KPSPresentation/Main.jav
Normal file
@@ -0,0 +1,105 @@
|
|||||||
|
import java.lang.String ;
|
||||||
|
import java.lang.System;
|
||||||
|
import java.io.PrintStream;
|
||||||
|
import java.lang.Character;
|
||||||
|
import java.lang.Object;
|
||||||
|
import java.lang.Integer;
|
||||||
|
import fst;
|
||||||
|
import Id;
|
||||||
|
import OLMain;
|
||||||
|
import Fac;
|
||||||
|
import Faculty;
|
||||||
|
import applyLambda;
|
||||||
|
import java.util.Vector;
|
||||||
|
import Matrix;
|
||||||
|
|
||||||
|
public class Main {
|
||||||
|
public static main(x) {
|
||||||
|
/*
|
||||||
|
new fst().main(5);
|
||||||
|
System.out.println(new fst().main(5));
|
||||||
|
|
||||||
|
//Id.jav: the identity-function
|
||||||
|
//applied to an integer
|
||||||
|
System.out.println(new Id().id(1));
|
||||||
|
//applied to a string
|
||||||
|
System.out.println(new Id().id("hallo"));
|
||||||
|
//lamda-Expr
|
||||||
|
//System.out.println(new Id().id2.apply(1));
|
||||||
|
//Bug: https://gitea.hb.dhbw-stuttgart.de/JavaTX/JavaCompilerCore/issues/378
|
||||||
|
|
||||||
|
//OL.jav: Overloading
|
||||||
|
OLMain ol = new OLMain();
|
||||||
|
|
||||||
|
//the function main is applied to an integer
|
||||||
|
System.out.println(ol.main(2));
|
||||||
|
//the main is applied to a double
|
||||||
|
System.out.println(ol.main(2.0));
|
||||||
|
System.out.println(ol.main("Hallo"));
|
||||||
|
//Fac.jav
|
||||||
|
System.out.println(new Fac().getFac(6));
|
||||||
|
|
||||||
|
|
||||||
|
//Faculty.jav
|
||||||
|
//System.out.println(new Faculty().fact.apply(6));
|
||||||
|
//Bug: https://gitea.hb.dhbw-stuttgart.de/JavaTX/JavaCompilerCore/issues/378
|
||||||
|
System.out.println(new Faculty().getFact(3));
|
||||||
|
|
||||||
|
//Lambda.jav: An lambda expression applied by the method apply
|
||||||
|
//System.out.println(new Lambda().m().apply(77));
|
||||||
|
//Bug: https://gitea.hb.dhbw-stuttgart.de/JavaTX/JavaCompilerCore/issues/378
|
||||||
|
|
||||||
|
//applyLambda.jav: A defined lambda expression is applied
|
||||||
|
System.out.println(new applyLambda().m());
|
||||||
|
*/
|
||||||
|
Vector<Vector<Integer>> vv = new Vector<Vector<Integer>>();
|
||||||
|
Vector<Integer> v1 = new Vector<Integer> ();
|
||||||
|
v1.addElement(2);
|
||||||
|
v1.addElement(2);
|
||||||
|
Vector<Integer> v2 = new Vector<Integer> ();
|
||||||
|
v2.addElement(3);
|
||||||
|
v2.addElement(3);
|
||||||
|
Matrix m1 = new Matrix();
|
||||||
|
m1.addElement(v1);
|
||||||
|
m1.addElement(v2);
|
||||||
|
//vv.addElement(v1);
|
||||||
|
//vv.addElement(v2);
|
||||||
|
//Matrix m1 = new Matrix(vv);
|
||||||
|
|
||||||
|
Vector<Vector<Integer>> vv1 = new Vector<Vector<Integer>>();
|
||||||
|
Vector<Integer> v3 = new Vector<Integer> ();
|
||||||
|
v3.addElement(2);
|
||||||
|
v3.addElement(2);
|
||||||
|
Vector<Integer> v4 = new Vector<Integer> ();
|
||||||
|
v4.addElement(3);
|
||||||
|
v4.addElement(3);
|
||||||
|
Matrix m2 = new Matrix();
|
||||||
|
m2.addElement(v3);
|
||||||
|
m2.addElement(v4);
|
||||||
|
//vv1.addElement(v3);
|
||||||
|
//vv1.addElement(v4);
|
||||||
|
//Matrix m2 = new Matrix(vv1);
|
||||||
|
|
||||||
|
|
||||||
|
//Matrix m3 = m1.mul(vv1);
|
||||||
|
Matrix m3 = m1.mul(m2);
|
||||||
|
System.out.println(m1.toString() + " * " + m2.toString() + " = " + m3.toString());
|
||||||
|
/*
|
||||||
|
//MatrixOP
|
||||||
|
MatrixOP mOp1 = new MatrixOP();
|
||||||
|
mOp1.addElement(v1);
|
||||||
|
mOp1.addElement(v2);
|
||||||
|
MatrixOP mOp2 = mOp1.mul.apply(mOp1, mOp1);
|
||||||
|
System.out.println(m1.toString() + " * " + m2.toString() + " = " + mOp2.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class MainBug {
|
||||||
|
public static main(x) {
|
||||||
|
System.out.println(new fst().main(5));
|
||||||
|
//System.out.println(new FacultyBug().getFact(3));
|
||||||
|
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
}
|
41
resources/KPSPresentation/Matrix.jav
Normal file
41
resources/KPSPresentation/Matrix.jav
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
import java.util.Vector;
|
||||||
|
import java.lang.Integer;
|
||||||
|
import java.lang.Boolean;
|
||||||
|
|
||||||
|
public class Matrix extends Vector<Vector<Integer>> {
|
||||||
|
|
||||||
|
|
||||||
|
public Matrix () {
|
||||||
|
}
|
||||||
|
|
||||||
|
public Matrix(vv) {
|
||||||
|
var i = 0;
|
||||||
|
while(i < vv.size()) {
|
||||||
|
this.add(vv.elementAt(i));
|
||||||
|
i=i+1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
mul(m) {
|
||||||
|
var ret = new Matrix();
|
||||||
|
var i = 0;
|
||||||
|
while(i < size()) {
|
||||||
|
var v1 = this.elementAt(i);
|
||||||
|
var v2 = new Vector<Integer>();
|
||||||
|
var j = 0;
|
||||||
|
while(j < v1.size()) {
|
||||||
|
var erg = 0;
|
||||||
|
var k = 0;
|
||||||
|
while(k < v1.size()) {
|
||||||
|
erg = erg + v1.elementAt(k)
|
||||||
|
* m.elementAt(k).elementAt(j);
|
||||||
|
k++; }
|
||||||
|
v2.addElement(erg);
|
||||||
|
j++; }
|
||||||
|
ret.addElement(v2);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
}
|
42
resources/KPSPresentation/MatrixOP.jav
Normal file
42
resources/KPSPresentation/MatrixOP.jav
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
import java.util.Vector;
|
||||||
|
import java.lang.Integer;
|
||||||
|
import java.lang.Byte;
|
||||||
|
import java.lang.Boolean;
|
||||||
|
|
||||||
|
public class MatrixOP extends Vector<Vector<Integer>> {
|
||||||
|
|
||||||
|
MatrixOP () {
|
||||||
|
}
|
||||||
|
|
||||||
|
MatrixOP(vv) {
|
||||||
|
Integer i;
|
||||||
|
i = 0;
|
||||||
|
while(i < vv.size()) {
|
||||||
|
this.add(vv.elementAt(i));
|
||||||
|
i=i+1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Fun2$$<Vector<? extends Vector<? extends Integer>>, Vector<? extends Vector<? extends Integer>>, MatrixOP> mul = (m1, m2) -> {
|
||||||
|
var ret = new MatrixOP();
|
||||||
|
var i = 0;
|
||||||
|
while(i < m1.size()) {
|
||||||
|
var v1 = m1.elementAt(i);
|
||||||
|
var v2 = new Vector<Integer>();
|
||||||
|
var j = 0;
|
||||||
|
while(j < v1.size()) {
|
||||||
|
var erg = 0;
|
||||||
|
var k = 0;
|
||||||
|
while(k < v1.size()) {
|
||||||
|
erg = erg + v1.elementAt(k)
|
||||||
|
* m2.elementAt(k).elementAt(j);
|
||||||
|
k++; }
|
||||||
|
// v2.addElement(new Integer(erg));
|
||||||
|
v2.addElement(erg);
|
||||||
|
j++; }
|
||||||
|
ret.addElement(v2);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
};
|
||||||
|
}
|
30
resources/KPSPresentation/OL.jav
Normal file
30
resources/KPSPresentation/OL.jav
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
import java.lang.String;
|
||||||
|
import java.lang.Integer;
|
||||||
|
import java.lang.Double;
|
||||||
|
import java.lang.Boolean;
|
||||||
|
import java.lang.Object;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class OL {
|
||||||
|
|
||||||
|
m(x) { return x + x; }
|
||||||
|
|
||||||
|
|
||||||
|
m(x) { return x || x; }
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class OLMain {
|
||||||
|
|
||||||
|
main(x) {
|
||||||
|
var ol;
|
||||||
|
ol = new OL();
|
||||||
|
return ol.m(x);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
20
resources/KPSPresentation/OLFun.jav
Normal file
20
resources/KPSPresentation/OLFun.jav
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
import java.lang.String;
|
||||||
|
import java.lang.Integer;
|
||||||
|
import java.lang.Double;
|
||||||
|
import java.util.Vector;
|
||||||
|
import java.lang.Boolean;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public class OLFun {
|
||||||
|
x;
|
||||||
|
|
||||||
|
|
||||||
|
m(f, y) {
|
||||||
|
y = f.apply(x+x);
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
12
resources/KPSPresentation/Pair.jav
Normal file
12
resources/KPSPresentation/Pair.jav
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
class Pair {
|
||||||
|
fst;
|
||||||
|
snd;
|
||||||
|
|
||||||
|
Pair(fst, snd) { this.fst=fst; this.snd=snd; }
|
||||||
|
|
||||||
|
getfst() { return this.fst; }
|
||||||
|
|
||||||
|
swap() {
|
||||||
|
return new Pair<>(this.snd, this.fst);
|
||||||
|
}
|
||||||
|
}
|
9
resources/KPSPresentation/Plus.jav
Normal file
9
resources/KPSPresentation/Plus.jav
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
import java.lang.Integer;
|
||||||
|
import java.lang.String;
|
||||||
|
|
||||||
|
public class Plus {
|
||||||
|
|
||||||
|
m(a, b) {
|
||||||
|
return a+b;
|
||||||
|
}
|
||||||
|
}
|
25
resources/KPSPresentation/Sorting.jav
Normal file
25
resources/KPSPresentation/Sorting.jav
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
import java.util.List;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.lang.String;
|
||||||
|
|
||||||
|
public class Sorting{
|
||||||
|
merge(a, b){
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
20
resources/KPSPresentation/Swap.jav
Normal file
20
resources/KPSPresentation/Swap.jav
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
import java.lang.String;
|
||||||
|
import java.lang.Object;
|
||||||
|
import java.lang.System;
|
||||||
|
import java.io.PrintStream;
|
||||||
|
import java.lang.Character;
|
||||||
|
|
||||||
|
public class Swap{
|
||||||
|
<ZDP, ZEA, ZDO, YZP, ZCY, ZDZ> Fun1$$<ZCY, Fun1$$<ZDZ, ZEA>> swap(f){
|
||||||
|
return x->y->f.apply(y).apply(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
Fun1$$<String, Fun1$$<String, Fun1$$<String, String>>> swap(f){
|
||||||
|
return x -> y -> z -> f.apply(z).apply(x).apply(y);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static main (y) {
|
||||||
|
var func = x -> y -> z -> x + y + z;
|
||||||
|
var res = new Swap().swap(func).apply("A").apply("B").apply("C");
|
||||||
|
System.out.println(res);}
|
||||||
|
}
|
6
resources/KPSPresentation/TPHMethod.jav
Normal file
6
resources/KPSPresentation/TPHMethod.jav
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
class TPHMethod {
|
||||||
|
void m(a, b) {
|
||||||
|
a = b;
|
||||||
|
b=a;
|
||||||
|
}
|
||||||
|
}
|
16
resources/KPSPresentation/Test.jav
Normal file
16
resources/KPSPresentation/Test.jav
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
class Test{
|
||||||
|
void m( op, a, b ){
|
||||||
|
op.myapply(a, b);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Atype{}
|
||||||
|
class Btype{}
|
||||||
|
|
||||||
|
class Operator1{
|
||||||
|
void myapply(Atype p1, Atype p2){...}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Operator2{
|
||||||
|
void myapply(Btype p1, Btype p2){...}
|
||||||
|
}
|
7
resources/KPSPresentation/Uncurrier.jav
Normal file
7
resources/KPSPresentation/Uncurrier.jav
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
public class Uncurrier{
|
||||||
|
uncurry (f){
|
||||||
|
return x -> f.apply(x);}
|
||||||
|
uncurry (f){
|
||||||
|
return (x, y) -> f.apply(x).apply(y);
|
||||||
|
}
|
||||||
|
}
|
7
resources/KPSPresentation/UncurrierMain.jav
Normal file
7
resources/KPSPresentation/UncurrierMain.jav
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
import Uncurrier;
|
||||||
|
|
||||||
|
class UncurrierMain {
|
||||||
|
public static main(x) {
|
||||||
|
var uc = new Uncurrier() ;
|
||||||
|
}
|
||||||
|
}
|
16
resources/KPSPresentation/VectorAdd.jav
Normal file
16
resources/KPSPresentation/VectorAdd.jav
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
import java.lang.Integer;
|
||||||
|
import java.lang.String;
|
||||||
|
import java.util.Vector;
|
||||||
|
|
||||||
|
class VectorAdd {
|
||||||
|
vectorAdd(v1, v2) {
|
||||||
|
var i = 0;
|
||||||
|
var erg = new Vector<>();
|
||||||
|
while (i < v1.size()) {
|
||||||
|
erg.addElement(v1.elementAt(i) + v2.elementAt(i));
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return erg;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
16
resources/KPSPresentation/applyLambda.jav
Normal file
16
resources/KPSPresentation/applyLambda.jav
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
import java.util.Vector;
|
||||||
|
class Apply { }
|
||||||
|
|
||||||
|
public class applyLambda {
|
||||||
|
|
||||||
|
public m () {
|
||||||
|
var lam1 = (x) -> {
|
||||||
|
return x;
|
||||||
|
};
|
||||||
|
|
||||||
|
return lam1.apply(new Apply());
|
||||||
|
//return lam1;
|
||||||
|
//return new Vector();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
7
resources/KPSPresentation/fst.jav
Normal file
7
resources/KPSPresentation/fst.jav
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
//import java.lang.Integer;
|
||||||
|
|
||||||
|
class fst {
|
||||||
|
main(x) {
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
}
|
8
resources/KPSPresentation/genVector.jav
Normal file
8
resources/KPSPresentation/genVector.jav
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
import java.util.Vector;
|
||||||
|
|
||||||
|
class genVector {
|
||||||
|
|
||||||
|
m(v) {
|
||||||
|
return v.elementAt(0);
|
||||||
|
}
|
||||||
|
}
|
8
resources/KPSPresentation/idTest.jav
Normal file
8
resources/KPSPresentation/idTest.jav
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
import java.lang.Integer;
|
||||||
|
import Id;
|
||||||
|
|
||||||
|
class Test {
|
||||||
|
m() {
|
||||||
|
Integer o1 = new Id<Integer,Integer>().id2.apply(1);
|
||||||
|
}
|
||||||
|
}
|
9
resources/KPSPresentation/lambdaId.jav
Normal file
9
resources/KPSPresentation/lambdaId.jav
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
public class lambdaId {
|
||||||
|
lambdaId = x -> x;
|
||||||
|
|
||||||
|
/*
|
||||||
|
id3 (x) {
|
||||||
|
return lambdaId.apply(x);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
9
resources/KPSPresentation/mathStruc.jav
Normal file
9
resources/KPSPresentation/mathStruc.jav
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
class mathStruc {
|
||||||
|
model;
|
||||||
|
|
||||||
|
innerOp = (o) -> (ms) -> new mathStruc<>(o.apply(model,ms.model));
|
||||||
|
|
||||||
|
mathStruc(m) {
|
||||||
|
model =m;
|
||||||
|
}
|
||||||
|
}
|
18
resources/KPSPresentation/mathStrucInteger.jav
Normal file
18
resources/KPSPresentation/mathStrucInteger.jav
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
import java.lang.Integer;
|
||||||
|
|
||||||
|
class mathStruc {
|
||||||
|
model;
|
||||||
|
|
||||||
|
innerOp = (o) -> (ms) -> new mathStruc<>(o.apply(model,ms.model));
|
||||||
|
|
||||||
|
mathStruc(m) {
|
||||||
|
model =m;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class mathStrucIntegerUse {
|
||||||
|
main() {
|
||||||
|
var ms = new mathStruc<>(2);
|
||||||
|
return ms.innerOp.apply((x,y) -> x+y).apply(ms);
|
||||||
|
}
|
||||||
|
}
|
90
resources/KPSPresentation/mathStrucMatrixOP.jav
Normal file
90
resources/KPSPresentation/mathStrucMatrixOP.jav
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
import java.util.Vector;
|
||||||
|
import java.lang.Integer;
|
||||||
|
import java.lang.Boolean;
|
||||||
|
|
||||||
|
public class mathStrucMatrixOP {
|
||||||
|
model;
|
||||||
|
|
||||||
|
innerOp = (o) -> (ms) -> new mathStrucMatrixOP<>(o.apply(model,ms.model));
|
||||||
|
|
||||||
|
public mathStrucMatrixOP(m) {
|
||||||
|
model =m;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class MatrixOP extends Vector<Vector<Integer>> {
|
||||||
|
|
||||||
|
MatrixOP () {
|
||||||
|
}
|
||||||
|
|
||||||
|
MatrixOP(vv) {
|
||||||
|
Integer i;
|
||||||
|
i = 0;
|
||||||
|
while(i < vv.size()) {
|
||||||
|
// Boolean a = this.add(vv.elementAt(i));
|
||||||
|
this.add(vv.elementAt(i));
|
||||||
|
i=i+1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public mul = (m1, m2) -> {
|
||||||
|
var ret = new MatrixOP();
|
||||||
|
var i = 0;
|
||||||
|
while(i < m1.size()) {
|
||||||
|
var v1 = m1.elementAt(i);
|
||||||
|
var v2 = new Vector<Integer>();
|
||||||
|
var j = 0;
|
||||||
|
while(j < v1.size()) {
|
||||||
|
var erg = 0;
|
||||||
|
var k = 0;
|
||||||
|
while(k < v1.size()) {
|
||||||
|
erg = erg + v1.elementAt(k)
|
||||||
|
* m2.elementAt(k).elementAt(j);
|
||||||
|
k++; }
|
||||||
|
// v2.addElement(new Integer(erg));
|
||||||
|
v2.addElement(erg);
|
||||||
|
j++; }
|
||||||
|
ret.addElement(v2);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class mathStrucUseMatrixOP {
|
||||||
|
|
||||||
|
main() {
|
||||||
|
Vector<Vector<Integer>> vv = new Vector<Vector<Integer>>();
|
||||||
|
Vector<Integer> v1 = new Vector<Integer>();
|
||||||
|
v1.addElement(2);
|
||||||
|
v1.addElement(2);
|
||||||
|
Vector<Integer> v2 = new Vector<Integer>();
|
||||||
|
v2.addElement(3);
|
||||||
|
v2.addElement(3);
|
||||||
|
vv.addElement(v1);
|
||||||
|
vv.addElement(v2);
|
||||||
|
|
||||||
|
MatrixOP m1 = new MatrixOP(vv);
|
||||||
|
|
||||||
|
Vector<Vector<Integer>> vv1 = new Vector<Vector<Integer>>();
|
||||||
|
Vector<Integer> v3 = new Vector<Integer>();
|
||||||
|
v3.addElement(2);
|
||||||
|
v3.addElement(2);
|
||||||
|
Vector<Integer> v4 = new Vector<Integer>();
|
||||||
|
v4.addElement(3);
|
||||||
|
v4.addElement(3);
|
||||||
|
vv1.addElement(v3);
|
||||||
|
vv1.addElement(v4);
|
||||||
|
|
||||||
|
MatrixOP m2 = new MatrixOP(vv1);
|
||||||
|
|
||||||
|
var mms;
|
||||||
|
mms = new mathStrucMatrixOP<>(m1);
|
||||||
|
var mms2;
|
||||||
|
mms2 = new mathStrucMatrixOP<>(m2);
|
||||||
|
var mms3;
|
||||||
|
mms3 = mms.innerOp.apply(m1.mul).apply(mms2);
|
||||||
|
return mms3;
|
||||||
|
}
|
||||||
|
}
|
14
resources/KPSPresentation/test1.jav
Normal file
14
resources/KPSPresentation/test1.jav
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
import java.lang.String;
|
||||||
|
import java.lang.Boolean;
|
||||||
|
import java.lang.Integer;
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
public class testclass{
|
||||||
|
|
||||||
|
public testMethod(ele){
|
||||||
|
if(ele){
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
@@ -1,3 +0,0 @@
|
|||||||
class Bug378Id {
|
|
||||||
id2 = x -> x;
|
|
||||||
}
|
|
@@ -1,8 +0,0 @@
|
|||||||
import Bug378Id;
|
|
||||||
import java.lang.Integer;
|
|
||||||
|
|
||||||
class Bug378Main {
|
|
||||||
static main(args) {
|
|
||||||
var hallo = (new Bug378Id<Integer>().id2).apply(1);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -2,6 +2,7 @@ import java.util.Vector;
|
|||||||
import java.lang.Integer;
|
import java.lang.Integer;
|
||||||
//import java.lang.Byte;
|
//import java.lang.Byte;
|
||||||
import java.lang.Boolean;
|
import java.lang.Boolean;
|
||||||
|
import java.util.function.BiFunction;
|
||||||
|
|
||||||
public class MatrixOP extends Vector<Vector<Integer>> {
|
public class MatrixOP extends Vector<Vector<Integer>> {
|
||||||
|
|
||||||
|
@@ -161,6 +161,7 @@ public class StatementToTargetExpression implements ASTVisitor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(FieldVar fieldVar) {
|
public void visit(FieldVar fieldVar) {
|
||||||
|
var isStatic = false;
|
||||||
var type = converter.convert(fieldVar.receiver.getType());
|
var type = converter.convert(fieldVar.receiver.getType());
|
||||||
var clazz = converter.compiler.getClass(new JavaClassName(type.name()));
|
var clazz = converter.compiler.getClass(new JavaClassName(type.name()));
|
||||||
var field = clazz.getField(fieldVar.fieldVarName).orElseThrow();
|
var field = clazz.getField(fieldVar.fieldVarName).orElseThrow();
|
||||||
|
@@ -33,10 +33,4 @@ public record TargetFunNType(String name, List<TargetType> funNParams, List<Targ
|
|||||||
public String getInternalName() {
|
public String getInternalName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toSignature() {
|
|
||||||
var args = FunNGenerator.getArguments(params);
|
|
||||||
return "LFun" + args.size() + "$$" + TargetSpecializedType.signatureParameters(params) + ";";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -8,20 +8,14 @@ public sealed interface TargetSpecializedType extends TargetType permits TargetF
|
|||||||
@Override
|
@Override
|
||||||
default String toSignature() {
|
default String toSignature() {
|
||||||
String ret = "L" + getInternalName();
|
String ret = "L" + getInternalName();
|
||||||
ret += signatureParameters(params());
|
if (!params().isEmpty()) {
|
||||||
ret += ";";
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static String signatureParameters(List<TargetType> params) {
|
|
||||||
var ret = "";
|
|
||||||
if (!params.isEmpty()) {
|
|
||||||
ret += "<";
|
ret += "<";
|
||||||
for (var param : params) {
|
for (var param : params()) {
|
||||||
ret += param.toSignature();
|
ret += param.toSignature();
|
||||||
}
|
}
|
||||||
ret += ">";
|
ret += ">";
|
||||||
}
|
}
|
||||||
|
ret += ";";
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -63,11 +63,13 @@ public class AllgemeinTest {
|
|||||||
//String className = "Cycle";
|
//String className = "Cycle";
|
||||||
//String className = "TripleTest";
|
//String className = "TripleTest";
|
||||||
//String className = "WildcardList";
|
//String className = "WildcardList";
|
||||||
String className = "List";
|
//String className = "List";
|
||||||
//String className = "Box";
|
//String className = "Box";
|
||||||
//String className = "GenBox";
|
//String className = "GenBox";
|
||||||
//String className = "InnerInf";
|
//String className = "InnerInf";
|
||||||
//String className = "Foo";
|
//String className = "Foo";
|
||||||
|
//String className = "Uncurrier";
|
||||||
|
String className = "UncurrierMain";
|
||||||
//PL 2019-10-24: genutzt fuer unterschiedliche Tests
|
//PL 2019-10-24: genutzt fuer unterschiedliche Tests
|
||||||
path = System.getProperty("user.dir")+"/resources/AllgemeinTest/" + className + ".jav";
|
path = System.getProperty("user.dir")+"/resources/AllgemeinTest/" + className + ".jav";
|
||||||
//path = System.getProperty("user.dir")+"/src/test/resources/AllgemeinTest/Overloading_Generics.jav";
|
//path = System.getProperty("user.dir")+"/src/test/resources/AllgemeinTest/Overloading_Generics.jav";
|
||||||
|
97
src/test/java/KPSPresentation.java
Normal file
97
src/test/java/KPSPresentation.java
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
import static targetast.TestCodegen.generateClassFiles;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLClassLoader;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||||
|
|
||||||
|
public class KPSPresentation {
|
||||||
|
|
||||||
|
private static String path;
|
||||||
|
private static File fileToTest;
|
||||||
|
private static JavaTXCompiler compiler;
|
||||||
|
private static ClassLoader loader;
|
||||||
|
private static Class<?> classToTest;
|
||||||
|
private static String pathToClassFile;
|
||||||
|
private static Object instanceOfClass;
|
||||||
|
|
||||||
|
|
||||||
|
public void testAlgo(String className) throws Exception {
|
||||||
|
//PL 2019-10-24: genutzt fuer unterschiedliche Tests
|
||||||
|
path = System.getProperty("user.dir")+"/resources/KPSPresentation/" + className + ".jav";
|
||||||
|
//path = System.getProperty("user.dir")+"/src/test/resources/AllgemeinTest/Overloading_Generics.jav";
|
||||||
|
//path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/mathStrucInteger.jav";
|
||||||
|
//compiler = new JavaTXCompiler(Lists.newArrayList(new File(System.getProperty("user.dir")+"/src/test/resources/AllgemeinTest/Overloading_Generics.jav")));
|
||||||
|
///*
|
||||||
|
compiler = new JavaTXCompiler(
|
||||||
|
Lists.newArrayList(new File(path)),
|
||||||
|
Lists.newArrayList(new File(System.getProperty("user.dir")+"/resources/KPSPresentation/classFiles/")),
|
||||||
|
new File(System.getProperty("user.dir")+"/resources/KPSPresentation/classFiles/"));
|
||||||
|
//*/
|
||||||
|
compiler.generateBytecode();
|
||||||
|
pathToClassFile = System.getProperty("user.dir")+"/resources/KPSPresentation/classFiles/";
|
||||||
|
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||||
|
classToTest = loader.loadClass(className);
|
||||||
|
//classToTest = loader.loadClass("Overloading_Generics");
|
||||||
|
//instanceOfClass = classToTest.getDeclaredConstructor().newInstance("A");
|
||||||
|
//classToTest = loader.loadClass("Overloading_Generics1");
|
||||||
|
//instanceOfClass = classToTest.getDeclaredConstructor(Object.class).newInstance("B");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void MainTest() throws Exception {
|
||||||
|
testAlgo("Main");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void fstTest() throws Exception {
|
||||||
|
testAlgo("fst");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void IdTest() throws Exception {
|
||||||
|
testAlgo("Id");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void OLTest() throws Exception {
|
||||||
|
testAlgo("OL");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void FacTest() throws Exception {
|
||||||
|
testAlgo("Fac");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void FacultyTest() throws Exception {
|
||||||
|
testAlgo("Faculty");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void Lambda() throws Exception {
|
||||||
|
testAlgo("Lambda");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void applyLambda() throws Exception {
|
||||||
|
testAlgo("applyLambda");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void Matrix() throws Exception {
|
||||||
|
testAlgo("Matrix");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -1476,14 +1476,4 @@ public class TestComplete {
|
|||||||
var m = clazz.getDeclaredMethod("main");
|
var m = clazz.getDeclaredMethod("main");
|
||||||
m.invoke(null);
|
m.invoke(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Disabled("Doesn't work yet")
|
|
||||||
@Test
|
|
||||||
public void testBug378() throws Exception {
|
|
||||||
var classFiles = generateClassFiles(createClassLoader(), "Bug378Main.jav");
|
|
||||||
var clazz = classFiles.get("Bug378Main");
|
|
||||||
var main = clazz.getDeclaredMethod("main", List.class);
|
|
||||||
main.setAccessible(true);
|
|
||||||
main.invoke(null, List.of());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user