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;...@@ -1579,6 +1579,10 @@ var zigAnalysis;
1579 return '"' + escapeHtml(expr.string) + '"';1579 return '"' + escapeHtml(expr.string) + '"';
1580 }1580 }
15811581
1582 case "int_big": {
1583 return (expr.int_big.negated ? "-" : "") + expr.int_big.value;
1584 }
1585
1582 case "anytype": {1586 case "anytype": {
1583 return "anytype";1587 return "anytype";
1584 }1588 }
src/Autodoc.zig+20-16
...@@ -639,7 +639,7 @@ const DocData = struct {...@@ -639,7 +639,7 @@ const DocData = struct {
639 negated: bool = false,639 negated: bool = false,
640 },640 },
641 int_big: struct {641 int_big: struct {
642 value: []const u8, // direct value642 value: []const u8, // string representation
643 negated: bool = false,643 negated: bool = false,
644 },644 },
645 float: f64, // direct value645 float: f64, // direct value
...@@ -726,12 +726,6 @@ const DocData = struct {...@@ -726,12 +726,6 @@ const DocData = struct {
726 if (self.int.negated) try w.writeAll("-");726 if (self.int.negated) try w.writeAll("-");
727 try jsw.emitNumber(self.int.value);727 try jsw.emitNumber(self.int.value);
728 },728 },
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 },
735 .builtinField => {729 .builtinField => {
736 try jsw.emitString(@tagName(self.builtinField));730 try jsw.emitString(@tagName(self.builtinField));
737 },731 },
...@@ -1099,15 +1093,24 @@ fn walkInstruction(...@@ -1099,15 +1093,24 @@ fn walkInstruction(
1099 },1093 },
1100 .int_big => {1094 .int_big => {
1101 // @check1095 // @check
1102 const str = data[inst_index].str.get(file.zir);1096 const str = data[inst_index].str; //.get(file.zir);
1103 _ = str;1097 const byte_count = str.len * @sizeOf(std.math.big.Limb);
1104 printWithContext(1098 const limb_bytes = file.zir.string_bytes[str.start..][0..byte_count];
1105 file,1099
1106 inst_index,1100 var limbs = try self.arena.alloc(std.math.big.Limb, str.len);
1107 "TODO: implement `{s}` for walkInstruction\n\n",1101 std.mem.copy(u8, std.mem.sliceAsBytes(limbs), limb_bytes);
1108 .{@tagName(tags[inst_index])},1102
1109 );1103 const big_int = std.math.big.int.Const{
1110 return self.cteTodo(@tagName(tags[inst_index]));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 };
1111 },1114 },
11121115
1113 .slice_start => {1116 .slice_start => {
...@@ -1776,6 +1779,7 @@ fn walkInstruction(...@@ -1776,6 +1779,7 @@ fn walkInstruction(
1776 );1779 );
1777 switch (operand.expr) {1780 switch (operand.expr) {
1778 .int => |*int| int.negated = true,1781 .int => |*int| int.negated = true,
1782 .int_big => |*int_big| int_big.negated = true,
1779 else => {1783 else => {
1780 printWithContext(1784 printWithContext(
1781 file,1785 file,