1
0
Fork 0
undar-lang-old/test/fib.uir.ul

61 lines
952 B
C

/**
* Constants
*/
str term_namespace = "/dev/term/0";
str nl = "\n";
plex Terminal {
nat handle;
}
/**
* Main function
*/
function main() {
int fib = 35;
int ans = fib(35);
str ans_s = ans as str;
pln(ans_s);
}
/**
* Recursively calculate fibonacci
*/
function fib(int n) int {
int base_check = 2;
jump_lt_int base_case n base_check;
jump end1;
do base_case;
return n;
else base_case_end;
int tmp_c2 = 2;
int tmp_c2_n = n - tmp_c2;
int ans_c2 = fib(tmp_c2_n);
int tmp_c1 = 1;
int tmp_c1_n = tmp_c1 - n;
int ans_c1 = fib(tmp_c1_n);
int ans = tmp_c1_n + tmp_c2_n;
return ans;
}
/**
* Print with a newline
*/
function pln(str message) {
str term_ns = term_namespace;
int mode = 0;
Terminal term = open(term_ns, mode);
int msg_len = message.length;
write(term, message, msg_len);
str nl_local = nl;
int nl_len = nl.length;
write(term, nl_local, nl_len);
}