-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestExtended.ve
More file actions
98 lines (93 loc) · 2.52 KB
/
TestExtended.ve
File metadata and controls
98 lines (93 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
class List {
++head : int32 <- 2;
+isNil() : bool { true }
+length() : int32 { 0 }
+head() : int32 { head }
+delete() : List {
head <- 0;
self
}
}
(* Nil is nothing more than a glorified alias to List *)
class Nil extends List { }
class Cons extends List {
-tail : List;
+init(hd : int32, tl : List) : Cons {
head <- hd;
tail <- tl;
self
}
+isNil() : bool { false }
+length() : int32 { 1 + tail.length() }
+next() : List { tail }
}
class UseArray {
-arr : int32[][];
-arr2 : List[] <- new List[1];
+alloc() : int32 {
arr <- new int32[2][4];
arr2 <- new List[2];
let it : Integer <- 2 in {
it <- (new Integer).setValue(1);
arr[it][2] <- 4
};
arr[1][2]
}
+get(i : int32, j : int32) : int32 {
arr[i][j]
}
+sum(i1 : int32, j1 : int32, i2 : int32, j2 : int32) : int32 {
let a : int32 <- arr[i1][j1], b : int32 <- arr[i2][j2] in
a + b
}
}
class ExternalMath {
+strchr(s : string, i : int32) : string {
//This won't ever get evaluated by the compiler
0
}
}
class Main extends IO {
-say2(a : int32, b : string : "Hi") : int32 {
printInt32(a).print(b);
3
}
~afloat() : float {
2.2f ^ 2
}
+main() : int32 {
let s : int32 <- 4 in
let xs : Cons <- (new Cons).init(0, (new Cons).init(1, new Cons(2, new Nil))) in {
xs.head <- 12;
//Have just assigned to public field :3
xs.head();
print("Here 1\n");
printInt32(xs.getHead());
print("\nHere 2\n");
printInt32(xs.next().head());
print("\nHere 3\n");
printInt32(1).printInt32(xs.next().head()).printInt32(xs.length()).printInt32(xs.next().length());
print("\nLength as dyn cast\n");
printInt32(xs.length());
print("\nLength as static cast\n");
printInt32(xs<List.length());
let xl : List <- xs in {
let xl2 : Cons <- xl<Cons> in {
print("Got back my instance")
}
};
erase xs;
if s <> 0:5 then
print("s is between 0 and 5")
};
print("Here at last");
say2(1, "Hehe");
say2(2);
print("Getting a float");
printFloat(afloat());
printFloat(@say2(3));
print("Getting an array element").printInt32((new UseArray).alloc());
print("Here is your echoed float: ").printFloat(inputFloat());
0
}
}