diff options
author | Julien Dessaux | 2022-06-09 23:17:53 +0200 |
---|---|---|
committer | Julien Dessaux | 2022-06-09 23:18:27 +0200 |
commit | 75fc1506e59c1eaa52971d20df72c7cbeca5ac82 (patch) | |
tree | 09ac84d955f9fc1f7c8bc5a11415f765296de42b /src/interpreter.zig | |
parent | Added submodules for the spec and the mycology test suite (diff) | |
download | zigfunge98-75fc1506e59c1eaa52971d20df72c7cbeca5ac82.tar.gz zigfunge98-75fc1506e59c1eaa52971d20df72c7cbeca5ac82.tar.bz2 zigfunge98-75fc1506e59c1eaa52971d20df72c7cbeca5ac82.zip |
Pass the sanity test
Diffstat (limited to 'src/interpreter.zig')
-rw-r--r-- | src/interpreter.zig | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/interpreter.zig b/src/interpreter.zig new file mode 100644 index 0000000..5702336 --- /dev/null +++ b/src/interpreter.zig @@ -0,0 +1,36 @@ +const std = @import("std"); +const field = @import("field.zig"); +const pointer = @import("pointer.zig"); + +pub const Interpreter = struct { + allocator: std.mem.Allocator, + field: *field.Field, + pointer: *pointer.Pointer, + + pub fn deinit(self: *Interpreter) void { + self.allocator.destroy(self); + } + pub fn init(allocator: std.mem.Allocator, f: *field.Field, p: *pointer.Pointer) !*Interpreter { + var i = try allocator.create(Interpreter); + errdefer allocator.destroy(i); + i.allocator = allocator; + i.field = f; + i.pointer = p; + return i; + } + pub fn run(self: *Interpreter) !i64 { + while (true) { + if (try self.pointer.exec()) |ret| { + if (ret.code) |code| { + return code; + } else { + return 0; + } + } + } + } +}; + +test "all" { + std.testing.refAllDecls(@This()); +} |