3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

paiza.ioでelixir その273

Posted at

概要

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



成果物

以上。

3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?