| ... | @@ -657,6 +657,7 @@ const DocData = struct { | ... | @@ -657,6 +657,7 @@ const DocData = struct { |
| 657 | array: []usize, // index in `exprs` | 657 | array: []usize, // index in `exprs` |
| 658 | call: usize, // index in `calls` | 658 | call: usize, // index in `calls` |
| 659 | enumLiteral: []const u8, // direct value | 659 | enumLiteral: []const u8, // direct value |
| | 660 | alignOf: usize, // index in `exprs` |
| 660 | typeOf: usize, // index in `exprs` | 661 | typeOf: usize, // index in `exprs` |
| 661 | typeOf_peer: []usize, | 662 | typeOf_peer: []usize, |
| 662 | errorUnion: usize, // index in `exprs` | 663 | errorUnion: usize, // index in `exprs` |
| ... | @@ -665,6 +666,7 @@ const DocData = struct { | ... | @@ -665,6 +666,7 @@ const DocData = struct { |
| 665 | bitSizeOf: usize, // index in `exprs` | 666 | bitSizeOf: usize, // index in `exprs` |
| 666 | enumToInt: usize, // index in `exprs` | 667 | enumToInt: usize, // index in `exprs` |
| 667 | compileError: []const u8, | 668 | compileError: []const u8, |
| | 669 | errorSets: usize, |
| 668 | string: []const u8, // direct value | 670 | string: []const u8, // direct value |
| 669 | switchIndex: usize, // index in `exprs` | 671 | switchIndex: usize, // index in `exprs` |
| 670 | switchOp: SwitchOp, | 672 | switchOp: SwitchOp, |
| ... | @@ -693,9 +695,6 @@ const DocData = struct { | ... | @@ -693,9 +695,6 @@ const DocData = struct { |
| 693 | const SwitchOp = struct { | 695 | const SwitchOp = struct { |
| 694 | cases: []usize, | 696 | cases: []usize, |
| 695 | else_index: ?usize, | 697 | else_index: ?usize, |
| 696 | // body_cases: ?[]usize, | | |
| 697 | | | |
| 698 | // const Case = struct { lhs: Expr, rhs: Expr }; | | |
| 699 | }; | 698 | }; |
| 700 | const As = struct { | 699 | const As = struct { |
| 701 | typeRefArg: ?usize, // index in `exprs` | 700 | typeRefArg: ?usize, // index in `exprs` |
| ... | @@ -722,7 +721,7 @@ const DocData = struct { | ... | @@ -722,7 +721,7 @@ const DocData = struct { |
| 722 | \\{{ "{s}":{{}} }} | 721 | \\{{ "{s}":{{}} }} |
| 723 | , .{@tagName(self)}); | 722 | , .{@tagName(self)}); |
| 724 | }, | 723 | }, |
| 725 | .type, .comptimeExpr, .call, .this, .declRef, .typeOf, .errorUnion => |v| { | 724 | .type, .comptimeExpr, .call, .this, .declRef, .typeOf, .errorUnion, .errorSets, .alignOf => |v| { |
| 726 | try w.print( | 725 | try w.print( |
| 727 | \\{{ "{s}":{} }} | 726 | \\{{ "{s}":{} }} |
| 728 | , .{ @tagName(self), v }); | 727 | , .{ @tagName(self), v }); |
| ... | @@ -1792,6 +1791,33 @@ fn walkInstruction( | ... | @@ -1792,6 +1791,33 @@ fn walkInstruction( |
| 1792 | .expr = .{ .errorUnion = type_slot_index }, | 1791 | .expr = .{ .errorUnion = type_slot_index }, |
| 1793 | }; | 1792 | }; |
| 1794 | }, | 1793 | }, |
| | 1794 | .merge_error_sets => { |
| | 1795 | const pl_node = data[inst_index].pl_node; |
| | 1796 | const extra = file.zir.extraData(Zir.Inst.Bin, pl_node.payload_index); |
| | 1797 | |
| | 1798 | var lhs: DocData.WalkResult = try self.walkRef( |
| | 1799 | file, |
| | 1800 | parent_scope, |
| | 1801 | extra.data.lhs, |
| | 1802 | false, |
| | 1803 | ); |
| | 1804 | var rhs: DocData.WalkResult = try self.walkRef( |
| | 1805 | file, |
| | 1806 | parent_scope, |
| | 1807 | extra.data.rhs, |
| | 1808 | false, |
| | 1809 | ); |
| | 1810 | const type_slot_index = self.types.items.len; |
| | 1811 | try self.types.append(self.arena, .{ .ErrorUnion = .{ |
| | 1812 | .lhs = lhs.expr, |
| | 1813 | .rhs = rhs.expr, |
| | 1814 | } }); |
| | 1815 | |
| | 1816 | return DocData.WalkResult{ |
| | 1817 | .typeRef = .{ .type = @enumToInt(Ref.type_type) }, |
| | 1818 | .expr = .{ .errorSets = type_slot_index }, |
| | 1819 | }; |
| | 1820 | }, |
| 1795 | .elem_type => { | 1821 | .elem_type => { |
| 1796 | const un_node = data[inst_index].un_node; | 1822 | const un_node = data[inst_index].un_node; |
| 1797 | | 1823 | |
| ... | @@ -2228,15 +2254,17 @@ fn walkInstruction( | ... | @@ -2228,15 +2254,17 @@ fn walkInstruction( |
| 2228 | }; | 2254 | }; |
| 2229 | }, | 2255 | }, |
| 2230 | .switch_block => { | 2256 | .switch_block => { |
| | 2257 | // WIP |
| 2231 | const pl_node = data[inst_index].pl_node; | 2258 | const pl_node = data[inst_index].pl_node; |
| 2232 | const extra = file.zir.extraData(Zir.Inst.SwitchBlock, pl_node.payload_index); | 2259 | const extra = file.zir.extraData(Zir.Inst.SwitchBlock, pl_node.payload_index); |
| 2233 | const array_data = try self.arena.alloc(usize, extra.data.bits.scalar_cases_len); | 2260 | const array_data = try self.arena.alloc(usize, extra.data.bits.scalar_cases_len); |
| 2234 | var extra_index = extra.end; | 2261 | var extra_index = extra.end; |
| 2235 | | 2262 | |
| 2236 | const sep = "=" ** 200; | 2263 | // const sep = "=" ** 200; |
| 2237 | std.debug.print("{s}\n", .{sep}); | 2264 | // std.debug.print("{s}\n", .{sep}); |
| 2238 | std.debug.print("pl_node = {any}\n", .{pl_node}); | 2265 | // std.debug.print("pl_node = {any}\n", .{pl_node}); |
| 2239 | std.debug.print("extra = {any}\n", .{extra}); | 2266 | // std.debug.print("extra = {any}\n", .{extra}); |
| | 2267 | // std.debug.print("{s}\n", .{sep}); |
| 2240 | | 2268 | |
| 2241 | const multi_cases_len = if (extra.data.bits.has_multi_cases) blk: { | 2269 | const multi_cases_len = if (extra.data.bits.has_multi_cases) blk: { |
| 2242 | const multi_cases_len = file.zir.extra[extra_index]; | 2270 | const multi_cases_len = file.zir.extra[extra_index]; |
| ... | @@ -2251,12 +2279,12 @@ fn walkInstruction( | ... | @@ -2251,12 +2279,12 @@ fn walkInstruction( |
| 2251 | extra_index += 1; | 2279 | extra_index += 1; |
| 2252 | const body = file.zir.extra[extra_index..][0..body_len]; | 2280 | const body = file.zir.extra[extra_index..][0..body_len]; |
| 2253 | extra_index += body.len; | 2281 | extra_index += body.len; |
| 2254 | for (body) |body_member| { | 2282 | for (body) |_| { |
| 2255 | const item_ref = @intToEnum(Ref, file.zir.extra[extra_index]); | 2283 | const item_ref = @intToEnum(Ref, file.zir.extra[extra_index]); |
| 2256 | const item = try self.walkRef(file, parent_scope, item_ref, false); | 2284 | const item = try self.walkRef(file, parent_scope, item_ref, false); |
| 2257 | std.debug.print("prong item_ref = {any}\n", .{item_ref}); | 2285 | // std.debug.print("prong item_ref = {any}\n", .{item_ref}); |
| 2258 | std.debug.print("prong item = {any}\n", .{item}); | 2286 | // std.debug.print("prong item = {any}\n", .{item}); |
| 2259 | std.debug.print("body member = {any}\n", .{body_member}); | 2287 | // std.debug.print("body member = {any}\n", .{body_member}); |
| 2260 | const item_index = self.exprs.items.len; | 2288 | const item_index = self.exprs.items.len; |
| 2261 | try self.exprs.append(self.arena, item.expr); | 2289 | try self.exprs.append(self.arena, item.expr); |
| 2262 | else_index = item_index; | 2290 | else_index = item_index; |
| ... | @@ -2279,15 +2307,16 @@ fn walkInstruction( | ... | @@ -2279,15 +2307,16 @@ fn walkInstruction( |
| 2279 | array_data[scalar_i] = item.expr.as.exprArg; | 2307 | array_data[scalar_i] = item.expr.as.exprArg; |
| 2280 | | 2308 | |
| 2281 | const body_ref = @intToEnum(Ref, file.zir.extra[extra_index]); | 2309 | const body_ref = @intToEnum(Ref, file.zir.extra[extra_index]); |
| 2282 | const body_item = try self.walkRef(file, parent_scope, item_ref, false); | 2310 | const body_item = try self.walkRef(file, parent_scope, body_ref, false); |
| | 2311 | _ = body_item; |
| 2283 | | 2312 | |
| 2284 | array_data[scalar_i] = item.expr.as.exprArg; | 2313 | array_data[scalar_i] = item.expr.as.exprArg; |
| 2285 | std.debug.print("{s}\n", .{sep}); | 2314 | // std.debug.print("{s}\n", .{sep}); |
| 2286 | std.debug.print("body item_ref = {any}\n", .{item_ref}); | 2315 | // std.debug.print("body item_ref = {any}\n", .{item_ref}); |
| 2287 | std.debug.print("body item = {any}\n", .{item}); | 2316 | // std.debug.print("body item = {any}\n", .{item}); |
| 2288 | std.debug.print("body_len scalar cases = {any}\n", .{body_ref}); | 2317 | // std.debug.print("body_len scalar cases = {any}\n", .{body_ref}); |
| 2289 | std.debug.print("body scalar cases = {any}\n", .{body_item}); | 2318 | // std.debug.print("body scalar cases = {any}\n", .{body_item}); |
| 2290 | std.debug.print("{s}\n", .{sep}); | 2319 | // std.debug.print("{s}\n", .{sep}); |
| 2291 | } | 2320 | } |
| 2292 | } | 2321 | } |
| 2293 | { | 2322 | { |
| ... | @@ -2311,14 +2340,15 @@ fn walkInstruction( | ... | @@ -2311,14 +2340,15 @@ fn walkInstruction( |
| 2311 | | 2340 | |
| 2312 | const body = file.zir.extra[extra_index..][0..body_len]; | 2341 | const body = file.zir.extra[extra_index..][0..body_len]; |
| 2313 | extra_index += body_len; | 2342 | extra_index += body_len; |
| | 2343 | _ = body; |
| 2314 | | 2344 | |
| 2315 | std.debug.print("body multi_i = {any}\n", .{body}); | 2345 | // std.debug.print("body multi_i = {any}\n", .{body}); |
| 2316 | std.debug.print("items = {any}\n", .{items}); | 2346 | // std.debug.print("items = {any}\n", .{items}); |
| 2317 | } | 2347 | } |
| 2318 | } | 2348 | } |
| 2319 | | 2349 | |
| 2320 | // std.debug.print("multi_cases_len = {}\n", .{multi_cases_len}); | 2350 | // std.debug.print("multi_cases_len = {}\n", .{multi_cases_len}); |
| 2321 | std.debug.print("{s}\n", .{sep}); | 2351 | // std.debug.print("{s}\n", .{sep}); |
| 2322 | | 2352 | |
| 2323 | const switch_index = self.exprs.items.len; | 2353 | const switch_index = self.exprs.items.len; |
| 2324 | try self.exprs.append(self.arena, .{ .switchOp = .{ .cases = array_data, .else_index = else_index } }); | 2354 | try self.exprs.append(self.arena, .{ .switchOp = .{ .cases = array_data, .else_index = else_index } }); |
| ... | @@ -2368,6 +2398,26 @@ fn walkInstruction( | ... | @@ -2368,6 +2398,26 @@ fn walkInstruction( |
| 2368 | .expr = .{ .typeOf = operand_index }, | 2398 | .expr = .{ .typeOf = operand_index }, |
| 2369 | }; | 2399 | }; |
| 2370 | }, | 2400 | }, |
| | 2401 | .align_of => { |
| | 2402 | // WIP |
| | 2403 | // not fully working |
| | 2404 | // @alignOf() with some pointer type it's not even called in js |
| | 2405 | // @alignOf([*]u8) are being rendered as [*]u8 |
| | 2406 | const un_node = data[inst_index].un_node; |
| | 2407 | const operand = try self.walkRef( |
| | 2408 | file, |
| | 2409 | parent_scope, |
| | 2410 | un_node.operand, |
| | 2411 | need_type, |
| | 2412 | ); |
| | 2413 | const operand_index = self.exprs.items.len; |
| | 2414 | try self.exprs.append(self.arena, operand.expr); |
| | 2415 | |
| | 2416 | return DocData.WalkResult{ |
| | 2417 | .typeRef = operand.typeRef, |
| | 2418 | .expr = .{ .alignOf = operand_index }, |
| | 2419 | }; |
| | 2420 | }, |
| 2371 | .typeof_builtin => { | 2421 | .typeof_builtin => { |
| 2372 | const pl_node = data[inst_index].pl_node; | 2422 | const pl_node = data[inst_index].pl_node; |
| 2373 | const extra = file.zir.extraData(Zir.Inst.Block, pl_node.payload_index); | 2423 | const extra = file.zir.extraData(Zir.Inst.Block, pl_node.payload_index); |
| ... | @@ -2388,6 +2438,31 @@ fn walkInstruction( | ... | @@ -2388,6 +2438,31 @@ fn walkInstruction( |
| 2388 | .expr = .{ .typeOf = operand_index }, | 2438 | .expr = .{ .typeOf = operand_index }, |
| 2389 | }; | 2439 | }; |
| 2390 | }, | 2440 | }, |
| | 2441 | .typeof_log2_int_type => { |
| | 2442 | // @check |
| | 2443 | const un_node = data[inst_index].un_node; |
| | 2444 | const operand = try self.walkRef( |
| | 2445 | file, |
| | 2446 | parent_scope, |
| | 2447 | un_node.operand, |
| | 2448 | need_type, |
| | 2449 | ); |
| | 2450 | |
| | 2451 | // WIP |
| | 2452 | // const sep = "=" ** 200; |
| | 2453 | // std.debug.print("{s}\n", .{sep}); |
| | 2454 | // std.debug.print("un_node = {any}\n", .{un_node}); |
| | 2455 | // std.debug.print("operand = {any}\n", .{operand}); |
| | 2456 | // std.debug.print("{s}\n", .{sep}); |
| | 2457 | |
| | 2458 | const operand_index = self.exprs.items.len; |
| | 2459 | try self.exprs.append(self.arena, operand.expr); |
| | 2460 | |
| | 2461 | return DocData.WalkResult{ |
| | 2462 | .typeRef = operand.typeRef, |
| | 2463 | .expr = .{ .typeOf = operand_index }, |
| | 2464 | }; |
| | 2465 | }, |
| 2391 | .type_info => { | 2466 | .type_info => { |
| 2392 | // @check | 2467 | // @check |
| 2393 | const un_node = data[inst_index].un_node; | 2468 | const un_node = data[inst_index].un_node; |
| ... | @@ -2536,6 +2611,23 @@ fn walkInstruction( | ... | @@ -2536,6 +2611,23 @@ fn walkInstruction( |
| 2536 | .expr = .{ .type = self.types.items.len - 1 }, | 2611 | .expr = .{ .type = self.types.items.len - 1 }, |
| 2537 | }; | 2612 | }; |
| 2538 | }, | 2613 | }, |
| | 2614 | .float128 => { |
| | 2615 | const pl_node = data[inst_index].pl_node; |
| | 2616 | const extra = file.zir.extraData(Zir.Inst.Float128, pl_node.payload_index); |
| | 2617 | _ = extra; |
| | 2618 | // const sep = "=" ** 200; |
| | 2619 | // std.debug.print("{s}\n", .{sep}); |
| | 2620 | // std.debug.print("pl_node = {any}\n", .{pl_node}); |
| | 2621 | // std.debug.print("extra = {any}\n", .{extra}); |
| | 2622 | // std.debug.print("{s}\n", .{sep}); |
| | 2623 | // printWithContext( |
| | 2624 | // file, |
| | 2625 | // inst_index, |
| | 2626 | // "TODO: implement `{s}` for walkInstruction\n\n", |
| | 2627 | // .{@tagName(tags[inst_index])}, |
| | 2628 | // ); |
| | 2629 | return self.cteTodo(@tagName(tags[inst_index])); |
| | 2630 | }, |
| 2539 | .block => { | 2631 | .block => { |
| 2540 | const res = DocData.WalkResult{ .expr = .{ | 2632 | const res = DocData.WalkResult{ .expr = .{ |
| 2541 | .comptimeExpr = self.comptime_exprs.items.len, | 2633 | .comptimeExpr = self.comptime_exprs.items.len, |
| ... | @@ -3746,14 +3838,15 @@ fn tryResolveRefPath( | ... | @@ -3746,14 +3838,15 @@ fn tryResolveRefPath( |
| 3746 | } | 3838 | } |
| 3747 | | 3839 | |
| 3748 | // if we got here, our search failed | 3840 | // if we got here, our search failed |
| 3749 | printWithContext( | 3841 | // printWithContext( |
| 3750 | file, | 3842 | // file, |
| 3751 | inst_index, | 3843 | // inst_index, |
| 3752 | "failed to match `{s}` in struct", | 3844 | // "failed to match `{s}` in struct", |
| 3753 | .{child_string}, | 3845 | // .{child_string}, |
| 3754 | ); | 3846 | // ); |
| 3755 | // path[i + 1] = (try self.cteTodo("match failure")).expr; | 3847 | // path[i + 1] = (try self.cteTodo("match failure")).expr; |
| 3756 | // this are working, check c.zig | 3848 | // |
| | 3849 | // that's working |
| 3757 | path[i + 1] = (try self.cteTodo(child_string)).expr; | 3850 | path[i + 1] = (try self.cteTodo(child_string)).expr; |
| 3758 | continue :outer; | 3851 | continue :outer; |
| 3759 | }, | 3852 | }, |