authorgravatar for der.teufel.mail@gmail.comKrzysztof Wolicki <der.teufel.mail@gmail.com> 2022-08-31 21:18:50+02:00
committergravatar for der.teufel.mail@gmail.comKrzysztof Wolicki <der.teufel.mail@gmail.com> 2022-09-02 11:01:46+02:00
log0d3c6b7aa847682445a0d292b7f97035a0bad052
tree7441fbd7d3e2cdc68cfe2de27d570052f4025bdb
parent36f4f32fad3e88a84b6a10d78df31a4ed2c24465

autodoc: Added int_big support


2 files changed, 38 insertions(+), 13 deletions(-)

lib/docs/main.js+4
......@@ -1555,6 +1555,10 @@ var zigAnalysis;
15551555 return '"' + escapeHtml(expr.string) + '"';
15561556 }
15571557
1558 case "int_big": {
1559 return (expr.int_big.negated ? "-" : "") + expr.int_big.value;
1560 }
1561
15581562 case "anytype": {
15591563 return "anytype";
15601564 }
src/Autodoc.zig+34-13
......@@ -625,7 +625,7 @@ const DocData = struct {
625625 negated: bool = false,
626626 },
627627 int_big: struct {
628 value: []const u8, // direct value
628 value: []const u8, // string representation
629629 negated: bool = false,
630630 },
631631 float: f64, // direct value
......@@ -714,9 +714,12 @@ const DocData = struct {
714714 },
715715 .int_big => {
716716
717 //@panic("TODO: json serialization of big ints!");
718 //if (v.negated) try w.writeAll("-");
719 //try jsw.emitNumber(v.value);
717 try jsw.beginObject();
718 try jsw.objectField("value");
719 try jsw.emitString(self.int_big.value);
720 try jsw.objectField("negated");
721 try jsw.emitBool(self.int_big.negated);
722 try jsw.endObject();
720723 },
721724 .builtinField => {
722725 try jsw.emitString(@tagName(self.builtinField));
......@@ -1084,15 +1087,32 @@ fn walkInstruction(
10841087 },
10851088 .int_big => {
10861089 // @check
1087 const str = data[inst_index].str.get(file.zir);
1088 _ = str;
1089 printWithContext(
1090 file,
1091 inst_index,
1092 "TODO: implement `{s}` for walkInstruction\n\n",
1093 .{@tagName(tags[inst_index])},
1094 );
1095 return self.cteTodo(@tagName(tags[inst_index]));
1090 const str = data[inst_index].str; //.get(file.zir);
1091 const byte_count = str.len * @sizeOf(std.math.big.Limb);
1092 const limb_bytes = file.zir.string_bytes[str.start..][0..byte_count];
1093
1094 var limbs = try self.arena.alloc(std.math.big.Limb, str.len);
1095 std.mem.copy(u8, std.mem.sliceAsBytes(limbs), limb_bytes);
1096
1097 const big_int = std.math.big.int.Const{
1098 .limbs = limbs,
1099 .positive = true,
1100 };
1101
1102 const as_string = try big_int.toStringAlloc(self.arena, 10, .lower);
1103
1104 return DocData.WalkResult{
1105 .typeRef = .{ .type = @enumToInt(Ref.comptime_int_type) },
1106 .expr = .{ .int_big = .{ .value = as_string } },
1107 };
1108
1109 // printWithContext(
1110 // file,
1111 // inst_index,
1112 // "TODO: implement `{s}` for walkInstruction\n\n",
1113 // .{@tagName(tags[inst_index])},
1114 // );
1115 // return self.cteTodo(@tagName(tags[inst_index]));
10961116 },
10971117
10981118 .slice_start => {
......@@ -1714,6 +1734,7 @@ fn walkInstruction(
17141734 );
17151735 switch (operand.expr) {
17161736 .int => |*int| int.negated = true,
1737 .int_big => |*int_big| int_big.negated = true,
17171738 else => {
17181739 printWithContext(
17191740 file,