Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
d9e601a
Copy fmt.zig
Jan 3, 2020
f818223
Toy with generator based format
Jan 3, 2020
bcbcd3b
Translate formatInt*
Jan 3, 2020
1e20c10
Re-enable formatInt
Jan 3, 2020
c48a83a
Re-enable simple transforms
Jan 3, 2020
6ddadb4
Add back some positional tests
Jan 3, 2020
9c26d51
Enable format pointers
Jan 3, 2020
8a0bec6
Enable optionals
Jan 3, 2020
f4883ce
Enable errors
Jan 3, 2020
4698f87
Enable string printing
Jan 3, 2020
ce40708
Enable arrays
Jan 3, 2020
a774b79
Enable more trivial cases
Jan 3, 2020
6ed5502
Enable enums
Jan 3, 2020
f2060ef
Enable unions
Jan 3, 2020
3f0ecdf
Enable structs
Jan 3, 2020
7e50a2e
Enable recursion!
Jan 3, 2020
3329900
Partially working formatFloatExponent
Jan 3, 2020
e77efae
Work around async spill bug
Jan 4, 2020
7cb8cc8
Enable formatFloatDecimals
Jan 4, 2020
98e3d88
Enable formatBytes
Jan 4, 2020
9d8e84c
Migrate most fmt.* references to fmtgen
Jan 5, 2020
42a47eb
Leverage comptime recursion
Jan 6, 2020
5d0b2d9
Convert Generator to union based state machine
Jan 7, 2020
24e43df
General cleanup
Jan 7, 2020
11b04a6
Merge branch 'master' into format-generator
Jan 7, 2020
940fa5b
Migrate outStream (except debug.warn)
Jan 8, 2020
cc4fcd0
Merge branch 'master' into format-generator
Jan 13, 2020
b6ea8f9
Merge branch 'master' into format-generator
Jan 14, 2020
3915433
Combine yields as it's pretty expensive
Jan 14, 2020
9163e25
Simplified generator state as it's tested to be slightly faster
Jan 14, 2020
2272b90
Use intrusive generator yields
Jan 14, 2020
1661f50
Merge branch 'master' into format-generator
Jan 21, 2020
3b64d09
Sync with #4102, #4192, #4219
Jan 21, 2020
ce36f5c
Merge branch 'master' into format-generator
Jan 30, 2020
52a88b1
Pull in changes from fmt.zig
Jan 31, 2020
7a0c908
Merge branch 'master' into format-generator
Feb 10, 2020
7c8e358
Wire debug.warn into new OutStream
Feb 10, 2020
ab19af4
Enable custom formatter
Feb 10, 2020
1c6d6d2
Exhaustive enums
Feb 10, 2020
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
10 changes: 5 additions & 5 deletions doc/docgen.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1050,7 +1050,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
try out.write("<pre>");
try tokenizeAndPrint(tokenizer, out, code.source_token);
try out.write("</pre>");
const name_plus_ext = try std.fmt.allocPrint(allocator, "{}.zig", .{code.name});
const name_plus_ext = try std.fmtgen.allocPrint(allocator, "{}.zig", .{code.name});
const tmp_source_file_name = try fs.path.join(
allocator,
&[_][]const u8{ tmp_dir_name, name_plus_ext },
Expand All @@ -1059,7 +1059,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var

switch (code.id) {
Code.Id.Exe => |expected_outcome| code_block: {
const name_plus_bin_ext = try std.fmt.allocPrint(allocator, "{}{}", .{ code.name, exe_ext });
const name_plus_bin_ext = try std.fmtgen.allocPrint(allocator, "{}{}", .{ code.name, exe_ext });
var build_args = std.ArrayList([]const u8).init(allocator);
defer build_args.deinit();
try build_args.appendSlice(&[_][]const u8{
Expand Down Expand Up @@ -1090,7 +1090,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
},
}
for (code.link_objects) |link_object| {
const name_with_ext = try std.fmt.allocPrint(allocator, "{}{}", .{ link_object, obj_ext });
const name_with_ext = try std.fmtgen.allocPrint(allocator, "{}{}", .{ link_object, obj_ext });
const full_path_object = try fs.path.join(
allocator,
&[_][]const u8{ tmp_dir_name, name_with_ext },
Expand Down Expand Up @@ -1355,15 +1355,15 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
});
},
Code.Id.Obj => |maybe_error_match| {
const name_plus_obj_ext = try std.fmt.allocPrint(allocator, "{}{}", .{ code.name, obj_ext });
const name_plus_obj_ext = try std.fmtgen.allocPrint(allocator, "{}{}", .{ code.name, obj_ext });
const tmp_obj_file_name = try fs.path.join(
allocator,
&[_][]const u8{ tmp_dir_name, name_plus_obj_ext },
);
var build_args = std.ArrayList([]const u8).init(allocator);
defer build_args.deinit();

const name_plus_h_ext = try std.fmt.allocPrint(allocator, "{}.h", .{code.name});
const name_plus_h_ext = try std.fmtgen.allocPrint(allocator, "{}.h", .{code.name});
const output_h_file_name = try fs.path.join(
allocator,
&[_][]const u8{ tmp_dir_name, name_plus_h_ext },
Expand Down
4 changes: 2 additions & 2 deletions lib/std/atomic/queue.zig
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ test "std.atomic.Queue dump" {
sos.reset();
try queue.dumpToStream(SliceOutStream.Error, &sos.stream);

var expected = try std.fmt.bufPrint(expected_buffer[0..],
var expected = try std.fmtgen.bufPrint(expected_buffer[0..],
\\head: 0x{x}=1
\\ (null)
\\tail: 0x{x}=1
Expand All @@ -373,7 +373,7 @@ test "std.atomic.Queue dump" {
sos.reset();
try queue.dumpToStream(SliceOutStream.Error, &sos.stream);

expected = try std.fmt.bufPrint(expected_buffer[0..],
expected = try std.fmtgen.bufPrint(expected_buffer[0..],
\\head: 0x{x}=1
\\ 0x{x}=2
\\ (null)
Expand Down
12 changes: 2 additions & 10 deletions lib/std/buffer.zig
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,8 @@ pub const Buffer = struct {
}

pub fn allocPrint(allocator: *Allocator, comptime format: []const u8, args: var) !Buffer {
const countSize = struct {
fn countSize(size: *usize, bytes: []const u8) (error{}!void) {
size.* += bytes.len;
}
}.countSize;
var size: usize = 0;
std.fmt.format(&size, error{}, countSize, format, args) catch |err| switch (err) {};
var self = try Buffer.initSize(allocator, size);
assert((std.fmt.bufPrint(self.list.items, format, args) catch unreachable).len == size);
return self;
const slice = try std.fmtgen.allocPrint(allocator, format, args);
return Buffer.fromOwnedSlice(allocator, slice);
}

pub fn deinit(self: *Buffer) void {
Expand Down
6 changes: 5 additions & 1 deletion lib/std/fifo.zig
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,11 @@ pub fn LinearFifo(
pub usingnamespace if (T == u8)
struct {
pub fn print(self: *Self, comptime format: []const u8, args: var) !void {
return std.fmt.format(self, error{OutOfMemory}, Self.write, format, args);
var generator = std.fmtgen.Generator([]const u8).init();
_ = async std.fmtgen.format(&generator, format, args);
while (generator.next()) |bytes| {
try self.write(bytes);
}
}
}
else
Expand Down
Loading