Compiler of Flecha AST (generated by https://gitlab.com/trimegisto/parser-flecha) to Mamarracho Language
- Install sbt
- Run
git clone https://gitlab.com/trimegisto/compiler-flecha/
- Run
sbt
- Run scala console
- Run
FlechaRunner.compile(path_of_input)
---- Primitiva: GE
def printBool x =
case x
| True -> (unsafePrintChar 'T'; unsafePrintChar '\n')
| False -> (unsafePrintChar 'F'; unsafePrintChar '\n')
def main =
printBool (10 >= 9);
printBool (10 >= 10);
printBool (10 >= 11)
scala> FlechaRunner.compile("src/utils/testCases/input/test01.input")
jump(main)
rtn0:
mov_reg($fun, @fun)
mov_reg($arg, @arg)
mov_reg($r3, $arg)
mov_reg($r4, $r3)
mov_reg($val, $r4)
load($tag, $val, 0)
mov_int($test, 4)
jump_eq($tag, $test, branch1)
mov_int($test, 5)
jump_eq($tag, $test, branch2)
branch1:
alloc($r5, 2)
mov_int($t, 2)
store($r5, 0, $t)
mov_int($t, 84)
store($r5, 1, $t)
load($r7, $r5, 1)
print_char($r7)
alloc($r6, 2)
mov_int($t, 2)
store($r6, 0, $t)
mov_int($t, 10)
store($r6, 1, $t)
load($r8, $r6, 1)
print_char($r8)
mov_reg($r2, $r6)
jump(END_CASE1)
branch2:
alloc($r9, 2)
mov_int($t, 2)
store($r9, 0, $t)
mov_int($t, 70)
store($r9, 1, $t)
load($r11, $r9, 1)
print_char($r11)
alloc($r10, 2)
mov_int($t, 2)
store($r10, 0, $t)
mov_int($t, 10)
store($r10, 1, $t)
load($r12, $r10, 1)
print_char($r12)
mov_reg($r2, $r10)
jump(END_CASE1)
END_CASE1:
mov_reg(@res, $r2)
return()
main:
alloc($r1, 2)
mov_int($t, 3)
store($r1, 0, $t)
mov_label($t, rtn0)
store($r1, 1, $t)
mov_reg(@printBool, $r1)
mov_reg($r16, $r1)
alloc($r18, 2)
mov_int($t, 1)
store($r18, 0, $t)
mov_int($t, 10)
store($r18, 1, $t)
alloc($r19, 2)
mov_int($t, 1)
store($r19, 0, $t)
mov_int($t, 9)
store($r19, 1, $t)
load($r20, $r18, 1)
load($r21, $r19, 1)
jump_eq($r21, $r20, branch3)
jump_lt($r21, $r20, branch3)
jump(branch4)
branch3:
alloc($r17, 1)
mov_int($t, 4)
store($r17, 0, $t)
jump(END_CASE2)
branch4:
alloc($r17, 1)
mov_int($t, 5)
store($r17, 0, $t)
jump(END_CASE2)
END_CASE2:
mov_reg(@fun, $r16)
mov_reg(@arg, $r17)
load($t, $r16, 1)
icall($t)
mov_reg($r14, @res)
mov_reg($r24, $r1)
alloc($r26, 2)
mov_int($t, 1)
store($r26, 0, $t)
mov_int($t, 10)
store($r26, 1, $t)
alloc($r27, 2)
mov_int($t, 1)
store($r27, 0, $t)
mov_int($t, 10)
store($r27, 1, $t)
load($r28, $r26, 1)
load($r29, $r27, 1)
jump_eq($r29, $r28, branch5)
jump_lt($r29, $r28, branch5)
jump(branch6)
branch5:
alloc($r25, 1)
mov_int($t, 4)
store($r25, 0, $t)
jump(END_CASE3)
branch6:
alloc($r25, 1)
mov_int($t, 5)
store($r25, 0, $t)
jump(END_CASE3)
END_CASE3:
mov_reg(@fun, $r24)
mov_reg(@arg, $r25)
load($t, $r24, 1)
icall($t)
mov_reg($r22, @res)
mov_reg($r30, $r1)
alloc($r32, 2)
mov_int($t, 1)
store($r32, 0, $t)
mov_int($t, 10)
store($r32, 1, $t)
alloc($r33, 2)
mov_int($t, 1)
store($r33, 0, $t)
mov_int($t, 11)
store($r33, 1, $t)
load($r34, $r32, 1)
load($r35, $r33, 1)
jump_eq($r35, $r34, branch7)
jump_lt($r35, $r34, branch7)
jump(branch8)
branch7:
alloc($r31, 1)
mov_int($t, 4)
store($r31, 0, $t)
jump(END_CASE4)
branch8:
alloc($r31, 1)
mov_int($t, 5)
store($r31, 0, $t)
jump(END_CASE4)
END_CASE4:
mov_reg(@fun, $r30)
mov_reg(@arg, $r31)
load($t, $r30, 1)
icall($t)
mov_reg($r23, @res)
mov_reg($r15, $r23)
mov_reg($r13, $r15)
mov_reg(@main, $r13)