Skip to content

Commit a97a444

Browse files
committed
better vm interface and tracy integration
- tracy moved to an external dependency - vm now asks for pre-parsed templates the second change allows to properly stage parsing before running templates
1 parent 240cc44 commit a97a444

File tree

7 files changed

+49
-358
lines changed

7 files changed

+49
-358
lines changed

build.zig

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,15 @@ pub fn build(b: *std.Build) !void {
1313
const scripty = b.dependency("scripty", .{});
1414

1515
const enable_tracy = b.option(bool, "tracy", "Enable Tracy profiling") orelse false;
16-
const tracy_options = b.addOptions();
17-
tracy_options.addOption(bool, "enable_tracy", enable_tracy);
18-
tracy_options.addOption(bool, "enable_tracy_allocation", false);
19-
tracy_options.addOption(bool, "enable_tracy_callstack", true);
20-
tracy_options.addOption(usize, "tracy_callstack_depth", 10);
16+
17+
const tracy = b.dependency("tracy", .{ .enable = enable_tracy });
2118

2219
const superhtml = b.addModule("superhtml", .{
2320
.root_source_file = b.path("src/root.zig"),
2421
.target = target,
2522
});
2623
superhtml.addImport("scripty", scripty.module("scripty"));
27-
superhtml.addOptions("tracy_options", tracy_options);
24+
superhtml.addImport("tracy", tracy.module("tracy"));
2825

2926
if (enable_tracy) {
3027
if (target.result.os.tag == .windows) {
@@ -106,15 +103,13 @@ fn setupTestStep(
106103
test_step.dependOn(check);
107104

108105
const unit_tests = b.addTest(.{
109-
.root_source_file = b.path("src/root.zig"),
106+
.root_module = superhtml,
110107
.target = target,
111108
.optimize = .Debug,
112109
// .strip = true,
113110
// .filter = "if-else-loop",
114111
});
115112

116-
unit_tests.root_module.addImport("superhtml", superhtml);
117-
118113
const run_unit_tests = b.addRunArtifact(unit_tests);
119114
test_step.dependOn(&run_unit_tests.step);
120115

build.zig.zon

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@
88
.url = "git+https://github.com/kristoff-it/zig-lsp-kit#87ff3d537a0c852442e180137d9557711963802c",
99
.hash = "lsp_kit-0.1.0-hAAxO9S9AADv_5D0iplASFtNCFXAPk54M0u-3jj2MRFk",
1010
},
11-
.scripty = .{
12-
.url = "git+https://github.com/kristoff-it/scripty#37dad0cc4a527d9b8148db7b8bfce5cc3670e3fa",
13-
.hash = "scripty-0.1.0-LKK5O93AAAAsHaPH44imnLqQ9dKHj-y-jOapdwBe4Dxs",
14-
},
1511
.afl_kit = .{
1612
.url = "git+https://github.com/kristoff-it/zig-afl-kit?ref=zig-0.14.0#1e9fcaa08361307d16a9bde82b4a7fd4560ce502",
1713
.hash = "afl_kit-0.1.0-uhOgGDkdAAALG16McR2B4b8QwRUQ2sa9XdgDTFXRWQTY",
@@ -21,6 +17,14 @@
2117
.url = "git+https://github.com/ziglibs/known-folders#aa24df42183ad415d10bc0a33e6238c437fc0f59",
2218
.hash = "known_folders-0.0.0-Fy-PJtLDAADGDOwYwMkVydMSTp_aN-nfjCZw6qPQ2ECL",
2319
},
20+
.tracy = .{
21+
.url = "git+https://github.com/kristoff-it/tracy#67d2d89e351048c76fc6d161e0ac09d8a831dc60",
22+
.hash = "tracy-0.0.0-4Xw-1pwwAABTfMgoDP1unCbZDZhJEfict7XCBGF6IdIn",
23+
},
24+
.scripty = .{
25+
.url = "git+https://github.com/kristoff-it/scripty#57056571abcc6fe69fcb171c10b0c9e5962f53b0",
26+
.hash = "scripty-0.1.0-LKK5O9jDAADwZbkwkzYcmtTD3xIStr1SNYWL0kcGf8sk",
27+
},
2428
},
2529
.paths = .{
2630
"LICENSE",

src/html/Ast.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const Ast = @This();
22

33
const std = @import("std");
4-
const tracy = @import("../tracy.zig");
4+
const tracy = @import("tracy");
55
const root = @import("../root.zig");
66
const Language = root.Language;
77
const Span = root.Span;

src/html/Tokenizer.zig

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ const named_character_references = @import("named_character_references.zig");
1212

1313
const std = @import("std");
1414
const root = @import("../root.zig");
15-
const tracy = @import("../tracy.zig");
1615
const Language = root.Language;
1716
const Span = root.Span;
1817

@@ -397,9 +396,6 @@ pub fn getName(tokenizer: *Tokenizer, tag_src: []const u8) ?Span {
397396
}
398397

399398
pub fn next(self: *Tokenizer, src: []const u8) ?Token {
400-
const zone = tracy.trace(@src());
401-
defer zone.end();
402-
403399
if (self.deferred_token) |t| {
404400
const token_copy = t;
405401
self.deferred_token = null;

src/template.zig

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const std = @import("std");
22
const scripty = @import("scripty");
3+
const tracy = @import("tracy");
34
const root = @import("root.zig");
45
const errors = @import("errors.zig");
56
const html = @import("html.zig");
@@ -247,6 +248,9 @@ pub fn SuperTemplate(comptime ScriptyVM: type, comptime OutWriter: type) type {
247248
writer: OutWriter,
248249
err_writer: errors.ErrWriter,
249250
) errors.FatalShowOOM!Continuation {
251+
const zone = tracy.trace(@src());
252+
defer zone.end();
253+
250254
scripty_vm.reset();
251255
scripty_ctx.ctx._map = &tpl.ctx;
252256
std.debug.assert(tpl.cursor.current() != null);
@@ -924,6 +928,9 @@ pub fn SuperTemplate(comptime ScriptyVM: type, comptime OutWriter: type) type {
924928
script_attr_name: Span,
925929
code_span: Span,
926930
) errors.Fatal!Value {
931+
const zone = tracy.trace(@src());
932+
defer zone.end();
933+
927934
tpl.setContext(script_ctx);
928935

929936
const result = script_vm.run(
@@ -974,6 +981,9 @@ pub fn SuperTemplate(comptime ScriptyVM: type, comptime OutWriter: type) type {
974981
script_attr_name: Span,
975982
code_span: Span,
976983
) errors.Fatal!Value {
984+
const zone = tracy.trace(@src());
985+
defer zone.end();
986+
977987
tpl.setContext(script_ctx);
978988

979989
const result = script_vm.run(
@@ -1022,6 +1032,9 @@ pub fn SuperTemplate(comptime ScriptyVM: type, comptime OutWriter: type) type {
10221032
script_attr_name: Span,
10231033
code_span: Span,
10241034
) errors.Fatal!ScriptyVM.Result {
1035+
const zone = tracy.trace(@src());
1036+
defer zone.end();
1037+
10251038
tpl.setContext(script_ctx);
10261039
const result = script_vm.run(
10271040
tpl.arena,
@@ -1067,6 +1080,9 @@ pub fn SuperTemplate(comptime ScriptyVM: type, comptime OutWriter: type) type {
10671080
script_attr_name: Span,
10681081
code_span: Span,
10691082
) errors.Fatal!Value {
1083+
const zone = tracy.trace(@src());
1084+
defer zone.end();
1085+
10701086
tpl.setContext(script_ctx);
10711087
const result = script_vm.run(
10721088
tpl.arena,
@@ -1116,6 +1132,9 @@ pub fn SuperTemplate(comptime ScriptyVM: type, comptime OutWriter: type) type {
11161132
script_attr_name: Span,
11171133
code_span: Span,
11181134
) errors.Fatal!*Value.Iterator {
1135+
const zone = tracy.trace(@src());
1136+
defer zone.end();
1137+
11191138
tpl.setContext(script_ctx);
11201139

11211140
const result = script_vm.run(

0 commit comments

Comments
 (0)