aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLoris Cro <kappaloris@gmail.com>2022-09-02 17:48:17 +0200
committerGitHub <noreply@github.com>2022-09-02 17:48:17 +0200
commit907c60aaa7158a9407c4d81fe7e77df75a84ae80 (patch)
tree2d87c09c1d4ac6593087334c004d7bb4035cf969 /src
parent70b96169ae244261c2853f4833b71a0a45a82a5a (diff)
parenta77d7b740fbe52c3822567db28bade2110c9e737 (diff)
downloadzig-907c60aaa7158a9407c4d81fe7e77df75a84ae80.tar.gz
zig-907c60aaa7158a9407c4d81fe7e77df75a84ae80.zip
Merge pull request #12705 from der-teufel-programming/autodoc-big-int
Autodoc big_int
Diffstat (limited to 'src')
-rw-r--r--src/Autodoc.zig36
1 files changed, 20 insertions, 16 deletions
diff --git a/src/Autodoc.zig b/src/Autodoc.zig
index e833ddc34f..3f344f0421 100644
--- a/src/Autodoc.zig
+++ b/src/Autodoc.zig
@@ -639,7 +639,7 @@ const DocData = struct {
negated: bool = false,
},
int_big: struct {
- value: []const u8, // direct value
+ value: []const u8, // string representation
negated: bool = false,
},
float: f64, // direct value
@@ -726,12 +726,6 @@ const DocData = struct {
if (self.int.negated) try w.writeAll("-");
try jsw.emitNumber(self.int.value);
},
- .int_big => {
-
- //@panic("TODO: json serialization of big ints!");
- //if (v.negated) try w.writeAll("-");
- //try jsw.emitNumber(v.value);
- },
.builtinField => {
try jsw.emitString(@tagName(self.builtinField));
},
@@ -1099,15 +1093,24 @@ fn walkInstruction(
},
.int_big => {
// @check
- const str = data[inst_index].str.get(file.zir);
- _ = str;
- printWithContext(
- file,
- inst_index,
- "TODO: implement `{s}` for walkInstruction\n\n",
- .{@tagName(tags[inst_index])},
- );
- return self.cteTodo(@tagName(tags[inst_index]));
+ const str = data[inst_index].str; //.get(file.zir);
+ const byte_count = str.len * @sizeOf(std.math.big.Limb);
+ const limb_bytes = file.zir.string_bytes[str.start..][0..byte_count];
+
+ var limbs = try self.arena.alloc(std.math.big.Limb, str.len);
+ std.mem.copy(u8, std.mem.sliceAsBytes(limbs), limb_bytes);
+
+ const big_int = std.math.big.int.Const{
+ .limbs = limbs,
+ .positive = true,
+ };
+
+ const as_string = try big_int.toStringAlloc(self.arena, 10, .lower);
+
+ return DocData.WalkResult{
+ .typeRef = .{ .type = @enumToInt(Ref.comptime_int_type) },
+ .expr = .{ .int_big = .{ .value = as_string } },
+ };
},
.slice_start => {
@@ -1776,6 +1779,7 @@ fn walkInstruction(
);
switch (operand.expr) {
.int => |*int| int.negated = true,
+ .int_big => |*int_big| int_big.negated = true,
else => {
printWithContext(
file,