Skip to content

Commit 0752c9d

Browse files
committed
more writergate upgrades
1 parent 840682e commit 0752c9d

File tree

3 files changed

+27
-28
lines changed

3 files changed

+27
-28
lines changed

src/errors.zig

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
const std = @import("std");
2+
const Writer = std.Io.Writer;
23
const builtin = @import("builtin");
34
const html = @import("html.zig");
45
const Span = @import("root.zig").Span;
56

6-
pub const ErrWriter = std.ArrayListUnmanaged(u8).Writer;
7-
87
/// Used to catch programming errors where a function fails to report
98
/// correctly that an error has occurred.
109
pub const Fatal = error{
@@ -29,7 +28,7 @@ pub const FatalShow = Fatal || error{
2928
pub const FatalShowOOM = error{OutOfMemory} || FatalShow;
3029

3130
pub fn report(
32-
writer: ErrWriter,
31+
writer: *Writer,
3332
template_name: []const u8,
3433
template_path: []const u8,
3534
bad_node: Span,
@@ -52,7 +51,7 @@ pub fn report(
5251
}
5352

5453
pub fn diagnostic(
55-
writer: ErrWriter,
54+
writer: *Writer,
5655
template_name: []const u8,
5756
template_path: []const u8,
5857
bracket_line: bool,
@@ -102,7 +101,7 @@ pub fn diagnostic(
102101
}
103102

104103
pub fn header(
105-
writer: ErrWriter,
104+
writer: *Writer,
106105
comptime title: []const u8,
107106
comptime msg: []const u8,
108107
) error{ErrIO}!void {
@@ -116,7 +115,7 @@ pub fn header(
116115
}
117116

118117
pub fn fatal(
119-
writer: ErrWriter,
118+
writer: *Writer,
120119
comptime fmt: []const u8,
121120
args: anytype,
122121
) Fatal {

src/template.zig

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const std = @import("std");
2+
const Writer = std.Io.Writer;
23
const scripty = @import("scripty");
34
const tracy = @import("tracy");
45
const root = @import("root.zig");
@@ -11,7 +12,7 @@ const Node = Ast.Node;
1112

1213
const log = std.log.scoped(.supertemplate);
1314

14-
pub fn SuperTemplate(comptime ScriptyVM: type, comptime OutWriter: type) type {
15+
pub fn SuperTemplate(comptime ScriptyVM: type) type {
1516
return struct {
1617
arena: std.mem.Allocator,
1718
name: []const u8,
@@ -82,7 +83,7 @@ pub fn SuperTemplate(comptime ScriptyVM: type, comptime OutWriter: type) type {
8283
std.debug.assert(tpl.print_cursor == tpl.print_end);
8384
}
8485

85-
pub fn showBlocks(tpl: Template, err_writer: errors.ErrWriter) error{ErrIO}!void {
86+
pub fn showBlocks(tpl: Template, err_writer: *Writer) error{ErrIO}!void {
8687
var found_first = false;
8788
var it = tpl.ast.blocks.iterator();
8889
while (it.next()) |kv| {
@@ -111,7 +112,7 @@ pub fn SuperTemplate(comptime ScriptyVM: type, comptime OutWriter: type) type {
111112
err_writer.print("\n", .{}) catch return error.ErrIO;
112113
}
113114

114-
pub fn showInterface(tpl: Template, err_writer: errors.ErrWriter) error{ErrIO}!void {
115+
pub fn showInterface(tpl: Template, err_writer: *Writer) error{ErrIO}!void {
115116
var found_first = false;
116117
var it = tpl.ast.interface.iterator();
117118
while (it.next()) |kv| {
@@ -144,8 +145,8 @@ pub fn SuperTemplate(comptime ScriptyVM: type, comptime OutWriter: type) type {
144145
script_vm: *ScriptyVM,
145146
script_ctx: *Context,
146147
super_id: []const u8,
147-
writer: OutWriter,
148-
err_writer: errors.ErrWriter,
148+
writer: *Writer,
149+
err_writer: *Writer,
149150
) errors.FatalOOM!void {
150151
_ = script_vm;
151152
_ = script_ctx;
@@ -245,8 +246,8 @@ pub fn SuperTemplate(comptime ScriptyVM: type, comptime OutWriter: type) type {
245246
tpl: *Template,
246247
scripty_vm: *ScriptyVM,
247248
scripty_ctx: *Context,
248-
writer: OutWriter,
249-
err_writer: errors.ErrWriter,
249+
writer: *Writer,
250+
err_writer: *Writer,
250251
) errors.FatalShowOOM!Continuation {
251252
const zone = tracy.trace(@src());
252253
defer zone.end();
@@ -922,7 +923,7 @@ pub fn SuperTemplate(comptime ScriptyVM: type, comptime OutWriter: type) type {
922923

923924
fn evalVar(
924925
tpl: *Template,
925-
err_writer: errors.ErrWriter,
926+
err_writer: *Writer,
926927
script_vm: *ScriptyVM,
927928
script_ctx: *Context,
928929
script_attr_name: Span,
@@ -976,7 +977,7 @@ pub fn SuperTemplate(comptime ScriptyVM: type, comptime OutWriter: type) type {
976977

977978
fn evalCtx(
978979
tpl: *Template,
979-
err_writer: errors.ErrWriter,
980+
err_writer: *Writer,
980981
script_vm: *ScriptyVM,
981982
script_ctx: *Context,
982983
script_attr_name: Span,
@@ -1028,7 +1029,7 @@ pub fn SuperTemplate(comptime ScriptyVM: type, comptime OutWriter: type) type {
10281029

10291030
fn evalAttr(
10301031
tpl: *Template,
1031-
err_writer: errors.ErrWriter,
1032+
err_writer: *Writer,
10321033
script_vm: *ScriptyVM,
10331034
script_ctx: *Context,
10341035
script_attr_name: Span,
@@ -1077,7 +1078,7 @@ pub fn SuperTemplate(comptime ScriptyVM: type, comptime OutWriter: type) type {
10771078

10781079
fn evalIf(
10791080
tpl: *Template,
1080-
err_writer: errors.ErrWriter,
1081+
err_writer: *Writer,
10811082
script_vm: *ScriptyVM,
10821083
script_ctx: *Context,
10831084
script_attr_name: Span,
@@ -1130,7 +1131,7 @@ pub fn SuperTemplate(comptime ScriptyVM: type, comptime OutWriter: type) type {
11301131

11311132
fn evalLoop(
11321133
tpl: *Template,
1133-
err_writer: errors.ErrWriter,
1134+
err_writer: *Writer,
11341135
script_vm: *ScriptyVM,
11351136
script_ctx: *Context,
11361137
script_attr_name: Span,
@@ -1183,7 +1184,7 @@ pub fn SuperTemplate(comptime ScriptyVM: type, comptime OutWriter: type) type {
11831184

11841185
pub fn reportError(
11851186
self: Template,
1186-
err_writer: errors.ErrWriter,
1187+
err_writer: *Writer,
11871188
bad_node: Span,
11881189
error_code: []const u8,
11891190
comptime title: []const u8,
@@ -1203,7 +1204,7 @@ pub fn SuperTemplate(comptime ScriptyVM: type, comptime OutWriter: type) type {
12031204

12041205
pub fn diagnostic(
12051206
tpl: Template,
1206-
err_writer: errors.ErrWriter,
1207+
err_writer: *Writer,
12071208
bracket: bool,
12081209
note_line: []const u8,
12091210
bad_node: Span,

src/vm.zig

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const std = @import("std");
2+
const Writer = std.Io.Writer;
23
const scripty = @import("scripty");
34
const tracy = @import("tracy");
45
const errors = @import("errors.zig");
@@ -33,8 +34,8 @@ pub fn VM(
3334
return struct {
3435
arena: std.mem.Allocator,
3536
content_name: []const u8,
36-
out: OutWriter,
37-
err: ErrWriter,
37+
out: *Writer,
38+
err: *Writer,
3839

3940
state: State,
4041
quota: usize = 100,
@@ -49,11 +50,9 @@ pub fn VM(
4950
}) = .{},
5051

5152
const ScriptyVM = scripty.VM(Context, Value);
52-
const OutWriter = std.ArrayListUnmanaged(u8).Writer;
53-
const ErrWriter = errors.ErrWriter;
5453
const Self = @This();
5554

56-
pub const Template = SuperTemplate(ScriptyVM, OutWriter);
55+
pub const Template = SuperTemplate(ScriptyVM);
5756
pub const State = union(enum) {
5857
init: TemplateCartridge,
5958
discovering_templates,
@@ -88,8 +87,8 @@ pub fn VM(
8887
layout_super_ast: Ast,
8988
layout_is_xml: bool,
9089
content_name: []const u8,
91-
out_writer: OutWriter,
92-
err_writer: ErrWriter,
90+
out_writer: *Writer,
91+
err_writer: *Writer,
9392
) Self {
9493
return .{
9594
.arena = arena,
@@ -568,7 +567,7 @@ pub fn VM(
568567
fn fatalTrace(
569568
content_name: []const u8,
570569
items: []const Template,
571-
err_writer: errors.ErrWriter,
570+
err_writer: *Writer,
572571
) errors.Fatal {
573572
err_writer.print("trace:\n", .{}) catch return error.ErrIO;
574573
var cursor = items.len - 1;

0 commit comments

Comments
 (0)