From ae10b7d764d9587ab92a682781f8479107e8dff0 Mon Sep 17 00:00:00 2001 From: Nathan Reiner Date: Sat, 19 Jul 2025 20:18:15 +0200 Subject: add pex --- src/pex/node.zig | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/pex/node.zig (limited to 'src/pex/node.zig') 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; +} -- cgit v1.2.3-70-g09d2