Add build option to enable debug execution tracing
parent
e921a0dda8
commit
252190f5e6
|
@ -36,6 +36,14 @@ pub fn build(b: *std.Build) void {
|
||||||
.optimize = optimize,
|
.optimize = optimize,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Declare an option to build the program with debug statements
|
||||||
|
// (crafting interpreters: A virtual machine: execution tracing)
|
||||||
|
const executionTracing = b.option(bool, "tracing", "enable execution tracing") orelse false;
|
||||||
|
const options = b.addOptions();
|
||||||
|
options.addOption(bool, "tracing", executionTracing);
|
||||||
|
|
||||||
|
exe.root_module.addOptions("config", options);
|
||||||
|
|
||||||
// This declares intent for the executable to be installed into the
|
// This declares intent for the executable to be installed into the
|
||||||
// standard location when the user invokes the "install" step (the default
|
// standard location when the user invokes the "install" step (the default
|
||||||
// step when running `zig build`).
|
// step when running `zig build`).
|
||||||
|
|
|
@ -1,11 +1,15 @@
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
const config = @import("config");
|
||||||
|
|
||||||
const chunk = @import("./chunk.zig");
|
const chunk = @import("./chunk.zig");
|
||||||
const OpCode = chunk.OpCode;
|
const OpCode = chunk.OpCode;
|
||||||
const VM = @import("./vm.zig").VM;
|
const VM = @import("./vm.zig").VM;
|
||||||
|
|
||||||
pub fn main() !void {
|
pub fn main() !void {
|
||||||
// Prints to stderr (it's a shortcut based on `std.io.getStdErr()`)
|
// Prints to stderr (it's a shortcut based on `std.io.getStdErr()`)
|
||||||
|
if (config.tracing) {
|
||||||
std.debug.print("All your {s} are belong to us.\n", .{"codebase"});
|
std.debug.print("All your {s} are belong to us.\n", .{"codebase"});
|
||||||
|
}
|
||||||
|
|
||||||
var mem = std.heap.GeneralPurposeAllocator(.{}){};
|
var mem = std.heap.GeneralPurposeAllocator(.{}){};
|
||||||
const alloc = mem.allocator();
|
const alloc = mem.allocator();
|
||||||
|
|
Loading…
Reference in New Issue