aboutsummaryrefslogtreecommitdiff
path: root/src/pex/node.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/pex/node.zig')
-rw-r--r--src/pex/node.zig36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/pex/node.zig b/src/pex/node.zig
new file mode 100644
index 0000000..7abb274
--- /dev/null
+++ b/src/pex/node.zig
@@ -0,0 +1,36 @@
+const std = @import("std");
+const Instruction = @import("instruction.zig").Instruction;
+
+const Self = @This();
+
+instruction: Instruction,
+next: ?*Self = null,
+
+pub fn create(instruction: Instruction, node_pool: *std.heap.MemoryPool(Self)) !*Self {
+ const node = try node_pool.create();
+ node.* = .{ .instruction = instruction };
+ return node;
+}
+
+pub fn deinit(self: *Self) void {
+ if (self.next) |next| {
+ next.deinit();
+ }
+ self.* = undefined;
+}
+
+pub fn clone(
+ self: *Self,
+ node_pool: *std.heap.MemoryPool(Self),
+) !*Self {
+ const self_clone = try node_pool.create();
+ self_clone.instruction = self.instruction;
+
+ if (self.next) |next| {
+ self_clone.next = try next.clone(node_pool);
+ } else {
+ self_clone.next = null;
+ }
+
+ return self_clone;
+}