aboutsummaryrefslogtreecommitdiff
path: root/src/pex/node.zig
diff options
context:
space:
mode:
authorNathan Reiner <nathan@nathanreiner.xyz>2025-07-19 20:18:15 +0200
committerNathan Reiner <nathan@nathanreiner.xyz>2025-07-19 20:18:15 +0200
commitae10b7d764d9587ab92a682781f8479107e8dff0 (patch)
tree13e060f304ca1cac98ae1e71a2a6e27d9c5fb269 /src/pex/node.zig
parentd138a622dcc77302cc452c52946f6202b6a03f5e (diff)
add pex
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;
+}