Created
July 7, 2018 15:39
-
-
Save ilmoeuro/9c400e51997850ef4822d30ba66a4f4a to your computer and use it in GitHub Desktop.
Code generation goal for untyped language
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Result function1(Closure closure, Arguments arguments) { | |
Value print = get_closure_value(closure, 0); | |
pos("examples1.simp", 9); | |
Value i = make_number(99); | |
loop1: | |
pos("examples1.simp", 10); | |
Value aux1 = make_number(0); | |
Value aux2 = greater_than(i, aux1); | |
if (!is_true(aux2)) goto loop1_end; | |
pos("examples1.simp", 11); | |
call(print, i); | |
pos("examples1.simp", 12); | |
Value aux3 = make_string(" bottles of beer on the wall\n"); | |
call(print, aux3); | |
pos("examples1.simp", 13); | |
call(print, i); | |
pos("examples1.simp", 14); | |
Value aux4 = make_string(" bottles of beer\n"); | |
call(print, aux4); | |
pos("examples1.simp", 15); | |
Value aux5 = make_string("Take one down, pass it around"); | |
call(print, aux5); | |
pos("examples1.simp", 16); | |
Value aux6 = make_number(1); | |
i = subtract(i, aux6); | |
pos("examples1.simp", 17); | |
call(print, i); | |
pos("examples1.simp", 18); | |
Value aux7 = make_string(" bottles of beer on the wall\n"); | |
call(print, aux7); | |
goto loop1; | |
loop1_end: | |
return make_null(); | |
} | |
void module_examples1(Environment env) { | |
Value print = import(env, "std", "print"); | |
Closure the99bottles_closure = make_closure(); | |
set_closure_value(the99bottles_closure, 0, print); | |
Value the99bottles = make_function(function1, the99bottles_closure); | |
export(env, "examples1", "the99bottles", the99bottles); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import std { | |
print, | |
} | |
export the99bottles = () { | |
let i = 99; | |
while (i > 0) { | |
print(i); | |
print(" bottles of beer on the wall\n"); | |
print(i); | |
print(" bottles of beer\n"); | |
print("Take one down, pass it around"); | |
i = i - 1; | |
print(i); | |
print(" bottles of beer on the wall\n"); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment