21 Commits

Author SHA1 Message Date
Andrew Kelley
0fb7a0a94b std.zon: better namespace for Serializer 2025-07-19 18:27:09 -07:00
Andrew Kelley
c3da98cf5a std.zon: update to new I/O API 2025-07-19 18:27:09 -07:00
Andrew Kelley
2d5d2ba4f5 std.zig.Render: update it and references 2025-07-16 17:20:02 -07:00
Andrew Kelley
1a998886c8
Merge pull request #24329 from ziglang/writergate
Deprecates all existing std.io readers and writers in favor of the newly
provided std.io.Reader and std.io.Writer which are non-generic and have the
buffer above the vtable - in other words the buffer is in the interface, not
the implementation. This means that although Reader and Writer are no longer
generic, they are still transparent to optimization; all of the interface
functions have a concrete hot path operating on the buffer, and only make
vtable calls when the buffer is full.
2025-07-10 12:04:27 +02:00
Alex Rønne Petersen
820f1a23a5 std: Disable std.zon parse float on dynamic x86-linux-musl
https://github.com/ziglang/zig/issues/23922#issuecomment-3054296672
2025-07-10 06:52:01 +02:00
Andrew Kelley
93ac76594a std: fmt.format to io.Writer.print
allows reverting format -> deprecatedFormat, plus I think this is a
nicer place for the function.
2025-07-09 15:31:02 -07:00
Andrew Kelley
7e2a26c0c4 std.io.Writer.printValue: rework logic
Alignment and fill options only apply to numbers.

Rework the implementation to mainly branch on the format string rather
than the type information. This is more straightforward to maintain and
more straightforward for comptime evaluation.

Enums support being printed as decimal, hexadecimal, octal, and binary.

`formatInteger` is another possible format method that is
unconditionally called when the value type is struct and one of the
integer-printing format specifiers are used.
2025-07-07 22:43:53 -07:00
Andrew Kelley
5378fdb153 std.fmt: fully remove format string from format methods
Introduces `std.fmt.alt` which is a helper for calling alternate format
methods besides one named "format".
2025-07-07 22:43:53 -07:00
Andrew Kelley
0e37ff0d59 std.fmt: breaking API changes
added adapter to AnyWriter and GenericWriter to help bridge the gap
between old and new API

make std.testing.expectFmt work at compile-time

std.fmt no longer has a dependency on std.unicode. Formatted printing
was never properly unicode-aware. Now it no longer pretends to be.

Breakage/deprecations:
* std.fs.File.reader -> std.fs.File.deprecatedReader
* std.fs.File.writer -> std.fs.File.deprecatedWriter
* std.io.GenericReader -> std.io.Reader
* std.io.GenericWriter -> std.io.Writer
* std.io.AnyReader -> std.io.Reader
* std.io.AnyWriter -> std.io.Writer
* std.fmt.format -> std.fmt.deprecatedFormat
* std.fmt.fmtSliceEscapeLower -> std.ascii.hexEscape
* std.fmt.fmtSliceEscapeUpper -> std.ascii.hexEscape
* std.fmt.fmtSliceHexLower -> {x}
* std.fmt.fmtSliceHexUpper -> {X}
* std.fmt.fmtIntSizeDec -> {B}
* std.fmt.fmtIntSizeBin -> {Bi}
* std.fmt.fmtDuration -> {D}
* std.fmt.fmtDurationSigned -> {D}
* {} -> {f} when there is a format method
* format method signature
  - anytype -> *std.io.Writer
  - inferred error set -> error{WriteFailed}
  - options -> (deleted)
* std.fmt.Formatted
  - now takes context type explicitly
  - no fmt string
2025-07-07 22:43:51 -07:00
Jacob Young
6b41beb370 big.int: implement float conversions
These conversion routines accept a `round` argument to control how the
result is rounded and return whether the result is exact. Most callers
wanted this functionality and had hacks around it being missing.

Also delete `std.math.big.rational` because it was only being used for
float conversion, and using rationals for that is a lot more complex
than necessary. It also required an allocator, whereas the new integer
routines only need to be passed enough memory to store the result.
2025-06-15 14:15:18 -04:00
Jacob Young
1f6f8b0ffe x86_64: implement integer @reduce(.Add) 2025-05-28 15:10:22 -04:00
Andrew Kelley
f32a5d349d std: eradicate u29 and embrace std.mem.Alignment 2025-04-13 02:20:32 -04:00
Manlio Perillo
f4e3631655 std.zon.parse: Fix typo in test "std.zon parse bool"
Replace "Correct floats" with "Correct bools".
2025-04-09 14:43:12 +02:00
Mason Remaley
fa1695a8b0
std.zon.parse: make ast and zoir fields of Diagnostics non-optional 2025-04-02 06:09:21 +01:00
Mason Remaley
65649576db
std.zon.parse: rename Status to Diagnostics
This name is more appropriate and in line with the rest of `std`.
2025-04-02 06:08:55 +01:00
Mason Remaley
3b2fec17a4
std.zon: populate Zoir.Node.Index values with corresponding ZOIR node
This allows using `std.zon` to parse schemas which are not directly
representable in the Zig type system; for instance, `build.zig.zon`.
2025-04-02 06:08:04 +01:00
Ali Cheraghi
b636d56d6a zon: normalize negative zeroes 2025-03-31 19:07:34 -04:00
Techatrix
ca6fb30e99
std.zig.Ast: improve type safety
This commits adds the following distinct integer types to std.zig.Ast:
- OptionalTokenIndex
- TokenOffset
- OptionalTokenOffset
- Node.OptionalIndex
- Node.Offset
- Node.OptionalOffset

The `Node.Index` type has also been converted to a distinct type while
`TokenIndex` remains unchanged.

`Ast.Node.Data` has also been changed to a (untagged) union to provide
safety checks.
2025-03-07 22:22:01 +01:00
Mason Remaley
339b628d4c
Output zig targets as ZON instead of JSON (#22939)
* Adds startTupleField/startStructField, makes pattern in print targets less verbose

* Makes some enums into strings

* Start/finish renamed to begin/end

I feel bad changing this, but I don't know why I named them this way in the first place.
Begin/end is consistent with the json API, and with other APIs in the wild that follow this pattern.
Better to change now than later.
2025-02-21 21:40:57 -05:00
Nico Elbers
0cf6ae290b zon.stringify: Correctly serialize unions with void fields
Closes #22933
2025-02-19 07:21:59 +01:00
Mason Remaley
13c6eb0d71
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`.
2025-02-03 09:14:37 +00:00