Skip to content

Commit 32df14b

Browse files
authored
feat(compiler): Allow compilation of empty programs (#1336)
1 parent 20050d2 commit 32df14b

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

compiler/src/parsing/parser.mly

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,3 +712,4 @@ toplevel_stmts:
712712

713713
program:
714714
| opt_eols toplevel_stmts EOF { make_program $2 }
715+
| opt_eols EOF { make_program [] }
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
basic functionality › nil
2+
(module
3+
(type $none_=>_i32 (func (result i32)))
4+
(type $none_=>_none (func))
5+
(import \"_grainEnv\" \"mem\" (memory $0 0))
6+
(import \"_grainEnv\" \"tbl\" (table $tbl 0 funcref))
7+
(import \"_grainEnv\" \"relocBase\" (global $relocBase_0 i32))
8+
(import \"_grainEnv\" \"moduleRuntimeId\" (global $moduleRuntimeId_0 i32))
9+
(global $GRAIN$TABLE_SIZE i32 (i32.const 0))
10+
(elem $elem (global.get $relocBase_0))
11+
(export \"memory\" (memory $0))
12+
(export \"_gmain\" (func $_gmain))
13+
(export \"_start\" (func $_start))
14+
(export \"GRAIN$TABLE_SIZE\" (global $GRAIN$TABLE_SIZE))
15+
(func $_gmain (result i32)
16+
(local $0 i32)
17+
(local $1 i32)
18+
(local $2 i32)
19+
(local $3 i64)
20+
(local $4 f32)
21+
(local $5 f64)
22+
(return
23+
(block $cleanup_locals.2 (result i32)
24+
(local.set $0
25+
(block $compile_block.1 (result i32)
26+
(i32.const 1879048190)
27+
)
28+
)
29+
(local.get $0)
30+
)
31+
)
32+
)
33+
(func $_start
34+
(drop
35+
(call $_gmain)
36+
)
37+
)
38+
;; custom section \"cmi\", size 235
39+
)

compiler/test/suites/basic_functionality.re

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ describe("basic functionality", ({test, testSkip}) => {
1010
let assertCompileError = makeCompileErrorRunner(test);
1111
let assertRunError = makeErrorRunner(test_or_skip);
1212

13+
assertSnapshot("nil", "");
1314
assertSnapshot("forty", "let x = 40; x");
1415
assertSnapshot("neg", "-40");
1516
assertSnapshot("simple_min", "-1073741824");

0 commit comments

Comments
 (0)