commit 4f386277351b7c1ee0ac5fb64050b2dc0d428c8b
parent dc9ac95d0cb79567bce37c0b500f35cb1b180c29
Author: Walther Chen <walther.chen@gmail.com>
Date:   Tue,  8 Nov 2022 22:51:24 -0500

Update interface of interpret to include alloc, clean og stage

Diffstat:
Msrc/common.zig | 4++--
Msrc/og.zig | 8+++++---
2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/src/common.zig b/src/common.zig @@ -27,7 +27,7 @@ pub fn runInterpreter(interpret: anytype) anyerror!void { const program = try parse(src, alloc); defer program.deinit(); - try interpret(program, &memory, stdin.reader(), stdout.writer()); + try interpret(program, &memory, stdin.reader(), stdout.writer(), alloc); } fn parse(src: []const u8, alloc: std.mem.Allocator) !Program { @@ -68,6 +68,6 @@ pub fn testHelloWorld(interpret: anytype) anyerror!void { var wtr = list.writer(); const program = Program{ .instructions = hello_world, .alloc = std.testing.allocator }; - try interpret(program, &memory, rdr, wtr); + try interpret(program, &memory, rdr, wtr, std.testing.allocator); try expectEqualSlices(u8, "Hello World!\n", list.items); } diff --git a/src/og.zig b/src/og.zig @@ -10,12 +10,14 @@ test "og: interpret hello world" { try common.testHelloWorld(interpret); } -fn interpret(program: Program, memory: []u8, rdr: anytype, wtr: anytype) !void { +fn interpret(program: Program, memory: []u8, rdr: anytype, wtr: anytype, alloc: std.mem.Allocator) !void { + _ = alloc; + + const instructions = program.instructions; var pc: usize = 0; var dataptr: usize = 0; - while (pc < program.instructions.len) { - const instructions = program.instructions; + while (pc < instructions.len) { const instruction = instructions[pc]; switch (instruction) {