Add region to block SExpr node

This commit is contained in:
Anthony Bullard 2025-05-18 08:52:39 -05:00
parent 7fb647faa2
commit c9795890b5
No known key found for this signature in database
12 changed files with 264 additions and 236 deletions

View file

@ -2214,15 +2214,19 @@ pub const NodeStore = struct {
pub fn toSExpr(self: @This(), env: *base.ModuleEnv, ir: *IR, line_starts: std.ArrayList(u32)) sexpr.Expr { pub fn toSExpr(self: @This(), env: *base.ModuleEnv, ir: *IR, line_starts: std.ArrayList(u32)) sexpr.Expr {
var block_node = sexpr.Expr.init(env.gpa, "block"); var block_node = sexpr.Expr.init(env.gpa, "block");
block_node.appendRegionChild(env.gpa, ir.regionInfo(self.region, line_starts));
var statements_node = sexpr.Expr.init(env.gpa, "statements");
for (ir.store.statementSlice(self.statements)) |stmt_idx| { for (ir.store.statementSlice(self.statements)) |stmt_idx| {
const stmt = ir.store.getStatement(stmt_idx); const stmt = ir.store.getStatement(stmt_idx);
var stmt_node = stmt.toSExpr(env, ir, line_starts); var stmt_node = stmt.toSExpr(env, ir, line_starts);
block_node.appendNodeChild(env.gpa, &stmt_node); statements_node.appendNodeChild(env.gpa, &stmt_node);
} }
block_node.appendNodeChild(env.gpa, &statements_node);
return block_node; return block_node;
} }
}; };

View file

@ -8,5 +8,7 @@ PARSER: missing_header
~~~TOKENS ~~~TOKENS
Int(1:1-1:2),OpenCurly(1:2-1:3),EndOfFile(1:3-1:3), Int(1:1-1:2),OpenCurly(1:2-1:3),EndOfFile(1:3-1:3),
~~~PARSE ~~~PARSE
(file (malformed_header (1:1-1:2) "missing_header") (block)) (file
(malformed_header (1:1-1:2) "missing_header")
(block (1:2-1:3) (statements)))
~~~END ~~~END

View file

@ -45,13 +45,14 @@ CloseCurly(12:1-12:2),EndOfFile(12:2-12:2),
(ident (8:1-8:6) "main!") (ident (8:1-8:6) "main!")
(lambda (8:9-12:2) (lambda (8:9-12:2)
(args (underscore)) (args (underscore))
(block (block (8:13-12:2)
(statements
(decl (9:2-9:17) (decl (9:2-9:17)
(ident (9:2-9:7) "world") (ident (9:2-9:7) "world")
(string (9:10-9:17) (string_part (9:11-9:16) "World"))) (string (9:10-9:17) (string_part (9:11-9:16) "World")))
(apply (11:2-11:31) (apply (11:2-11:31)
(ident (11:2-11:14) "Stdout" ".line!") (ident (11:2-11:14) "Stdout" ".line!")
(string (11:15-11:30) (string_part (11:16-11:29) "Hello, world!"))))))) (string (11:15-11:30) (string_part (11:16-11:29) "Hello, world!"))))))))
~~~FORMATTED ~~~FORMATTED
NO CHANGE NO CHANGE
~~~END ~~~END

View file

@ -28,7 +28,8 @@ CloseCurly(7:5-7:6),EndOfFile(7:6-7:6),
(if_then_else (3:7-7:6) (if_then_else (3:7-7:6)
(ident (3:10-3:14) "" "true") (ident (3:10-3:14) "" "true")
(tag (3:15-3:16) "A") (tag (3:15-3:16) "A")
(block (tag (6:5-6:6) "B"))))) (block (5:10-7:6)
(statements (tag (6:5-6:6) "B"))))))
~~~FORMATTED ~~~FORMATTED
module [foo] module [foo]

View file

@ -22,8 +22,10 @@ CloseCurly(7:3-7:4),EndOfFile(7:4-7:4),
~~~PARSE ~~~PARSE
(if_then_else (1:1-7:4) (if_then_else (1:1-7:4)
(ident (2:2-2:6) "" "bool") (ident (2:2-2:6) "" "bool")
(block (int (4:4-4:5) "1")) (block (3:3-5:4)
(block (int (6:4-6:5) "2"))) (statements (int (4:4-4:5) "1")))
(block (5:10-7:4)
(statements (int (6:4-6:5) "2"))))
~~~FORMATTED ~~~FORMATTED
NO CHANGE NO CHANGE
~~~END ~~~END

View file

@ -22,8 +22,10 @@ CloseCurly(7:3-7:4),EndOfFile(7:4-7:4),
~~~PARSE ~~~PARSE
(if_then_else (1:1-7:4) (if_then_else (1:1-7:4)
(ident (2:2-2:6) "" "bool") (ident (2:2-2:6) "" "bool")
(block (int (4:4-4:5) "1")) (block (3:3-5:4)
(block (int (6:4-6:5) "2"))) (statements (int (4:4-4:5) "1")))
(block (5:10-7:4)
(statements (int (6:4-6:5) "2"))))
~~~FORMATTED ~~~FORMATTED
NO CHANGE NO CHANGE
~~~END ~~~END

