const std = @import("std"); const tree = @import("tree.zig"); const Arena = @import("arena.zig").Arena; const embed = @import("kernel_embed"); /// Copy the embedded kernel into an arena, returning the new root index. /// This allows the kernel to be used in App nodes alongside application terms. pub fn loadKernel(arena: *Arena) !u32 { var mapping = try arena.allocator.alloc(u32, embed.kernel_nodes.len); defer arena.allocator.free(mapping); for (embed.kernel_nodes, 0..) |node, i| { const idx: u32 = @intCast(i); mapping[idx] = switch (node) { .leaf => try arena.alloc(.leaf), .stem => |s| try arena.alloc(.{ .stem = .{ .child = mapping[s.child] } }), .fork => |f| try arena.alloc(.{ .fork = .{ .left = mapping[f.left], .right = mapping[f.right] } }), }; } return mapping[embed.kernel_root]; }