Skip to content

Commit 7311c4e

Browse files
authored
Merge pull request #7 from daniellehrner/feat/stack-refactor
Replace heap-allocated Stack with fixed-size array
2 parents 69c3579 + 717631e commit 7311c4e

File tree

6 files changed

+437
-154
lines changed

6 files changed

+437
-154
lines changed

build.zig

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,20 @@ pub fn build(b: *std.Build) void {
328328
const test_step = b.step("test", "Run unit tests");
329329
test_step.dependOn(&run_tests.step);
330330

331+
// Inline zig tests for interpreter module (discovers tests in all imported files)
332+
const interpreter_tests = b.addTest(.{
333+
.root_module = b.createModule(.{
334+
.root_source_file = .{ .src_path = .{ .owner = b, .sub_path = "src/interpreter/main.zig" } },
335+
.target = target,
336+
.optimize = optimize,
337+
}),
338+
});
339+
interpreter_tests.root_module.addImport("primitives", primitives_module);
340+
interpreter_tests.root_module.addImport("bytecode", bytecode_module);
341+
interpreter_tests.root_module.addImport("context", context_module);
342+
const run_interpreter_tests = b.addRunArtifact(interpreter_tests);
343+
test_step.dependOn(&run_interpreter_tests.step);
344+
331345
// Precompile unit tests - these are run via zig test command in CI
332346
// The command needs to link libc and include all modules
333347
// See .github/workflows/ci.yml for the full command

examples/benchmark.zig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ fn benchmarkStackOperations() !void {
6868

6969
const iterations = 100_000;
7070
var stack = interpreter.Stack.new();
71-
defer stack.deinit();
7271

7372
const start_time = std.time.nanoTimestamp();
7473

src/handler/main.zig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ pub const FrameResult = struct {
145145
pub fn deinit(self: *FrameResult) void {
146146
self.result.deinit();
147147
self.memory.deinit();
148-
self.stack.deinit();
149148
}
150149
};
151150

src/interpreter/interpreter.zig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,6 @@ pub const Interpreter = struct {
391391
/// Deinitialize the interpreter
392392
pub fn deinit(self: *Interpreter) void {
393393
self.bytecode.deinit();
394-
self.stack.deinit();
395394
self.memory.deinit();
396395
}
397396

src/interpreter/main.zig

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,6 @@ pub const testing = struct {
4545
std.debug.print("Gas tests passed.\n", .{});
4646
}
4747

48-
pub fn testStack() !void {
49-
var stack = Stack.new();
50-
std.debug.assert(stack.len() == 0);
51-
52-
try stack.push(@as(primitives.U256, 1));
53-
std.debug.assert(stack.len() == 1);
54-
55-
const value = stack.pop() orelse return error.StackEmpty;
56-
std.debug.assert(value == @as(primitives.U256, 1));
57-
58-
std.debug.print("Stack tests passed.\n", .{});
59-
}
60-
6148
pub fn testMemory() !void {
6249
var memory = Memory.new();
6350
std.debug.assert(memory.size() == 0);

0 commit comments

Comments
 (0)