-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.ann
188 lines (126 loc) · 3.84 KB
/
example.ann
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#this function prints out the input parameter and returns nothing.
beginfunction returns_nothing [param as string];
out ["returns_nothing with: ", param];
return;
endfunction;
#this function prints out the input parameter and returns it.
beginfunction returns_something [param as string];
out ["returns_something with: ", param];
return [param];
endfunction;
#this function recursively adds 2 to param N times (as indicated by total) and
#returns the final value.
beginfunction chain [param as int, count as int, total as int];
if is_equal [count, total];
return [param];
else;
set count to add [count, 1];
set param to add [param, 2];
set param to chain [ param, count, total];
return [param];
endif;
endfunction;
#this function prints out a greeting and returns no value
beginfunction greeter;
out ["hello"];
endfunction;
#this function dumps out the given parameter with no additional strings.
beginfunction dumper [param as any];
out [param];
endfunction;
beginfunction timed_yield [ms as int];
out ["will yield for ", ms, " milliseconds"];
yield for ms;
endfunction;
beginfunction regular_yield [ms as int];
out ["will yield"];
yield;
endfunction;
#main function, a small program that does some test calls and then will yield
#until a value is declared in the host.
beginfunction main;
out ["an empty string follows", ""];
out ["begin test calls..."];
returns_nothing ["my string"];
let result be returns_something ["my string"];
out ["result is: ", result];
out ["begin recursive test call..."];
let intval be 0;
set intval to chain [intval, 0, 3];
out ["intval is: ", intval];
out ["begin arithmetic tests..."];
set intval to 0;
out ["intval should be 0, is ", intval];
set intval to add [3, 2, 1];
out ["intval should be 6, is ", intval];
if not is_equal [intval, 6];
fail ["something went very wrong in the addition tests..."];
endif;
if not is_greater_than [intval, 1, 2, 3, 4, 5];
fail ["something failed in the greater than tests..."];
endif;
if is_greater_than [intval, 6];
fail ["a value cannot be greater than itself..."];
endif;
if not is_lesser_than [intval, 7, 8, 9, 10];
fail ["something failed in the lesser than tests..."];
endif;
if is_lesser_than [intval, 6];
fail ["a value cannot be lesser than itself..."];
endif;
set intval to substract [intval, 3];
if not is_equal [intval, 3];
fail ["something failed in the substraction operation..."];
endif;
if not is_int [intval];
fail ["something failed asserting that inval is an integer"];
endif;
if is_double [intval];
fail ["integer value should not be a double"];
endif;
if is_bool [intval];
fail ["integer value should not be a boolean"];
endif;
if is_string [intval];
fail ["integer value should not be a string"];
endif;
out ["begin control flow tests... if hostval or hosttest was declared a a string in the host, it will be printed out"];
if host_has ["hostval"];
let tempval be host_get ["hostval"];
if is_string [tempval];
out ["hostval was declared as ", tempval];
else;
out ["hostval was declared, but it was not a string"];
endif;
elseif host_has ["hosttest"];
let tempval be host_get ["hosttest"];
if is_string [tempval];
out ["hosttest was declared as ", tempval];
else;
out ["hosttest was declared, but it was not a string"];
endif;
else;
out ["neither hostval or hosttest were declared in the host"];
endif;
out ["testing simple loop"];
let doubleval be 0.0;
let targetval be 2.2;
out [doubleval];
out [targetval];
loop;
if is_greater_than [doubleval, targetval];
break;
endif;
set doubleval to add [doubleval, 0.1];
out [doubleval, " / ", targetval];
endloop;
out ["testing yielding loop..."];
loop;
if host_has ["exit"];
break;
endif;
out ["yielding until 'exit' is declared in the host"];
yield;
endloop;
return [intval];
endfunction;