Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ZON #20271

Open
wants to merge 53 commits into
base: master
Choose a base branch
from
Open

ZON #20271

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
bdc7539
Squashes all zon work into one commit for easier rebase
MasonRemaley Nov 4, 2024
33a749a
Rebases and gets runtime zon import tests passing, comptime import ne…
MasonRemaley Nov 5, 2024
3c07587
Gets some import zon behavior tests working, skips failing tests for now
MasonRemaley Nov 5, 2024
bf536f6
Gets strings working again
MasonRemaley Nov 5, 2024
bb6ad66
Starts moving parsing into known result type
MasonRemaley Nov 5, 2024
ca738f6
Starts moving optionals to known result type parsing
MasonRemaley Nov 5, 2024
6e47966
Parses integers to known result types. Not yet tested as those tests …
MasonRemaley Nov 6, 2024
39269c4
Pulls out separate types into their own functions to make easier to j…
MasonRemaley Nov 6, 2024
877bdcf
Parses arrays to known result type
MasonRemaley Nov 6, 2024
243146c
Parses enums to known result type
MasonRemaley Nov 6, 2024
6415e6f
WIP tuples: crash on string literals right now
MasonRemaley Nov 6, 2024
5306cd4
Parses tuples to known result types
MasonRemaley Nov 6, 2024
d8956e9
Parses strings to known result type
MasonRemaley Nov 6, 2024
5ccef64
Parses unions to explicit return types
MasonRemaley Nov 12, 2024
489ea56
Fixes bug in explicit union tag parsing
MasonRemaley Nov 12, 2024
1371cab
Parses void union fields from enum literals
MasonRemaley Nov 13, 2024
3d058d6
Parses structs to known result types
MasonRemaley Nov 13, 2024
501fe49
Fixes parsing integers as floats
MasonRemaley Nov 13, 2024
6c48642
Removes old implementation, renames parse to lower
MasonRemaley Nov 26, 2024
1a58d39
Implements slice coercion
MasonRemaley Nov 27, 2024
a3f50f5
Starts work on compile error tests
MasonRemaley Nov 27, 2024
26b5556
Fixes more failing compile error tests
MasonRemaley Dec 3, 2024
fdc88b1
Fixes more zon compile error tests
MasonRemaley Dec 3, 2024
9490b84
Gets all ZON tests passing locally
MasonRemaley Dec 3, 2024
d59e35d
Removes platform specific separator from test case
MasonRemaley Dec 3, 2024
a510ca1
Fixes mistake in rebase
MasonRemaley Dec 18, 2024
1519fe9
Updates runtime parser to use ZonGen
MasonRemaley Dec 18, 2024
47dc613
Parses to zoir on import, but does not yet use result or lower errors
MasonRemaley Dec 21, 2024
0e8bf41
Reports zongen errors when importing zon, doesn't yet use it for parsing
MasonRemaley Dec 21, 2024
4ad3227
Simplifies error handling
MasonRemaley Dec 22, 2024
a29a106
Ports import zon to use Zoir
MasonRemaley Dec 22, 2024
e410cb0
Cleans up diff with master, resovles some feedback
MasonRemaley Dec 22, 2024
cd27793
Moves big int -> float conversion to standard library, uses
MasonRemaley Jan 4, 2025
bc14a68
Calculates mode instead of storing it
MasonRemaley Jan 4, 2025
0e4478e
Fixes tuple in test to have non comptime fields
MasonRemaley Jan 4, 2025
8397191
Supports comptime fields on structs and tuples
MasonRemaley Jan 5, 2025
f28bd91
Fixes out of date comment
MasonRemaley Jan 5, 2025
5d0c72b
Provides migration path for to -> toInt
MasonRemaley Jan 5, 2025
8bea683
Removes redundant backend option from tests, stops using mode exe
MasonRemaley Jan 5, 2025
577587e
Stops requiring tree to be loaded unless errors occur
MasonRemaley Jan 6, 2025
2671f6c
Resolves unecessary copying of strings between ZonGen & parse
MasonRemaley Jan 6, 2025
0cc646a
Simplifies error formatting
MasonRemaley Jan 8, 2025
c9e12d6
Cleans up string parsing API
MasonRemaley Jan 8, 2025
50a94aa
Removes dead code, fixes expect order
MasonRemaley Jan 8, 2025
58d257c
Reports errors to sema instead of failed files when appropriate, stop…
MasonRemaley Jan 8, 2025
936a900
Uses sema arena when appropriate
MasonRemaley Jan 8, 2025
524ab23
Cleans up API naming & docs
MasonRemaley Jan 8, 2025
9430638
Replaces serialzier writer with AnyWriter, no longer needs to be generic
MasonRemaley Jan 8, 2025
a9c1596
Replaces comment about keeping code in sync with struct that can be r…
MasonRemaley Jan 8, 2025
ffdbf53
Trying out different serialize API
MasonRemaley Jan 10, 2025
9563cb0
Stops using parse.zig as a struct
MasonRemaley Jan 10, 2025
0a46f10
Resolves some review feedback
MasonRemaley Jan 24, 2025
5cac4a9
Updates some field/enum names after rebase
MasonRemaley Jan 24, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ pub fn build(b: *std.Build) !void {
const optimization_modes = chosen_opt_modes_buf[0..chosen_mode_index];

const fmt_include_paths = &.{ "lib", "src", "test", "tools", "build.zig", "build.zig.zon" };
const fmt_exclude_paths = &.{"test/cases"};
const fmt_exclude_paths = &.{ "test/cases", "test/behavior/zon" };
MasonRemaley marked this conversation as resolved.
Show resolved Hide resolved
const do_fmt = b.addFmt(.{
.paths = fmt_include_paths,
.exclude_paths = fmt_exclude_paths,
Expand Down
2 changes: 1 addition & 1 deletion lib/compiler/aro/aro/Value.zig
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ pub fn toInt(v: Value, comptime T: type, comp: *const Compilation) ?T {
if (comp.interner.get(v.ref()) != .int) return null;
var space: BigIntSpace = undefined;
const big_int = v.toBigInt(&space, comp);
return big_int.to(T) catch null;
return big_int.toInt(T) catch null;
}

const ComplexOp = enum {
Expand Down
4 changes: 2 additions & 2 deletions lib/compiler/aro/backend/Interner.zig
Original file line number Diff line number Diff line change
Expand Up @@ -628,13 +628,13 @@ pub fn put(i: *Interner, gpa: Allocator, key: Key) !Ref {
if (data.fitsInTwosComp(.unsigned, 32)) {
i.items.appendAssumeCapacity(.{
.tag = .u32,
.data = data.to(u32) catch unreachable,
.data = data.toInt(u32) catch unreachable,
});
break :int;
} else if (data.fitsInTwosComp(.signed, 32)) {
i.items.appendAssumeCapacity(.{
.tag = .i32,
.data = @bitCast(data.to(i32) catch unreachable),
.data = @bitCast(data.toInt(i32) catch unreachable),
});
break :int;
}
Expand Down
42 changes: 36 additions & 6 deletions lib/std/math/big/int.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2175,10 +2175,13 @@ pub const Const = struct {
TargetTooSmall,
};

/// Convert self to type T.
/// Deprecated; use `toInt`.
pub const to = toInt;

/// Convert self to integer type T.
///
/// Returns an error if self cannot be narrowed into the requested type without truncation.
pub fn to(self: Const, comptime T: type) ConvertError!T {
pub fn toInt(self: Const, comptime T: type) ConvertError!T {
switch (@typeInfo(T)) {
.int => |info| {
// Make sure -0 is handled correctly.
Expand Down Expand Up @@ -2216,7 +2219,26 @@ pub const Const = struct {
}
}
},
else => @compileError("cannot convert Const to type " ++ @typeName(T)),
else => @compileError("expected int type, found '" ++ @typeName(T) ++ "'"),
}
}

/// Convert self to float type T.
pub fn toFloat(self: Const, comptime T: type) T {
if (self.limbs.len == 0) return 0;

const base = std.math.maxInt(std.math.big.Limb) + 1;
var result: f128 = 0;
var i: usize = self.limbs.len;
while (i != 0) {
i -= 1;
const limb: f128 = @floatFromInt(self.limbs[i]);
result = @mulAdd(f128, base, result, limb);
}
if (self.positive) {
return @floatCast(result);
} else {
return @floatCast(-result);
}
}

Expand Down Expand Up @@ -2775,11 +2797,19 @@ pub const Managed = struct {

pub const ConvertError = Const.ConvertError;

/// Convert self to type T.
/// Deprecated; use `toInt`.
pub const to = toInt;

/// Convert self to integer type T.
///
/// Returns an error if self cannot be narrowed into the requested type without truncation.
pub fn to(self: Managed, comptime T: type) ConvertError!T {
return self.toConst().to(T);
pub fn toInt(self: Managed, comptime T: type) ConvertError!T {
return self.toConst().toInt(T);
}

/// Convert self to float type T.
pub fn toFloat(self: Managed, comptime T: type) T {
return self.toConst().toFloat(T);
}

/// Set self from the string representation `value`.
Expand Down
Loading