@@ -58,17 +58,8 @@ pub const StmtTag = enum(u8) {
58
58
};
59
59
60
60
/// Calculate the starting offset for expression tags
61
- const EXPR_TAG_START = blk : {
62
- // Get the maximum value from StmtTag enum
63
- var max : u8 = 0 ;
64
- for (std .meta .fields (StmtTag )) | field | {
65
- if (field .value > max ) {
66
- max = @intCast (field .value );
67
- }
68
- }
69
- // Expression tags start after the highest statement tag
70
- break :blk max + 1 ;
71
- };
61
+ /// We start at 100 to avoid collision with AST2.Node.Tag values (which go up to ~68)
62
+ const EXPR_TAG_START = 100 ;
72
63
73
64
/// CIR Expression tags - start after statement tags
74
65
pub const ExprTag = enum (u8 ) {
@@ -123,17 +114,8 @@ pub const ExprTag = enum(u8) {
123
114
};
124
115
125
116
/// Calculate the starting offset for pattern tags
126
- const PATT_TAG_START = blk : {
127
- // Get the maximum value from ExprTag enum
128
- var max : u8 = 0 ;
129
- for (std .meta .fields (ExprTag )) | field | {
130
- if (field .value > max ) {
131
- max = @intCast (field .value );
132
- }
133
- }
134
- // Pattern tags start after the highest expression tag
135
- break :blk max + 1 ;
136
- };
117
+ /// We start at 150 (EXPR_TAG_START=100 + ~48 ExprTag values + buffer)
118
+ const PATT_TAG_START = 150 ;
137
119
138
120
/// CIR Pattern tags - start after expression tags
139
121
pub const PattTag = enum (u8 ) {
@@ -355,7 +337,8 @@ pub fn getNodeTagPtr(self: *CIR, idx: AST2.Node.Idx) *AST2.Node.Tag {
355
337
356
338
/// Get an immutable node
357
339
pub fn getNode (self : * const CIR , idx : AST2.Node.Idx ) AST2.Node {
358
- return self .ast .* .nodes .get (@enumFromInt (@intFromEnum (idx )));
340
+ const node = self .ast .* .nodes .get (@enumFromInt (@intFromEnum (idx )));
341
+ return node ;
359
342
}
360
343
361
344
/// Mutate a node's tag in place to a CIR statement tag
@@ -974,6 +957,18 @@ fn canonicalizeLambdaParams(self: *CIR, allocator: Allocator, node_idx: AST2.Nod
974
957
try self .scope_state .addIdent (allocator , node .payload .ident , patt_idx );
975
958
try self .scope_state .recordVarPattern (allocator , patt_idx );
976
959
},
960
+ .tuple_literal = > {
961
+ // Multiple parameters passed as a tuple: |a, b| -> parsed as tuple_literal(a, b)
962
+ // Iterate through each element and canonicalize as a parameter
963
+ const nodes_idx = node .payload .nodes ;
964
+ if (! nodes_idx .isNil ()) {
965
+ var iter = self .ast .* .node_slices .nodes (& nodes_idx );
966
+ while (iter .next ()) | param_node | {
967
+ try self .canonicalizeLambdaParams (allocator , param_node , raw_src , idents );
968
+ }
969
+ }
970
+ // Don't mutate the tuple_literal node itself - it's just a container for params
971
+ },
977
972
.binop_pipe = > {
978
973
// Multiple parameters: |a| b | rest
979
974
// This is nested binop_pipe for multiple parameters
@@ -2583,7 +2578,7 @@ test "CIR2 error: expression in statement context" {
2583
2578
defer byte_slices .entries .deinit (allocator );
2584
2579
2585
2580
// Create a number literal node (expression)
2586
- const node_idx = try ast_ptr .appendNode (allocator , Position { .offset = 0 }, .num_literal_i32 , .{ .num_literal_i32 = 42 });
2581
+ const node_idx = try ast_ptr .appendNode (allocator , Region { . start = Position { .offset = 0 }, . end = Position { . offset = 2 } }, .num_literal_i32 , .{ .num_literal_i32 = 42 });
2587
2582
2588
2583
// Create a TypeStore for testing
2589
2584
var types_store = try TypeStore .initCapacity (allocator , 100 , 10 );
@@ -2632,7 +2627,7 @@ test "CIR2 demonstrates in-place tag mutation" {
2632
2627
2633
2628
// Create an identifier node
2634
2629
const ident_idx = Ident.Idx { .attributes = .{ .effectful = false , .ignored = false , .reassignable = false }, .idx = 1 };
2635
- const node_idx = try ast_ptr .appendNode (allocator , Position { .offset = 0 }, .lc , .{ .ident = ident_idx });
2630
+ const node_idx = try ast_ptr .appendNode (allocator , Region { . start = Position { .offset = 0 }, . end = Position { . offset = 3 } }, .lc , .{ .ident = ident_idx });
2636
2631
2637
2632
// Verify initial AST tag
2638
2633
const initial_node = ast_ptr .nodes .get (@enumFromInt (@intFromEnum (node_idx )));
@@ -2734,9 +2729,9 @@ test "sign bit encoding: mutable vs immutable pattern canonicalization" {
2734
2729
// Create two identifier nodes
2735
2730
const ident_idx = Ident.Idx { .attributes = .{ .effectful = false , .ignored = false , .reassignable = false }, .idx = 1 };
2736
2731
2737
- const node1_idx = try ast .appendNode (allocator , Position { .offset = 0 }, .lc , .{ .ident = ident_idx });
2732
+ const node1_idx = try ast .appendNode (allocator , Region { . start = Position { .offset = 0 }, . end = Position { . offset = 3 } }, .lc , .{ .ident = ident_idx });
2738
2733
2739
- const node2_idx = try ast .appendNode (allocator , Position { .offset = 10 }, .lc , .{ .ident = ident_idx });
2734
+ const node2_idx = try ast .appendNode (allocator , Region { . start = Position { .offset = 10 }, . end = Position { . offset = 13 } }, .lc , .{ .ident = ident_idx });
2740
2735
2741
2736
// Canonicalize one as immutable, one as mutable
2742
2737
const immutable_patt = try cir .canonicalizePatt (allocator , node1_idx );
0 commit comments