~boringcactus/crowbar-reference-compiler

ref: 960e8c898dc0826d6dd5991f087fcd9d3ee6fcd1 crowbar-reference-compiler/tests/test_hello_world.py -rw-r--r-- 753 bytes
960e8c89 — Melody Horn fix some typing edge cases 1 year, 6 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import unittest

from crowbar_reference_compiler import build_ast, build_ssa, parse_header, parse_implementation, scan


class TestHelloWorld(unittest.TestCase):
    def test_ssa(self):
        code = r"""
//include "stdio.hro";

int32 main() {
    printf("Hello, world!\n");
    return 0;
}
"""
        tokens = scan(code)
        parse_tree = parse_implementation(tokens)
        ast = build_ast(parse_tree, [])
        actual_ssa = build_ssa(ast)
        expected_ssa = r"""
data $data0 = { b "Hello, world!\n", b 0 }

export function l $main() {
@start
    %t0 =l copy $data0
    call $printf(l %t0, ...)
    %t1 =l copy 0
    ret %t1
}
""".strip()
        self.assertEqual(expected_ssa, actual_ssa)


if __name__ == '__main__':
    unittest.main()