View file

@ -26,8 +26,10 @@ CloseCurly(9:5-9:6),EndOfFile(9:6-9:6),
~~~PARSE ~~~PARSE
(if_then_else (1:1-9:6) (if_then_else (1:1-9:6)
(ident (2:2-2:6) "" "bool") (ident (2:2-2:6) "" "bool")
(block (int (4:4-4:5) "1")) (block (3:3-5:4)
(block (int (8:6-8:7) "2"))) (statements (int (4:4-4:5) "1")))
(block (7:5-9:6)
(statements (int (8:6-8:7) "2"))))
~~~FORMATTED ~~~FORMATTED
NO CHANGE NO CHANGE
~~~END ~~~END

View file

@ -14,7 +14,8 @@ CloseCurly(3:1-3:2),KwElse(3:3-3:7),Int(3:8-3:9),EndOfFile(3:9-3:9),
~~~PARSE ~~~PARSE
(if_then_else (1:1-3:9) (if_then_else (1:1-3:9)
(ident (1:4-1:8) "" "bool") (ident (1:4-1:8) "" "bool")
(block (int (2:2-2:3) "1")) (block (1:9-3:2)
(statements (int (2:2-2:3) "1")))
(int (3:8-3:9) "2")) (int (3:8-3:9) "2"))
~~~FORMATTED ~~~FORMATTED
NO CHANGE NO CHANGE

View file

@ -14,7 +14,8 @@ CloseCurly(3:1-3:2),KwElse(3:3-3:7),Int(3:8-3:9),EndOfFile(3:9-3:9),
~~~PARSE ~~~PARSE
(if_then_else (1:1-3:9) (if_then_else (1:1-3:9)
(ident (1:4-1:8) "" "bool") (ident (1:4-1:8) "" "bool")
(block (int (2:2-2:3) "1")) (block (1:9-3:2)
(statements (int (2:2-2:3) "1")))
(int (3:8-3:9) "2")) (int (3:8-3:9) "2"))
~~~FORMATTED ~~~FORMATTED
NO CHANGE NO CHANGE

View file

@ -18,8 +18,10 @@ CloseCurly(5:1-5:2),EndOfFile(5:2-5:2),
~~~PARSE ~~~PARSE
(if_then_else (1:1-5:2) (if_then_else (1:1-5:2)
(ident (1:4-1:8) "" "bool") (ident (1:4-1:8) "" "bool")
(block (int (2:2-2:3) "1")) (block (1:9-3:2)
(block (int (4:2-4:3) "2"))) (statements (int (2:2-2:3) "1")))
(block (3:8-5:2)
(statements (int (4:2-4:3) "2"))))
~~~FORMATTED ~~~FORMATTED
NO CHANGE NO CHANGE
~~~END ~~~END

View file

@ -18,8 +18,10 @@ CloseCurly(5:1-5:2),EndOfFile(5:2-5:2),
~~~PARSE ~~~PARSE
(if_then_else (1:1-5:2) (if_then_else (1:1-5:2)
(ident (1:4-1:8) "" "bool") (ident (1:4-1:8) "" "bool")
(block (int (2:2-2:3) "1")) (block (1:9-3:2)
(block (int (4:2-4:3) "2"))) (statements (int (2:2-2:3) "1")))
(block (3:8-5:2)
(statements (int (4:2-4:3) "2"))))
~~~FORMATTED ~~~FORMATTED
NO CHANGE NO CHANGE
~~~END ~~~END

View file

