authorgravatar for kappaloris@gmail.comLoris Cro <kappaloris@gmail.com> 2022-09-02 17:48:17+02:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2022-09-02 17:48:17+02:00
log907c60aaa7158a9407c4d81fe7e77df75a84ae80
tree2d87c09c1d4ac6593087334c004d7bb4035cf969
parent70b96169ae244261c2853f4833b71a0a45a82a5a
parenta77d7b740fbe52c3822567db28bade2110c9e737
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #12705 from der-teufel-programming/autodoc-big-int

Autodoc big_int

2 files changed, 24 insertions(+), 16 deletions(-)

lib/docs/main.js+4
......@@ -1579,6 +1579,10 @@ var zigAnalysis;
15791579 return '"' + escapeHtml(expr.string) + '"';
15801580 }
15811581
1582 case "int_big": {
1583 return (expr.int_big.negated ? "-" : "") + expr.int_big.value;
1584 }
1585
15821586 case "anytype": {
15831587 return "anytype";
15841588 }
src/Autodoc.zig+20-16
......@@ -639,7 +639,7 @@ const DocData = struct {
639639 negated: bool = false,
640640 },
641641 int_big: struct {
642 value: []const u8, // direct value
642 value: []const u8, // string representation
643643 negated: bool = false,
644644 },
645645 float: f64, // direct value
......@@ -726,12 +726,6 @@ const DocData = struct {
726726 if (self.int.negated) try w.writeAll("-");
727727 try jsw.emitNumber(self.int.value);
728728 },
729 .int_big => {
730
731 //@panic("TODO: json serialization of big ints!");
732 //if (v.negated) try w.writeAll("-");
733 //try jsw.emitNumber(v.value);
734 },
735729 .builtinField => {
736730 try jsw.emitString(@tagName(self.builtinField));
737731 },
......@@ -1099,15 +1093,24 @@ fn walkInstruction(
10991093 },
11001094 .int_big => {
11011095 // @check
1102 const str = data[inst_index].str.get(file.zir);
1103 _ = str;
1104 printWithContext(
1105 file,
1106 inst_index,
1107 "TODO: implement `{s}` for walkInstruction\n\n",
1108 .{@tagName(tags[inst_index])},
1109 );
1110 return self.cteTodo(@tagName(tags[inst_index]));
1096 const str = data[inst_index].str; //.get(file.zir);
1097 const byte_count = str.len * @sizeOf(std.math.big.Limb);
1098 const limb_bytes = file.zir.string_bytes[str.start..][0..byte_count];
1099
1100 var limbs = try self.arena.alloc(std.math.big.Limb, str.len);
1101 std.mem.copy(u8, std.mem.sliceAsBytes(limbs), limb_bytes);
1102
1103 const big_int = std.math.big.int.Const{
1104 .limbs = limbs,
1105 .positive = true,
1106 };
1107
1108 const as_string = try big_int.toStringAlloc(self.arena, 10, .lower);
1109
1110 return DocData.WalkResult{
1111 .typeRef = .{ .type = @enumToInt(Ref.comptime_int_type) },
1112 .expr = .{ .int_big = .{ .value = as_string } },
1113 };
11111114 },
11121115
11131116 .slice_start => {
......@@ -1776,6 +1779,7 @@ fn walkInstruction(
17761779 );
17771780 switch (operand.expr) {
17781781 .int => |*int| int.negated = true,
1782 .int_big => |*int_big| int_big.negated = true,
17791783 else => {
17801784 printWithContext(
17811785 file,