概要
paiza.ioでelixirやってみた。
コンパイラ、見つけたのでやってみた。
codegenやってみた。
参考にしたページ
投入したコード
[
"top_stmts",
[
"func",
"main",
[
],
[
[
"var",
"a",
1
],
[
"while",
[
"==",
2,
3
],
[
[
"set",
"a",
[
"+",
"a",
4
]
],
[
"set",
"a",
[
"+",
"a",
5
]
]
]
]
]
]
]
実行結果
call main
exit
label main
push bp
mov bp sp
add sp -1
mov reg_a 1
mov [bp:-1] reg_a
label while_1
mov reg_a 2
push reg_a
mov reg_a 3
push reg_a
pop reg_b
pop reg_a
compare
jump_eq then_2
mov reg_a 0
jump end_eq_2
label then_2
mov reg_a 1
label end_eq_2
mov reg_b 0
compare
jump_eq end_while_1
mov reg_a [bp:-1]
push reg_a
mov reg_a 4
push reg_a
pop reg_b
pop reg_a
add reg_a reg_b
mov [bp:-1] reg_a
mov reg_a [bp:-1]
push reg_a
mov reg_a 5
push reg_a
pop reg_b
pop reg_a
add reg_a reg_b
mov [bp:-1] reg_a
jump while_1
label end_while_1
mov sp bp
pop bp
ret
#>builtins
label set_vram
push bp
mov bp sp
set_vram [bp:2] [bp:3]
mov sp bp
pop bp
ret
label get_vram
push bp
mov bp sp
get_vram [bp:2] reg_a
mov sp bp
pop bp
ret
#<builtins
成果物
以上。