diff options
| author | Patrick Schönberger | 2021-08-04 21:44:26 +0200 |
|---|---|---|
| committer | Patrick Schönberger | 2021-08-04 21:44:26 +0200 |
| commit | b9322dfb8efe37f6f88a899269bdf21015f4db9a (patch) | |
| tree | 837a9aadd80723f6c3d672fe0c9ae04f4f0864c8 /test | |
| parent | c2ba7425955ae538e220cec79d9124756d1b4c8b (diff) | |
| download | toc-b9322dfb8efe37f6f88a899269bdf21015f4db9a.tar.gz toc-b9322dfb8efe37f6f88a899269bdf21015f4db9a.zip | |
generic functions and structs
Diffstat (limited to 'test')
| -rw-r--r-- | test/test1.toc | 40 | ||||
| -rw-r--r-- | test/test2.toc | 61 |
2 files changed, 101 insertions, 0 deletions
diff --git a/test/test1.toc b/test/test1.toc new file mode 100644 index 0000000..1f604c0 --- /dev/null +++ b/test/test1.toc @@ -0,0 +1,40 @@ +var abc: int;
+var def: int;
+var ghi: int;
+
+func f1<A, B> (a : int, b : int, cs: int[]) : int {
+ var i1 : int;
+ var s1 : S1;
+ if a != i1 {
+ var i2 : int = 987;
+ return i2;
+ }
+ print(s1.i1);
+ print(s1.a1[0]);
+ return 133;
+}
+
+struct S1<T> {
+ i1 : int;
+ i2 : int;
+ a1 : int[10];
+ a2 : int[10]*;
+ a2 : int[];
+
+ m1<I>() : void {
+ while i1 < i2 {
+ i1 = m2(i1);
+
+ i2 = i1 + i2 * (i2 - 45) + 4;
+
+ print(12345);
+ }
+ }
+
+ m2<A>(i: int) : int {
+ var j : int = 0;
+ while j < 10 {
+ print(a1[j]);
+ }
+ }
+}
\ No newline at end of file diff --git a/test/test2.toc b/test/test2.toc new file mode 100644 index 0000000..6e8d4f8 --- /dev/null +++ b/test/test2.toc @@ -0,0 +1,61 @@ +func puts(str : char*) : void;
+
+namespace N1 {
+ func f1() : void {
+ puts("Hello\n");
+ }
+ namespace N2 {
+ struct S1 {
+ i1 : int;
+ i2 : int;
+ i3 : int;
+
+ m1(i: int) : int {
+ this->i3 = this->i1 * this->i2;
+
+ N1::f1();
+
+ return this->i1 + this->i2;
+ }
+ }
+
+ func f1() : void {
+ var s1 : N1::N2::S1;
+ s1.m1(123);
+ }
+ }
+}
+
+struct S1<T> {
+ t1: T;
+ t2: T;
+
+ m1() : T {
+ return this->t1 + this->t2;
+ }
+}
+
+func generic1<A>(a1 : A, a2 : A) : A {
+ return a1 + a2;
+}
+
+func main(argc : int, argv : char**) : int {
+ var s1 : N1::N2::S1;
+ var s2 : N1::N2::S1;
+ var s3 : N1::N2::S1;
+ s1.i1 = 123;
+ s1.i2 = 456;
+ s1.m1(s2.m1(s3.m1(89)));
+
+ N1::N2::f1();
+
+ var s4 : S1<int>;
+ s4.t1 = 123;
+ s4.t2 = 456;
+ s4.m1();
+
+ generic1<int>(1, 2);
+ generic1<double>(3.4, 5.6);
+
+ return 0;
+}
\ No newline at end of file |
