aboutsummaryrefslogtreecommitdiff
path: root/src/interpreter.zig
blob: 5702336670727efa0c83058b0854280093e4ded9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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());
}