kernel.zig (880B)
1 const std = @import("std"); 2 const tree = @import("tree.zig"); 3 const Arena = @import("arena.zig").Arena; 4 const embed = @import("kernel_embed"); 5 6 /// Copy the embedded kernel into an arena, returning the new root index. 7 /// This allows the kernel to be used in App nodes alongside application terms. 8 pub fn loadKernel(arena: *Arena) !u32 { 9 var mapping = try arena.allocator.alloc(u32, embed.kernel_nodes.len); 10 defer arena.allocator.free(mapping); 11 12 for (embed.kernel_nodes, 0..) |node, i| { 13 const idx: u32 = @intCast(i); 14 mapping[idx] = switch (node) { 15 .leaf => try arena.alloc(.leaf), 16 .stem => |s| try arena.alloc(.{ .stem = .{ .child = mapping[s.child] } }), 17 .fork => |f| try arena.alloc(.{ .fork = .{ .left = mapping[f.left], .right = mapping[f.right] } }), 18 }; 19 } 20 21 return mapping[embed.kernel_root]; 22 }