documentation updates, imported tag pool, beginning work on lz4 reading/writing

This commit is contained in:
Peterino2 2026-10-31 12:55:20 -07:00
parent b7b2fa177f
commit 3d4be7570e
15 changed files with 469 additions and 184 deletions

View File

@ -1,3 +1,24 @@
## Build and validation # Working with Ribtech
This project uses zig 0.17.0
Use the installed Zig toolchain as the source of truth. Do not rely on remembered
APIs or hand-maintained summaries when the compiler distribution can answer the
question directly.
- Run `zig env` to locate `zig_exe`, `lib_dir`, and `std_dir`; do not assume a
particular installation path.
- Consult `<directory containing zig_exe>/doc/langref.html` for language syntax,
semantics, and builtins.
- Search `std_dir` for exact APIs, implementations, and tests. Use them as
examples of both correct usage and Zig coding style; follow standard-library
- conventions.
- Use compiler and test failures to verify any inferred API usage.
for `if` conditions, put continuation `and`/`or` operators at the start of
the next line. Run `zig fmt` on changed Zig files.
If the installed documentation is unavailable, use the versioned official
reference at <https://ziglang.org/documentation/0.17.0/> download a copy once and
avoid unessecary traffic.
Use Zig 0.17.0. Read `zig/SKILL.md` before doing any Zig work.

View File

