Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print more node values in compiler debug ouptut #8

Merged
merged 2 commits into from
Sep 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,10 @@ impl Compiler {
idx, ast_node, self.spans[idx].start, self.spans[idx].end
));

if matches!(ast_node, AstNode::Name | AstNode::Variable) {
if matches!(
ast_node,
AstNode::Name | AstNode::Variable | AstNode::Int | AstNode::Float | AstNode::String
) {
result.push_str(&format!(
" \"{}\"",
String::from_utf8_lossy(self.get_span_contents(NodeId(idx)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@ expression: evaluate_example(path)
input_file: tests/binary_ops_exact.nu
---
==== COMPILER ====
0: Int (0 to 1)
0: Int (0 to 1) "1"
1: Equal (2 to 4)
2: Int (5 to 6)
2: Int (5 to 6) "1"
3: BinaryOp { lhs: NodeId(0), op: NodeId(1), rhs: NodeId(2) } (0 to 6)
4: True (8 to 12)
5: List([NodeId(4)]) (7 to 12)
6: Append (14 to 16)
7: False (17 to 22)
8: BinaryOp { lhs: NodeId(5), op: NodeId(6), rhs: NodeId(7) } (7 to 22)
9: Int (23 to 24)
9: Int (23 to 24) "1"
10: Plus (25 to 26)
11: Int (27 to 28)
11: Int (27 to 28) "1"
12: BinaryOp { lhs: NodeId(9), op: NodeId(10), rhs: NodeId(11) } (23 to 28)
13: Float (29 to 32)
13: Float (29 to 32) "1.0"
14: Plus (33 to 34)
15: Float (35 to 38)
15: Float (35 to 38) "1.0"
16: BinaryOp { lhs: NodeId(13), op: NodeId(14), rhs: NodeId(15) } (29 to 38)
17: True (39 to 43)
18: Name (44 to 47) "and"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ expression: evaluate_example(path)
input_file: tests/binary_ops_mismatch.nu
---
==== COMPILER ====
0: String (0 to 3)
0: String (0 to 3) ""a""
1: Plus (4 to 5)
2: Float (6 to 9)
2: Float (6 to 9) "1.0"
3: BinaryOp { lhs: NodeId(0), op: NodeId(1), rhs: NodeId(2) } (0 to 9)
4: String (10 to 13)
4: String (10 to 13) ""a""
5: Append (14 to 16)
6: Float (17 to 20)
6: Float (17 to 20) "1.0"
7: BinaryOp { lhs: NodeId(4), op: NodeId(5), rhs: NodeId(6) } (10 to 20)
8: True (21 to 25)
9: Name (26 to 29) "and"
10: String (30 to 33)
10: String (30 to 33) ""a""
11: Block(BlockId(0)) (0 to 34)
==== SCOPE ====
0: Frame Scope, node_id: NodeId(11) (empty)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,46 +4,46 @@ expression: evaluate_example(path)
input_file: tests/binary_ops_subtypes.nu
---
==== COMPILER ====
0: Int (0 to 1)
0: Int (0 to 1) "1"
1: Equal (2 to 4)
2: Float (5 to 8)
2: Float (5 to 8) "1.0"
3: BinaryOp { lhs: NodeId(0), op: NodeId(1), rhs: NodeId(2) } (0 to 8)
4: String (9 to 12)
4: String (9 to 12) ""a""
5: Equal (13 to 15)
6: Float (16 to 19)
6: Float (16 to 19) "1.0"
7: BinaryOp { lhs: NodeId(4), op: NodeId(5), rhs: NodeId(6) } (9 to 19)
8: Int (20 to 21)
8: Int (20 to 21) "1"
9: Plus (22 to 23)
10: Float (24 to 27)
10: Float (24 to 27) "1.0"
11: BinaryOp { lhs: NodeId(8), op: NodeId(9), rhs: NodeId(10) } (20 to 27)
12: Int (29 to 30)
12: Int (29 to 30) "1"
13: List([NodeId(12)]) (28 to 30)
14: Append (32 to 34)
15: Float (35 to 38)
15: Float (35 to 38) "1.0"
16: BinaryOp { lhs: NodeId(13), op: NodeId(14), rhs: NodeId(15) } (28 to 38)
17: Float (40 to 43)
18: Int (44 to 45)
17: Float (40 to 43) "1.0"
18: Int (44 to 45) "1"
19: List([NodeId(17), NodeId(18)]) (39 to 45)
20: Append (47 to 49)
21: String (50 to 53)
21: String (50 to 53) ""a""
22: BinaryOp { lhs: NodeId(19), op: NodeId(20), rhs: NodeId(21) } (39 to 53)
23: Int (56 to 57)
23: Int (56 to 57) "1"
24: List([NodeId(23)]) (55 to 57)
25: Int (60 to 61)
25: Int (60 to 61) "2"
26: List([NodeId(25)]) (59 to 61)
27: List([NodeId(24), NodeId(26)]) (54 to 62)
28: Append (64 to 66)
29: Int (69 to 70)
29: Int (69 to 70) "3"
30: List([NodeId(29)]) (68 to 70)
31: List([NodeId(30)]) (67 to 71)
32: BinaryOp { lhs: NodeId(27), op: NodeId(28), rhs: NodeId(31) } (54 to 71)
33: Int (75 to 76)
33: Int (75 to 76) "1"
34: List([NodeId(33)]) (74 to 76)
35: Int (79 to 80)
35: Int (79 to 80) "2"
36: List([NodeId(35)]) (78 to 80)
37: List([NodeId(34), NodeId(36)]) (73 to 81)
38: Append (83 to 85)
39: Float (88 to 91)
39: Float (88 to 91) "3.0"
40: List([NodeId(39)]) (87 to 91)
41: List([NodeId(40)]) (86 to 92)
42: BinaryOp { lhs: NodeId(37), op: NodeId(38), rhs: NodeId(41) } (73 to 92)
Expand Down
14 changes: 7 additions & 7 deletions src/snapshots/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ input_file: tests/for.nu
---
==== COMPILER ====
0: Variable (4 to 5) "x"
1: Int (8 to 9)
1: Int (8 to 9) "0"
2: Let { variable_name: NodeId(0), ty: None, initializer: NodeId(1), is_mutable: true } (0 to 9)
3: Variable (14 to 15) "i"
4: Int (20 to 21)
5: Int (22 to 23)
6: Int (24 to 25)
4: Int (20 to 21) "1"
5: Int (22 to 23) "2"
6: Int (24 to 25) "3"
7: List([NodeId(4), NodeId(5), NodeId(6)]) (19 to 25)
8: Variable (33 to 35) "$x"
9: Assignment (36 to 37)
Expand All @@ -22,9 +22,9 @@ input_file: tests/for.nu
15: Block(BlockId(0)) (27 to 47)
16: For { variable: NodeId(3), range: NodeId(7), block: NodeId(15) } (10 to 47)
17: Variable (53 to 55) "$i"
18: Int (60 to 61)
19: Int (62 to 63)
20: Int (64 to 65)
18: Int (60 to 61) "4"
19: Int (62 to 63) "5"
20: Int (64 to 65) "6"
21: List([NodeId(18), NodeId(19), NodeId(20)]) (59 to 65)
22: Variable (73 to 75) "$x"
23: Assignment (76 to 77)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@ input_file: tests/for_break_continue.nu
---
==== COMPILER ====
0: Variable (4 to 5) "x"
1: Int (8 to 9)
1: Int (8 to 9) "0"
2: Let { variable_name: NodeId(0), ty: None, initializer: NodeId(1), is_mutable: true } (0 to 9)
3: Variable (14 to 15) "i"
4: Int (20 to 21)
5: Int (22 to 23)
6: Int (24 to 25)
4: Int (20 to 21) "1"
5: Int (22 to 23) "2"
6: Int (24 to 25) "3"
7: List([NodeId(4), NodeId(5), NodeId(6)]) (19 to 25)
8: Variable (36 to 38) "$x"
9: GreaterThan (39 to 40)
10: Int (41 to 42)
10: Int (41 to 42) "2"
11: BinaryOp { lhs: NodeId(8), op: NodeId(9), rhs: NodeId(10) } (36 to 42)
12: Break (53 to 58)
13: Block(BlockId(0)) (43 to 64)
14: If { condition: NodeId(11), then_block: NodeId(13), else_block: None } (33 to 64)
15: Variable (73 to 75) "$i"
16: LessThan (76 to 77)
17: Int (78 to 79)
17: Int (78 to 79) "3"
18: BinaryOp { lhs: NodeId(15), op: NodeId(16), rhs: NodeId(17) } (73 to 79)
19: Continue (90 to 98)
20: Block(BlockId(1)) (80 to 104)
Expand Down
12 changes: 6 additions & 6 deletions src/snapshots/new_nu_parser__test__node_output@if_.nu.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@ input_file: tests/if_.nu
---
==== COMPILER ====
0: Variable (4 to 5) "x"
1: Int (8 to 11)
1: Int (8 to 11) "123"
2: Let { variable_name: NodeId(0), ty: None, initializer: NodeId(1), is_mutable: false } (0 to 11)
3: Variable (16 to 18) "$x"
4: LessThan (19 to 20)
5: Int (21 to 24)
5: Int (21 to 24) "100"
6: BinaryOp { lhs: NodeId(3), op: NodeId(4), rhs: NodeId(5) } (16 to 24)
7: Int (31 to 32)
7: Int (31 to 32) "5"
8: Block(BlockId(0)) (25 to 35)
9: Variable (43 to 45) "$x"
10: GreaterThan (46 to 47)
11: Int (48 to 51)
11: Int (48 to 51) "200"
12: BinaryOp { lhs: NodeId(9), op: NodeId(10), rhs: NodeId(11) } (43 to 51)
13: Int (58 to 59)
13: Int (58 to 59) "6"
14: Block(BlockId(1)) (52 to 62)
15: Int (73 to 74)
15: Int (73 to 74) "7"
16: Block(BlockId(2)) (67 to 76)
17: If { condition: NodeId(12), then_block: NodeId(14), else_block: Some(NodeId(16)) } (40 to 76)
18: If { condition: NodeId(6), then_block: NodeId(8), else_block: Some(NodeId(17)) } (13 to 76)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ expression: evaluate_example(path)
input_file: tests/invalid_range.nu
---
==== COMPILER ====
0: Int (0 to 1)
0: Int (0 to 1) "1"
1: Garbage (2 to 4)
2: Int (5 to 6)
2: Int (5 to 6) "2"
3: Block(BlockId(0)) (0 to 7)
==== COMPILER ERRORS ====
Error (NodeId 1): incomplete expression

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ input_file: tests/invalid_record.nu
---
==== COMPILER ====
0: Name (2 to 3) "a"
1: Int (5 to 6)
1: Int (5 to 6) "1"
2: Name (9 to 10) "b"
3: Garbage (11 to 12)
4: Garbage (13 to 13)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ input_file: tests/let_.nu
---
==== COMPILER ====
0: Variable (4 to 5) "x"
1: Int (8 to 11)
1: Int (8 to 11) "123"
2: Let { variable_name: NodeId(0), ty: None, initializer: NodeId(1), is_mutable: false } (0 to 11)
3: Variable (13 to 15) "$x"
4: Block(BlockId(0)) (0 to 15)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ input_file: tests/let_mismatch.nu
0: Variable (4 to 5) "x"
1: Name (7 to 13) "number"
2: Type { name: NodeId(1), params: None, optional: false } (7 to 13)
3: Int (16 to 18)
3: Int (16 to 18) "10"
4: Let { variable_name: NodeId(0), ty: Some(NodeId(2)), initializer: NodeId(3), is_mutable: false } (0 to 18)
5: Variable (32 to 33) "y"
6: Name (35 to 38) "any"
7: Type { name: NodeId(6), params: None, optional: false } (35 to 38)
8: String (41 to 47)
8: String (41 to 47) ""spam""
9: Let { variable_name: NodeId(5), ty: Some(NodeId(7)), initializer: NodeId(8), is_mutable: false } (28 to 47)
10: Variable (60 to 61) "z"
11: Name (63 to 69) "string"
12: Type { name: NodeId(11), params: None, optional: false } (63 to 69)
13: Int (72 to 75)
13: Int (72 to 75) "123"
14: Let { variable_name: NodeId(10), ty: Some(NodeId(12)), initializer: NodeId(13), is_mutable: false } (56 to 75)
15: Variable (91 to 92) "w"
16: Name (94 to 98) "list"
Expand All @@ -28,7 +28,7 @@ input_file: tests/let_mismatch.nu
21: Type { name: NodeId(17), params: Some(NodeId(20)), optional: false } (99 to 103)
22: Params([NodeId(21)]) (98 to 109)
23: Type { name: NodeId(16), params: Some(NodeId(22)), optional: false } (94 to 98)
24: String (116 to 119)
24: String (116 to 119) "'a'"
25: List([NodeId(24)]) (114 to 120)
26: List([NodeId(25)]) (112 to 122)
27: Let { variable_name: NodeId(15), ty: Some(NodeId(23)), initializer: NodeId(26), is_mutable: false } (87 to 122)
Expand Down
30 changes: 15 additions & 15 deletions src/snapshots/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@ expression: evaluate_example(path)
input_file: tests/list.nu
---
==== COMPILER ====
0: Int (1 to 2)
1: Int (4 to 5)
2: Int (7 to 8)
0: Int (1 to 2) "1"
1: Int (4 to 5) "2"
2: Int (7 to 8) "3"
3: List([NodeId(0), NodeId(1), NodeId(2)]) (0 to 8)
4: Int (11 to 12)
5: Int (13 to 14)
6: Int (15 to 16)
4: Int (11 to 12) "0"
5: Int (13 to 14) "1"
6: Int (15 to 16) "2"
7: List([NodeId(4), NodeId(5), NodeId(6)]) (10 to 16)
8: String (19 to 22)
9: String (23 to 26)
10: String (27 to 30)
8: String (19 to 22) ""0""
9: String (23 to 26) ""1""
10: String (27 to 30) ""2""
11: List([NodeId(8), NodeId(9), NodeId(10)]) (18 to 30)
12: Int (33 to 34)
13: Int (35 to 36)
14: Float (37 to 40)
12: Int (33 to 34) "0"
13: Int (35 to 36) "1"
14: Float (37 to 40) "2.2"
15: List([NodeId(12), NodeId(13), NodeId(14)]) (32 to 40)
16: Int (43 to 44)
17: Int (45 to 46)
18: String (47 to 50)
16: Int (43 to 44) "0"
17: Int (45 to 46) "1"
18: String (47 to 50) ""2""
19: List([NodeId(16), NodeId(17), NodeId(18)]) (42 to 50)
20: Block(BlockId(0)) (0 to 52)
==== SCOPE ====
Expand Down
4 changes: 2 additions & 2 deletions src/snapshots/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ input_file: tests/literals.nu
==== COMPILER ====
0: True (1 to 5)
1: Null (6 to 10)
2: Int (11 to 12)
2: Int (11 to 12) "1"
3: Name (13 to 16) "abc"
4: String (17 to 22)
4: String (17 to 22) ""foo""
5: List([NodeId(0), NodeId(1), NodeId(2), NodeId(3), NodeId(4)]) (0 to 22)
6: Block(BlockId(0)) (0 to 24)
==== SCOPE ====
Expand Down
6 changes: 3 additions & 3 deletions src/snapshots/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ input_file: tests/loop.nu
---
==== COMPILER ====
0: Variable (4 to 5) "x"
1: Int (8 to 9)
1: Int (8 to 9) "0"
2: Let { variable_name: NodeId(0), ty: None, initializer: NodeId(1), is_mutable: true } (0 to 9)
3: Variable (24 to 26) "$x"
4: GreaterThan (27 to 28)
5: Int (29 to 31)
5: Int (29 to 31) "10"
6: BinaryOp { lhs: NodeId(3), op: NodeId(4), rhs: NodeId(5) } (24 to 31)
7: Break (42 to 47)
8: Block(BlockId(0)) (32 to 53)
9: If { condition: NodeId(6), then_block: NodeId(8), else_block: None } (21 to 53)
10: Variable (59 to 61) "$x"
11: AddAssignment (62 to 64)
12: Int (65 to 66)
12: Int (65 to 66) "1"
13: BinaryOp { lhs: NodeId(10), op: NodeId(11), rhs: NodeId(12) } (59 to 66)
14: Block(BlockId(1)) (15 to 68)
15: Loop { block: NodeId(14) } (10 to 68)
Expand Down
4 changes: 2 additions & 2 deletions src/snapshots/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ expression: evaluate_example(path)
input_file: tests/math.nu
---
==== COMPILER ====
0: Int (0 to 1)
0: Int (0 to 1) "3"
1: Plus (2 to 3)
2: Int (4 to 5)
2: Int (4 to 5) "4"
3: BinaryOp { lhs: NodeId(0), op: NodeId(1), rhs: NodeId(2) } (0 to 5)
4: Block(BlockId(0)) (0 to 5)
==== SCOPE ====
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ expression: evaluate_example(path)
input_file: tests/math_precedence.nu
---
==== COMPILER ====
0: Int (0 to 1)
0: Int (0 to 1) "1"
1: Plus (2 to 3)
2: Int (4 to 5)
2: Int (4 to 5) "2"
3: Multiply (6 to 7)
4: Int (8 to 9)
4: Int (8 to 9) "3"
5: Plus (10 to 11)
6: Int (12 to 13)
6: Int (12 to 13) "4"
7: BinaryOp { lhs: NodeId(2), op: NodeId(3), rhs: NodeId(4) } (4 to 9)
8: BinaryOp { lhs: NodeId(0), op: NodeId(1), rhs: NodeId(7) } (0 to 9)
9: BinaryOp { lhs: NodeId(8), op: NodeId(5), rhs: NodeId(6) } (0 to 13)
Expand Down
6 changes: 3 additions & 3 deletions src/snapshots/new_nu_parser__test__node_output@mut_.nu.snap
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ input_file: tests/mut_.nu
0: Variable (4 to 5) "x"
1: Name (7 to 10) "int"
2: Type { name: NodeId(1), params: None, optional: false } (7 to 10)
3: Int (13 to 16)
3: Int (13 to 16) "123"
4: Let { variable_name: NodeId(0), ty: Some(NodeId(2)), initializer: NodeId(3), is_mutable: true } (0 to 16)
5: Variable (18 to 20) "$x"
6: Assignment (21 to 22)
7: Int (23 to 24)
7: Int (23 to 24) "3"
8: Plus (25 to 26)
9: Int (27 to 30)
9: Int (27 to 30) "456"
10: BinaryOp { lhs: NodeId(7), op: NodeId(8), rhs: NodeId(9) } (23 to 30)
11: BinaryOp { lhs: NodeId(5), op: NodeId(6), rhs: NodeId(10) } (18 to 30)
12: Block(BlockId(0)) (0 to 30)
Expand Down
Loading