@ -541,20 +541,23 @@ CloseCurly(202:1-202:2),EndOfFile(202:2-202:2),
(ident (68:1-68:8) "add_one") (ident (68:1-68:8) "add_one")
(lambda (68:11-78:2) (lambda (68:11-78:2)
(args (ident (68:12-68:15) "num")) (args (ident (68:12-68:15) "num"))
(block (block (68:17-78:2)
(statements
(decl (69:2-69:11) (decl (69:2-69:11)
(ident (69:2-69:7) "other") (ident (69:2-69:7) "other")
(int (69:10-69:11) "1")) (int (69:10-69:11) "1"))
(if_then_else (70:2-78:2) (if_then_else (70:2-78:2)
(ident (70:5-70:8) "" "num") (ident (70:5-70:8) "" "num")
(block (block (70:9-74:3)
(statements
(dbg (dbg
(apply (72:4-72:15) (apply (72:4-72:15)
(ident (72:4-72:13) "" "some_func"))) (ident (72:4-72:13) "" "some_func")))
(int (73:3-73:4) "0")) (int (73:3-73:4) "0")))
(block (block (74:9-77:3)
(statements
(dbg (int (75:7-75:10) "123")) (dbg (int (75:7-75:10) "123"))
(ident (76:3-76:8) "" "other")))))) (ident (76:3-76:8) "" "other"))))))))
(decl (80:1-140:7) (decl (80:1-140:7)
(ident (80:1-80:11) "match_time") (ident (80:1-80:11) "match_time")
(lambda (80:14-140:7) (lambda (80:14-140:7)
@ -569,21 +572,23 @@ CloseCurly(202:1-202:2),EndOfFile(202:2-202:2),
(tag (85:3-85:7) "Blue") (tag (85:3-85:7) "Blue")
(tag (85:10-85:15) "Green") (tag (85:10-85:15) "Green")
(tag (85:18-85:21) "Red")) (tag (85:18-85:21) "Red"))
(block (block (85:25-88:4)
(statements
(decl (86:4-86:10) (decl (86:4-86:10)
(ident (86:4-86:5) "x") (ident (86:4-86:5) "x")
(int (86:8-86:10) "12")) (int (86:8-86:10) "12"))
(ident (87:4-87:5) "" "x"))) (ident (87:4-87:5) "" "x"))))
(branch (89:3-97:8) (branch (89:3-97:8)
(alternatives (alternatives
(tag (89:3-89:7) "Blue") (tag (89:3-89:7) "Blue")
(tag (91:4-91:9) "Green") (tag (91:4-91:9) "Green")
(tag (92:5-92:8) "Red")) (tag (92:5-92:8) "Red"))
(block (block (93:7-96:5)
(statements
(decl (94:5-94:11) (decl (94:5-94:11)
(ident (94:5-94:6) "x") (ident (94:5-94:6) "x")
(int (94:9-94:11) "12")) (int (94:9-94:11) "12"))
(ident (95:5-95:6) "" "x"))) (ident (95:5-95:6) "" "x"))))
(branch (97:3-99:4) (branch (97:3-99:4)
(ident (97:3-97:8) "lower") (ident (97:3-97:8) "lower")
(int (98:7-98:8) "1")) (int (98:7-98:8) "1"))
@ -715,7 +720,8 @@ CloseCurly(202:1-202:2),EndOfFile(202:2-202:2),
(ident (144:1-144:6) "main!") (ident (144:1-144:6) "main!")
(lambda (144:9-196:2) (lambda (144:9-196:2)
(args (underscore)) (args (underscore))
(block (block (144:13-196:2)
(statements
(decl (145:2-145:17) (decl (145:2-145:17)
(ident (145:2-145:7) "world") (ident (145:2-145:7) "world")
(string (145:10-145:17) (string_part (145:11-145:16) "World"))) (string (145:10-145:17) (string_part (145:11-145:16) "World")))
@ -763,7 +769,8 @@ CloseCurly(202:1-202:2),EndOfFile(202:2-202:2),
(for (for
(ident (174:6-174:7) "n") (ident (174:6-174:7) "n")
(ident (174:11-174:15) "" "list") (ident (174:11-174:15) "" "list")
(block (block (174:16-177:3)
(statements
(apply (175:3-175:43) (apply (175:3-175:43)
(ident (175:3-175:15) "Stdout" ".line!") (ident (175:3-175:15) "Stdout" ".line!")
(string (175:16-175:42) (string (175:16-175:42)
@ -777,7 +784,7 @@ CloseCurly(202:1-202:2),EndOfFile(202:2-202:2),
(binop (binop
"+" "+"
(ident (176:12-176:18) "" "number") (ident (176:12-176:18) "" "number")
(ident (176:21-176:22) "" "n"))))) (ident (176:21-176:22) "" "n"))))))
(decl (178:2-178:71) (decl (178:2-178:71)
(ident (178:2-178:8) "record") (ident (178:2-178:8) "record")
(record (178:11-178:71) (record (178:11-178:71)
@ -901,9 +908,10 @@ CloseCurly(202:1-202:2),EndOfFile(202:2-202:2),
(apply (193:4-193:21) (apply (193:4-193:21)
(ident (193:4-193:13) "Num" ".toStr") (ident (193:4-193:13) "Num" ".toStr")
(ident (193:14-193:20) "" "number")) (ident (193:14-193:20) "" "number"))
(string_part (194:4-194:17) " as a string?")))))) (string_part (194:4-194:17) " as a string?")))))))
(expect (198:1-202:2) (expect (198:1-202:2)
(block (block (198:8-202:2)
(statements
(decl (199:2-199:9) (decl (199:2-199:9)
(ident (199:2-199:5) "foo") (ident (199:2-199:5) "foo")
(int (199:8-199:9) "1")) (int (199:8-199:9) "1"))
@ -913,7 +921,7 @@ CloseCurly(202:1-202:2),EndOfFile(202:2-202:2),
(binop (binop
"==" "=="
(ident (201:2-201:6) "" "blah") (ident (201:2-201:6) "" "blah")
(ident (201:10-201:13) "" "foo"))))) (ident (201:10-201:13) "" "foo"))))))
~~~FORMATTED ~~~FORMATTED
NO CHANGE NO CHANGE
~~~END ~~~END