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;...@@ -1555,6 +1555,10 @@ var zigAnalysis;
1555 return '"' + escapeHtml(expr.string) + '"';1555 return '"' + escapeHtml(expr.string) + '"';
1556 }1556 }
15571557
1558 case "int_big": {
1559 return (expr.int_big.negated ? "-" : "") + expr.int_big.value;
1560 }
1561
1558 case "anytype": {1562 case "anytype": {
1559 return "anytype";1563 return "anytype";
1560 }1564 }
src/Autodoc.zig+34-13
...@@ -625,7 +625,7 @@ const DocData = struct {...@@ -625,7 +625,7 @@ const DocData = struct {
625 negated: bool = false,625 negated: bool = false,
626 },626 },
627 int_big: struct {627 int_big: struct {
628 value: []const u8, // direct value628 value: []const u8, // string representation
629 negated: bool = false,629 negated: bool = false,
630 },630 },
631 float: f64, // direct value631 float: f64, // direct value
...@@ -714,9 +714,12 @@ const DocData = struct {...@@ -714,9 +714,12 @@ const DocData = struct {
714 },714 },
715 .int_big => {715 .int_big => {
716716
717 //@panic("TODO: json serialization of big ints!");717 try jsw.beginObject();
718 //if (v.negated) try w.writeAll("-");718 try jsw.objectField("value");
719 //try jsw.emitNumber(v.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();
720 },723 },
721 .builtinField => {724 .builtinField => {
722 try jsw.emitString(@tagName(self.builtinField));725 try jsw.emitString(@tagName(self.builtinField));
...@@ -1084,15 +1087,32 @@ fn walkInstruction(...@@ -1084,15 +1087,32 @@ fn walkInstruction(
1084 },1087 },
1085 .int_big => {1088 .int_big => {
1086 // @check1089 // @check
1087 const str = data[inst_index].str.get(file.zir);1090 const str = data[inst_index].str; //.get(file.zir);
1088 _ = str;1091 const byte_count = str.len * @sizeOf(std.math.big.Limb);
1089 printWithContext(1092 const limb_bytes = file.zir.string_bytes[str.start..][0..byte_count];
1090 file,1093
1091 inst_index,1094 var limbs = try self.arena.alloc(std.math.big.Limb, str.len);
1092 "TODO: implement `{s}` for walkInstruction\n\n",1095 std.mem.copy(u8, std.mem.sliceAsBytes(limbs), limb_bytes);
1093 .{@tagName(tags[inst_index])},1096
1094 );1097 const big_int = std.math.big.int.Const{
1095 return self.cteTodo(@tagName(tags[inst_index]));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]));
1096 },1116 },
10971117
1098 .slice_start => {1118 .slice_start => {
...@@ -1714,6 +1734,7 @@ fn walkInstruction(...@@ -1714,6 +1734,7 @@ fn walkInstruction(
1714 );1734 );
1715 switch (operand.expr) {1735 switch (operand.expr) {
1716 .int => |*int| int.negated = true,1736 .int => |*int| int.negated = true,
1737 .int_big => |*int_big| int_big.negated = true,
1717 else => {1738 else => {
1718 printWithContext(1739 printWithContext(
1719 file,1740 file,