@ -4,6 +4,18 @@ pub fn build(b: *std.Build) void {
const optimize = b.standardOptimizeOption(.{}); const optimize = b.standardOptimizeOption(.{});
const target = b.standardTargetOptions(.{}); const target = b.standardTargetOptions(.{});
const slugger = b.dependency("slugger", .{ .target = target, .optimize = optimize });
const core = b.addModule("core", .{
.root_source_file = b.path("src/core/core.zig"),
.target = target,
.optimize = optimize,
.imports = &.{.{ .name = "slugger", .module = slugger.module("slugger") }},
});
const core_tests = b.addTest(.{ .root_module = core });
b.step("test", "Run core tests").dependOn(&b.addRunArtifact(core_tests).step);
const parser = b.addExecutable(.{ const parser = b.addExecutable(.{
.root_module = b.createModule(.{ .root_module = b.createModule(.{
.optimize = optimize, .optimize = optimize,

10
engine/build.zig.zon Normal file
View File

@ -0,0 +1,10 @@
.{
.name = .engine,
.fingerprint = 0xe8a81a8d8caad42b,
.version = "0.0.0",
.minimum_zig_version = "0.17.0",
.dependencies = .{
.slugger = .{ .path = "lib/slugger" },
},
.paths = .{ "build.zig", "build.zig.zon", "src", "lib", "tools", "programs" },
}

View File

@ -36,4 +36,21 @@ pub fn build(b: *std.Build) void {
"xxhash.c", "xxhash.c",
}, },
}); });
const lz4_zig = b.addModule("lz4_zig", .{
.target = target,
.optimize = optimize,
.pic = pic,
.strip = strip,
.link_libc = true,
.root_source_file = b.path("lz4.zig"),
});
lz4_zig.linkLibrary(lz4);
const tests = b.addTes(.{ .root_module = lz4_zig });
const run_tests = b.addRunArtifact(tests);
run_tests.addPassthruArgs();
b.step("test", "runs lz4_zig tests").dependOn(&run_tests.step);
} }

View File

View File

@ -97,6 +97,16 @@ pub const destroyNameRegistry = names.destroyNameRegistry;
pub const setNameRegistry = names.setNameRegistry; pub const setNameRegistry = names.setNameRegistry;
pub const NameRegistry = names.NameRegistry; pub const NameRegistry = names.NameRegistry;
pub const tag_pool = @import("structures/tag-pool.zig");
pub const RawTag = tag_pool.RawTag;
pub const TagPool = tag_pool.TagPool;
pub const TagPoolRegistry = tag_pool.TagPoolRegistry;
pub const DeclareTagPool = tag_pool.DeclareTagPool;
pub const createTagPoolRegistry = tag_pool.createTagPoolRegistry;
pub const setTagPoolRegistry = tag_pool.setTagPoolRegistry;
pub const getTagPoolRegistry = tag_pool.getTagPoolRegistry;
pub const destroyTagPoolRegistry = tag_pool.destroyTagPoolRegistry;
pub const spans = @import("structures/spans.zig"); pub const spans = @import("structures/spans.zig");
pub const MergedSpans = spans.MergedSpans; pub const MergedSpans = spans.MergedSpans;
pub const Span = spans.Span; pub const Span = spans.Span;
@ -134,6 +144,7 @@ comptime {
std.testing.refAllDecls(string_pool); std.testing.refAllDecls(string_pool);
std.testing.refAllDecls(ref_string_map); std.testing.refAllDecls(ref_string_map);
std.testing.refAllDecls(spans); std.testing.refAllDecls(spans);
std.testing.refAllDecls(tag_pool);
} }
// ---- aliases ---- // ---- aliases ----

View File

@ -645,7 +645,7 @@ test "concatSlice" {
const left = try RefString.new("rib"); const left = try RefString.new("rib");
defer left.drop(); defer left.drop();
const joined = try left.concatSlice("tech"); const joined = try left.concatSlice("lab");
defer joined.drop(); defer joined.drop();
try std.testing.expectEqualStrings("riblab", joined.getUtf8()); try std.testing.expectEqualStrings("riblab", joined.getUtf8());

View File

@ -0,0 +1,289 @@
// Named string-interning pools. Each pool maps strings to compact u32 tags
// 24 bits of index 8 identifying which pool it came from,
const std = @import("std");
// Raw tag handle stored by the registry. Prefer typed pool-specific tags from DeclareTagPool().
pub const RawTag = packed struct(u32) {
index: u24 = 0,
pool: u8 = 0,
pub fn toInt(self: @This()) u32 {
return @bitCast(self);
}
pub fn toStringZ(self: *@This()) ?[:0]const u8 {
const registry = getTagPoolRegistry();
std.debug.assert(registry.pools.items.len > self.pool);
const pool = registry.pools.items[@intCast(self.pool)];
std.debug.assert(pool.stringList.items.len > self.index);
return pool.stringList.items[@intCast(self.index)];
}
pub fn toString(self: *@This()) ?[]const u8 {
return (self.toStringZ() orelse return null);
}
};
pub const TagPool = struct {
backing: std.mem.Allocator = undefined,
poolName: []const u8 = undefined,
arena: std.heap.ArenaAllocator = undefined,
keys: std.StringHashMapUnmanaged(u24) = .{},
stringList: std.ArrayList([:0]const u8) = .empty, // stored as zero sentinel and non-writeable for c compat
poolIndex: u8 = 0,
pub fn createInternal(allocator: std.mem.Allocator, name: []const u8) !*@This() {
const self = try allocator.create(@This());
self.* = .{
.backing = allocator,
.arena = std.heap.ArenaAllocator.init(allocator),
};
errdefer self.destroy();
self.poolName = try self.arena.allocator().dupe(u8, name);
return self;
}
pub fn getRawTag(self: *@This(), string: []const u8) RawTag {
return self.getRawTagFallible(string) catch |err| switch (err) {
error.TagPoolExhausted => @panic("tag limit exceeded"),
error.OutOfMemory => @panic("unable to allocate tag"),
};
}
pub fn findRawTag(self: *const @This(), string: []const u8) ?RawTag {
const index = self.keys.get(string) orelse return null;
return .{ .index = index, .pool = self.poolIndex };
}
pub fn getRawTagFallible(self: *@This(), string: []const u8) error{ OutOfMemory, TagPoolExhausted }!RawTag {
if (self.keys.get(string)) |key| {
return .{ .index = key, .pool = self.poolIndex };
}
if (self.stringList.items.len >= 1 << 24) return error.TagPoolExhausted;
const allocator = self.arena.allocator();
try self.keys.ensureUnusedCapacity(allocator, 1);
try self.stringList.ensureUnusedCapacity(allocator, 1);
const rv = RawTag{ .index = @intCast(self.stringList.items.len), .pool = self.poolIndex };
const st = try allocator.dupeSentinel(u8, string, 0);
self.keys.putAssumeCapacity(st, rv.index);
self.stringList.appendAssumeCapacity(st);
return rv;
}
pub fn destroy(self: *@This()) void {
self.arena.deinit();
self.backing.destroy(self);
}
};
pub const TagPoolRegistry = struct {
allocator: std.mem.Allocator,
pools: std.ArrayList(*TagPool) = .empty,
poolsByName: std.StringHashMapUnmanaged(u8) = .{},
pub fn init(allocator: std.mem.Allocator) @This() {
return .{ .allocator = allocator };
}
/// Takes ownership of `p` and assigns its pool index.
pub fn newTagPool(self: *@This(), p: *TagPool) error{ OutOfMemory, TagPoolRegistryExhausted }!u8 {
const index = self.pools.items.len;
if (index > std.math.maxInt(u8)) return error.TagPoolRegistryExhausted;
try self.pools.ensureUnusedCapacity(self.allocator, 1);
try self.poolsByName.put(self.allocator, p.poolName, @intCast(index));
self.pools.appendAssumeCapacity(p);
p.poolIndex = @intCast(index);
return @intCast(index);
}
pub fn findPool(self: *const @This(), name: []const u8) ?*TagPool {
const index = self.poolsByName.get(name) orelse return null;
return self.pools.items[index];
}
pub fn deinit(self: *@This()) void {
for (self.pools.items) |pool| {
pool.destroy();
}
self.pools.deinit(self.allocator);
self.poolsByName.deinit(self.allocator);
}
};
pub var gTagPoolRegistry: *TagPoolRegistry = undefined;
var registryCreated: bool = false;
var registryOwned: bool = false;
pub fn createTagPoolRegistry(allocator: std.mem.Allocator) !*TagPoolRegistry {
if (!registryCreated) {
gTagPoolRegistry = try allocator.create(TagPoolRegistry);
gTagPoolRegistry.* = .init(allocator);
registryCreated = true;
registryOwned = true;
}
return gTagPoolRegistry;
}
pub fn setTagPoolRegistry(registry: *TagPoolRegistry) void {
gTagPoolRegistry = registry;
registryCreated = true;
registryOwned = false;
}
pub fn isReady() bool {
return registryCreated;
}
pub fn getTagPoolRegistry() *TagPoolRegistry {
if (!registryCreated) @panic("tag pool registry not created");
return gTagPoolRegistry;
}
pub fn destroyTagPoolRegistry() void {
if (!registryCreated) return;
if (registryOwned) {
const allocator = gTagPoolRegistry.allocator;
gTagPoolRegistry.deinit();
allocator.destroy(gTagPoolRegistry);
}
registryCreated = false;
registryOwned = false;
}
pub fn DeclareTagPool(comptime name: []const u8) type {
const Interface = struct {
pub const Tag = packed struct(u32) {
raw: RawTag,
pub fn toInt(self: @This()) u32 {
return self.raw.toInt();
}
pub fn toStringZ(self: *@This()) ?[:0]const u8 {
return self.raw.toStringZ();
}
pub fn toString(self: *@This()) ?[]const u8 {
return self.raw.toString();
}
};
pub fn ComptimeTag(comptime string: []const u8) type {
return struct {
pub var tag: ?Tag = null;
pub const staticString = string;
pub fn get() Tag {
if (tag) |t| {
return t;
}
tag = getTag(staticString);
return tag.?;
}
};
}
pub const tagPoolName = name;
pub var PoolIndex: ?u8 = null; // null means uninitialized
pub var staticInstance: *TagPool = undefined;
pub fn initialize() !void {
const registry = getTagPoolRegistry();
// if it's already initialized, use that slot
if (registry.findPool(tagPoolName)) |pool| {
staticInstance = pool;
} else {
const pool = try TagPool.createInternal(registry.allocator, tagPoolName);
errdefer pool.destroy();
_ = try registry.newTagPool(pool);
staticInstance = pool;
}
PoolIndex = staticInstance.poolIndex;
}
pub fn getPool() *TagPool {
if (PoolIndex == null) {
@panic("trying to access uninitialized pool");
}
return staticInstance;
}
pub fn getTag(string: []const u8) Tag {
return .{ .raw = getPool().getRawTag(string) };
}
pub fn findTag(string: []const u8) ?Tag {
const raw = getPool().findRawTag(string) orelse return null;
return .{ .raw = raw };
}
pub fn getTagFallible(string: []const u8) !Tag {
return .{ .raw = try getPool().getRawTagFallible(string) };
}
};
return Interface;
}
test "tag pool interns and round-trips strings" {
_ = try createTagPoolRegistry(std.testing.allocator);
defer destroyTagPoolRegistry();
const Pool = DeclareTagPool("test.tag_pool.intern");
try Pool.initialize();
var a = Pool.getTag("alpha");
const b = Pool.getTag("beta");
const a2 = Pool.getTag("alpha");
try std.testing.expectEqual(a.toInt(), a2.toInt());
try std.testing.expect(a.toInt() != b.toInt());
try std.testing.expectEqualStrings("alpha", a.toStringZ().?);
try std.testing.expectEqualStrings("alpha", a.toString().?);
try std.testing.expectEqual(a.toInt(), Pool.findTag("alpha").?.toInt());
try std.testing.expect(Pool.findTag("missing") == null);
}
test "tag pools get distinct indices and redeclaring reuses the slot" {
_ = try createTagPoolRegistry(std.testing.allocator);
defer destroyTagPoolRegistry();
const First = DeclareTagPool("test.tag_pool.first");
const Second = DeclareTagPool("test.tag_pool.second");
const FirstAgain = DeclareTagPool("test.tag_pool.first");
try First.initialize();
try Second.initialize();
try FirstAgain.initialize();
try std.testing.expect(First.PoolIndex.? != Second.PoolIndex.?);
try std.testing.expectEqual(First.getPool(), FirstAgain.getPool());
var first = First.getTag("same");
var second = Second.getTag("same");
try std.testing.expect(first.toInt() != second.toInt());
try std.testing.expectEqualStrings("same", first.toString().?);
try std.testing.expectEqualStrings("same", second.toString().?);
}
test "comptime tag caches its lookup" {
_ = try createTagPoolRegistry(std.testing.allocator);
defer destroyTagPoolRegistry();
const Pool = DeclareTagPool("test.tag_pool.comptime");
try Pool.initialize();
const Hello = Pool.ComptimeTag("hello");
Hello.tag = null;
const t = Hello.get();
try std.testing.expectEqual(t.toInt(), Hello.tag.?.toInt());
try std.testing.expectEqual(t.toInt(), Pool.findTag("hello").?.toInt());
}

View File

@ -605,8 +605,16 @@ pub fn DeclareLoggerSystem(comptime opts: LoggerSystemInitOptions) type {
pub const LoggerSystem = DeclareLoggerSystem(.{}); pub const LoggerSystem = DeclareLoggerSystem(.{});
pub fn initialize(io: std.Io, allocator: std.mem.Allocator, payload_allocator: std.mem.Allocator) void { pub fn initialize(
io: std.Io,
allocator: std.mem.Allocator,
payload_allocator: std.mem.Allocator,
use_stdout: bool,
) void {
gLoggerSystem.init(io, allocator, payload_allocator); gLoggerSystem.init(io, allocator, payload_allocator);
if (use_stdout) {
try gLoggerSystem.addStdout();
}
} }
/// Counts rejected full-queue submissions (including retries) and events lost /// Counts rejected full-queue submissions (including retries) and events lost
@ -1042,154 +1050,6 @@ pub fn DeclareLogger(comptime LoggerName: []const u8, comptime opts: LoggerOptio
}; };
} }
const std = @import("std");
const builtin = @import("builtin");
// test "structured logging end to end" {
// const Logger = DeclareLogger("normal", .{});
// const Record = struct { id: i16, enabled: bool, position: struct { x: f32, label: []const u8 } };
// const emit = struct {
// fn log(comptime fmt: []const u8, args: anytype) !void {
// const before = gLoggerSystem.entries.items.len;
// try Logger.tryAddLog(@src(), .log, fmt, args);
// try std.testing.expectEqual(before, gLoggerSystem.entries.items.len);
// try std.testing.expectEqual(@as(usize, 1), try drain());
// const entry = gLoggerSystem.entries.items[before];
// try std.testing.expectEqual(Verbosity.log, entry.verbosity);
// var output: std.Io.Writer.Allocating = .init(std.testing.allocator);
// defer output.deinit();
// try entry.render(&gLoggerSystem, &output.writer, .{ .colormode = .none, .show_source = true });
// var expected: std.Io.Writer.Allocating = .init(std.testing.allocator);
// defer expected.deinit();
// const source = gLoggerSystem.logSites.items[entry.siteId].source;
// try expected.writer.writeAll("[normal ] [log ] ");
// try expected.writer.print(fmt, args);
// try expected.writer.print(" [{s}:{d}]\n", .{ source.file, source.line });
// try std.testing.expectEqualStrings(expected.written(), output.written());
// }
// }.log;
// // Exercise static site reuse across independent system lifetimes.
// for (0..2) |_| {
// initialize(std.testing.io, std.testing.allocator, std.testing.allocator);
// defer deinit();
// Logger.setVerbosity(.warn);
// Logger.addLog(@src(), .log, "filtered", .{});
// try std.testing.expectEqual(@as(usize, 0), try drain());
// Logger.setVerbosity(.verbose);
// try emit("literal {{braces}}", .{});
// try emit("{1s:*>6} {0d} {1s}", .{ @as(i16, -7), "hello" });
// for (0..2) |_| try emit("{} {x:08} {X} {b} {o} {d:.2} {e} {x} {any}", .{
// 42,
// @as(u32, 255),
// @as(u8, 255),
// @as(u12, 7),
// @as(i7, -3),
// 1.25,
// @as(f64, -2.5),
// @as(f16, 1.5),
// Record{ .id = -2, .enabled = true, .position = .{ .x = 3.5, .label = "owned" } },
// });
// try emit("{} {any:>8}", .{ true, false });
// const bool_entry = gLoggerSystem.entries.items[gLoggerSystem.entries.items.len - 1];
// try std.testing.expectEqualSlices(u8, &.{ 1, 0 }, bool_entry.serialized_args);
// try std.testing.expectEqual(@as(usize, 4), gLoggerSystem.logSites.items.len);
// try std.testing.expectEqual(@as(usize, 1), gLoggerSystem.mem.loggers.items.len);
//
// for (0..LoggerSystem.options.queue_capacity - 1) |x| {
// Logger.addLog(@src(), .warn, "queued {x}", .{x});
// }
//
// Logger.addLog(@src(), .warn, "queued", .{});
// try std.testing.expectError(error.QueueFull, Logger.tryAddLog(@src(), .warn, "full", .{}));
// try std.testing.expectEqual(@as(u64, 1), droppedCount());
// flush();
// Logger.addLog(@src(), .warn, "cleanup {s}", .{"undrained payload"});
// close();
// try std.testing.expectError(error.Closed, Logger.tryAddLog(@src(), .warn, "closed", .{}));
// }
// }
//
// test "concurrent logging with bounded queue and simultaneous main thread drain" {
// const A = DeclareLogger("producer-A", .{});
// const B = DeclareLogger("producer-B", .{});
// const Worker = struct {
// fn run(id: u32, start: *std.Io.Event, stop: *std.atomic.Value(bool), done: *std.atomic.Value(u32), failed: *std.atomic.Value(bool)) void {
// defer _ = done.fetchAdd(1, .release);
// start.waitUncancelable(std.testing.io);
// for (0..256) |seq| {
// var text: [4]u8 = @splat(@intCast('a' + id));
// while (!stop.load(.acquire)) {
// const result = if (seq % 2 == 0)
// A.tryAddLog(@src(), .log, "A {d}:{d} {s}", .{ id, @as(u32, @intCast(seq)), text[0..] })
// else
// B.tryAddLog(@src(), .warn, "B {d}:{d} {s}", .{ id, @as(u32, @intCast(seq)), text[0..] });
// result catch |err| switch (err) {
// error.QueueFull => {
// std.Thread.yield() catch {};
// continue;
// },
// else => {
// failed.store(true, .release);
// return;
// },
// };
// break;
// }
// @memset(&text, 0xdd);
// if (stop.load(.acquire)) return;
// }
// }
// };
// gLoggerSystem.init(std.testing.io, std.testing.allocator, std.testing.allocator);
// defer deinit();
// var start: std.Io.Event = .unset;
// var stop: std.atomic.Value(bool) = .init(false);
// var done: std.atomic.Value(u32) = .init(0);
// var failed: std.atomic.Value(bool) = .init(false);
// var threads: [4]std.Thread = undefined;
// var spawned: usize = 0;
// defer {
// stop.store(true, .release);
// start.set(std.testing.io);
// for (threads[0..spawned]) |thread| thread.join();
// }
// for (&threads, 0..) |*thread, id| {
// thread.* = try std.Thread.spawn(.{}, Worker.run, .{ @as(u32, @intCast(id)), &start, &stop, &done, &failed });
// spawned += 1;
// }
// start.set(std.testing.io);
// while (done.load(.acquire) != threads.len) {
// _ = try drain();
// std.Thread.yield() catch {};
// }
// _ = try drain();
// try std.testing.expect(!failed.load(.acquire));
// try std.testing.expectEqual(@as(usize, 1024), gLoggerSystem.entries.items.len);
// try std.testing.expectEqual(@as(usize, 2), gLoggerSystem.logSites.items.len);
// try std.testing.expectEqual(@as(usize, 2), gLoggerSystem.mem.loggers.items.len);
// var next: [4]u32 = @splat(0);
// for (gLoggerSystem.entries.items) |entry| {
// var cursor: StructuredLog.Cursor = .{ .bytes = entry.serialized_args };
// const id: usize = @intCast(try cursor.integer(4));
// try std.testing.expect(id < next.len);
// const seq: u32 = @intCast(try cursor.integer(4));
// try std.testing.expectEqual(if (seq % 2 == 0) Verbosity.log else Verbosity.warn, entry.verbosity);
// try std.testing.expectEqual(next[id], seq);
// next[id] += 1;
// const text: [4]u8 = @splat(@intCast('a' + id));
// var output: std.Io.Writer.Allocating = .init(std.testing.allocator);
// defer output.deinit();
// try entry.render(&gLoggerSystem, &output.writer, .{ .colormode = .none, .show_source = true });
// var expected: std.Io.Writer.Allocating = .init(std.testing.allocator);
// defer expected.deinit();
// const source = gLoggerSystem.logSites.items[entry.siteId].source;
// const name = if (seq % 2 == 0) "producer-A" else "producer-B";
// try expected.writer.print("[{s:<8}] [{s:<7}] {s} {d}:{d} {s} [{s}:{d}]\n", .{ name[0..8], @tagName(entry.verbosity), if (seq % 2 == 0) "A" else "B", id, seq, text, source.file, source.line });
// try std.testing.expectEqualStrings(expected.written(), output.written());
// }
// for (next) |n| try std.testing.expectEqual(@as(u32, 256), n);
// }
test "testing" { test "testing" {
const xxd = @import("p2").xxd; const xxd = @import("p2").xxd;
@ -1205,7 +1065,7 @@ test "testing" {
ending, ending,
}; };
initialize(std.testing.io, std.testing.allocator, std.testing.allocator); initialize(std.testing.io, std.testing.allocator, std.testing.allocator, false);
defer deinit(); defer deinit();
const Logger = DeclareLogger("mylogger", .{ .verbosity = .verbose }); const Logger = DeclareLogger("mylogger", .{ .verbosity = .verbose });
Logger.addLog(@src(), .log, "{} {} who doesn't {} {s} 2 + 2 is {d}", .{ TestEnum.ending, TestEnum2.ending, true, "dragons", 4 }); Logger.addLog(@src(), .log, "{} {} who doesn't {} {s} 2 + 2 is {d}", .{ TestEnum.ending, TestEnum2.ending, true, "dragons", 4 });
@ -1267,3 +1127,5 @@ test "testing" {
pub const sluggerformat = @import("sluggerformat.zig"); pub const sluggerformat = @import("sluggerformat.zig");
const p2 = @import("p2"); const p2 = @import("p2");
const std = @import("std");
const builtin = @import("builtin");

View File

View File

@ -1,16 +1,74 @@
/// desc: publically exported C slice // note about naming schemes:
pub const RtSlice = extern struct { // - Capital for structs
// - camelCase for functions intended to be used by zig
// - snake_case for functions intended to be exported to the api
//
// a file like core.zig (this file) exists so we can generate a c api from it later.
/// desc: a thing representing a zig slice
pub const Slice = extern struct {
ptr: [*c]u8, ptr: [*c]u8,
len: usize, len: usize,
pub fn fromZ(s: []const u8) @This() { pub fn fromZ(s: []const u8) @This() {
return .{ .ptr = s.ptr, .len = s.len }; return .{ .ptr = s.ptr, .len = s.len };
} }
pub fn toSlice(self: @This()) []u8 {
var s: []u8 = undefined;
s.len = self.len;
s.ptr = @ptrCast(self.ptr);
return s;
}
}; };
/// desc: initializes the core module, /// desc: gets a pointer to the actual engine instance
pub export fn core_start() callconv(.c) void {} ///
/// this will be used by dynamically loaded modules discover and register functionality
pub export fn get_engine() callconv(.c) ?anyopaque {
return @ptrCast(engine.getEngine());
}
pub export fn core_log(string: [*c]u8) callconv(.c) void {} pub export fn get_tag_registry() callconv(.c) ?anyopaque {
return @ptrCast(engine.getTagRegistry());
}
pub export fn core_start() callconv(.c) void {
const eng = engine.get();
const io = eng.io;
const allocator = eng.systemAllocator;
_ = io;
_ = allocator;
}
pub export fn core_declare_logging_category(name: [*c]u8, default_verbosity: Verbosity) void {
_ = name;
_ = default_verbosity;
}
pub const Verbosity = enum(c_int) {
verbose,
info,
warn,
err,
};
/// desc: pushes a string to the logging system
pub export fn core_log_puts(category: u32, verbosity: Verbosity, string: [*c]u8) callconv(.c) void {
_ = category;
_ = verbosity;
_ = string;
}
pub export fn core_shutdown() callconv(.c) void {} pub export fn core_shutdown() callconv(.c) void {}
// non exported functions below here, used by the zig runtime.
pub fn startEngine(io: std.Io, systemAllocator: std.mem.Allocator) void {
// create the engine registry
engine.initialize(io, systemAllocator);
}
const engine = @import("engine.zig");
const slugger = @import("slugger");
const std = @import("std");

View File

@ -0,0 +1,24 @@
// engine is the core registry for our hot
// reloading
//
// unlike old ribtech the engine does not bring a runtime.
// you as the user of the engine bring your own,
//
// I can provide a standard interface for accessing and
// creating threadpools and memory,
//
// but the program, how it schedules, the loop of the frame itself
//
// that is up to you.
//
// The engine is just a place where you can publish,
// modify and tear down systems for modification
pub const Engine = struct {
io: std.Io,
// engineObjects: std.ArrayList(EngineObjectRef),
};
const EngineObjectRef = struct {};
const std = @import("std");

View File

@ -0,0 +1,5 @@
ptr: *anyopaque,
name: TagPool.Tag,
const TagPool = core.DeclareTagPool("EngineObject");
const core = @import("../core.zig");

View File

@ -4,6 +4,8 @@ pub fn main(init: std.process.Init) !void {
const args = init.minimal.args; const args = init.minimal.args;
const argsSlice = try args.toSlice(init.arena.allocator()); const argsSlice = try args.toSlice(init.arena.allocator());
const io = init.io; const io = init.io;
_ = io;
_ = argsSlice;
} }
const std = @import("std"); const std = @import("std");

View File

@ -1,26 +0,0 @@
---
name: zig
description: Work on Zig 0.17 code and build files using the documentation and standard-library source shipped with the active compiler. Use for writing, reviewing, debugging, or migrating Zig in this repository.
---
# Zig 0.17
Use the installed Zig toolchain as the source of truth. Do not rely on remembered
APIs or hand-maintained summaries when the compiler distribution can answer the
question directly.
- Run `zig env` to locate `zig_exe`, `lib_dir`, and `std_dir`; do not assume a
particular installation path.
- Consult `<directory containing zig_exe>/doc/langref.html` for language syntax,
semantics, and builtins.
- Search `std_dir` for exact APIs, implementations, and tests. Use them as
examples of both correct usage and Zig coding style; follow standard-library
- conventions.
- Use compiler and test failures to verify any inferred API usage.
for `if` conditions, put continuation `and`/`or` operators at the start of
the next line. Run `zig fmt` on changed Zig files.
If the installed documentation is unavailable, use the versioned official
reference at <https://ziglang.org/documentation/0.17.0/> download a copy once and
avoid unessecary traffic.