blob: 7abb274fea9e44e429c974bebd08f73816a297d4 (
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 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;
}
|