compiler,std: implement ZON support

This commit allows using ZON (Zig Object Notation) in a few ways.

* `@import` can be used to load ZON at comptime and convert it to a
  normal Zig value. In this case, `@import` must have a result type.
* `std.zon.parse` can be used to parse ZON at runtime, akin to the
  parsing logic in `std.json`.
* `std.zon.stringify` can be used to convert arbitrary data structures
  to ZON at runtime, again akin to `std.json`.
This commit is contained in:
Mason Remaley
2024-11-04 14:03:36 -08:00
committed by mlugg
parent 953355ebea
commit 13c6eb0d71
145 changed files with 8786 additions and 434 deletions

View File

@@ -13776,8 +13776,8 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
};
const bit_count = extra.type.scalarBits(self);
const val: i64 = if (bit_count <= 64)
bigint.to(i64) catch unreachable
else if (bigint.to(u64)) |val|
bigint.toInt(i64) catch unreachable
else if (bigint.toInt(u64)) |val|
@bitCast(val)
else |_| {
const limbs = try record.addManyAsSlice(
@@ -14276,9 +14276,9 @@ pub fn toBitcode(self: *Builder, allocator: Allocator) bitcode_writer.Error![]co
else => unreachable,
},
};
const val: i64 = if (bigint.to(i64)) |val|
const val: i64 = if (bigint.toInt(i64)) |val|
val
else |_| if (bigint.to(u64)) |val|
else |_| if (bigint.toInt(u64)) |val|
@bitCast(val)
else |_| {
const limbs_len = std.math.divCeil(u32, extra.bit_width, 64) catch unreachable;