✓
Passing This code compiles and runs correctly.
Code
// THE ARENA, RUNG 4 — a live SUM(hp) aggregate maintained by the store's
// full lifecycle contract, all three faces of Ruling 5 on one plural store:
// `inserted { hp }` — births ADD to the pool
// `updated { old, new }` — damage flows its DELTA into the pool
// `removed { hp }` — deaths remove the corpse's REMAINING hp
// The pool therefore equals the sum over live rows at every settled point —
// including the overkill case: a foe driven to -8 subtracts past zero at
// damage time, and its removal adds the overshoot back. No reconciliation
// pass, no scan: the aggregate rides the write paths ("everything reactive
// compiles down into these same interceptor branches").
//
// Contract-before-subscription: each damage write settles the pool (and
// prints it, via the board's own reactive rule) BEFORE the arena's guarded
// death-announcement rule observes the new hp.
import std/io
import std/store
std/store:new(board) { alive: 0[i64], kills: 0[i64], pool: 0[i64] }
std/store:new(arena, capacity: 64) { hp: i64, kind: i64 }
! inserted { hp } |> std/store:stored { board.alive: board.alive + 1 } |> std/store:stored { board.pool: board.pool + hp }
! removed { hp } |> std/store:stored { board.alive: board.alive - 1 } |> std/store:stored { board.kills: board.kills + 1 } |> std/store:stored { board.pool: board.pool - hp }
! updated { old, new } |> std/store:stored { board.pool: board.pool + new - old }
std/store(board)
! alive a |> std/io:print.ln("board: {{ a:d }} alive")
! kills k |> std/io:print.ln("board: {{ k:d }} killed")
! pool p |> std/io:print.ln("board: hp pool {{ p:d }}")
std/store(arena)
! hp h when h <= 0 |> std/io:print.ln("a foe reels ({{ h:d }} hp)")
std/store:insert(arena) { hp: 30, kind: 1 }
| row _ |> _
| full |> _
std/store:insert(arena) { hp: 12, kind: 1 }
| row _ |> _
| full |> _
std/store:insert(arena) { hp: 40, kind: 2 }
| row _ |> _
| full |> _
std/store:rule(arena)
! row e when e.kind == 1 |> std/store:stored { e.hp: e.hp - 20 }
std/store:rule(arena)
! row e when e.hp <= 0 |> std/store:take(arena[e])
| item i |> std/io:print.ln("culled a foe at {{ i.hp:d }} hp")
Actual
board: 1 alive
board: hp pool 30
board: 2 alive
board: hp pool 42
board: 3 alive
board: hp pool 82
board: hp pool 62
board: hp pool 42
a foe reels (-8 hp)
board: 2 alive
board: 1 killed
board: hp pool 50
culled a foe at -8 hp
Expected output
✓ Zig✓ C#board: 1 alive
board: hp pool 30
board: 2 alive
board: hp pool 42
board: 3 alive
board: hp pool 82
board: hp pool 62
board: hp pool 42
a foe reels (-8 hp)
board: 2 alive
board: 1 killed
board: hp pool 50
culled a foe at -8 hp
Emitted Zig source
// Access compiler flags via the per-user compiler_env module
const CompilerEnv = @import("compiler_env").CompilerEnv;
pub const panic = if (@import("builtin").mode == .Debug)
@import("std").debug.FullPanic(@import("std").debug.defaultPanic)
else
@import("std").debug.simple_panic;
const __koru_bare = struct {
extern fn posix_memalign(memptr: *?*anyopaque, alignment: usize, size: usize) c_int;
extern fn free(ptr: ?*anyopaque) void;
fn bareAlloc(_: *anyopaque, len: usize, alignment: @import("std").mem.Alignment, _: usize) ?[*]u8 {
var p: ?*anyopaque = null;
const a = @max(alignment.toByteUnits(), @sizeOf(usize));
if (posix_memalign(&p, a, len) != 0) return null;
return @ptrCast(p);
}
fn bareResize(_: *anyopaque, _: []u8, _: @import("std").mem.Alignment, _: usize, _: usize) bool { return false; }
fn bareRemap(_: *anyopaque, _: []u8, _: @import("std").mem.Alignment, _: usize, _: usize) ?[*]u8 { return null; }
fn bareFree(_: *anyopaque, memory: []u8, _: @import("std").mem.Alignment, _: usize) void { free(@ptrCast(memory.ptr)); }
const vtable = @import("std").mem.Allocator.VTable{ .alloc = bareAlloc, .resize = bareResize, .remap = bareRemap, .free = bareFree };
const allocator = @import("std").mem.Allocator{ .ptr = undefined, .vtable = &vtable };
};
const __koru_backing = if (@import("builtin").link_libc) @import("std").heap.c_allocator else if (@import("builtin").os.tag == .freestanding) __koru_bare.allocator else @import("std").heap.page_allocator;
var __koru_leak_count: @import("std").atomic.Value(usize) = .init(0);
fn __koru_alloc(ctx: *anyopaque, len: usize, alignment: @import("std").mem.Alignment, ret_addr: usize) ?[*]u8 {
_ = ctx;
const r = __koru_backing.rawAlloc(len, alignment, ret_addr);
if (comptime @import("builtin").mode == .Debug) {
if (r != null) _ = __koru_leak_count.fetchAdd(1, .monotonic);
}
return r;
}
fn __koru_resize(ctx: *anyopaque, memory: []u8, alignment: @import("std").mem.Alignment, new_len: usize, ret_addr: usize) bool {
_ = ctx;
return __koru_backing.rawResize(memory, alignment, new_len, ret_addr);
}
fn __koru_remap(ctx: *anyopaque, memory: []u8, alignment: @import("std").mem.Alignment, new_len: usize, ret_addr: usize) ?[*]u8 {
_ = ctx;
return __koru_backing.rawRemap(memory, alignment, new_len, ret_addr);
}
fn __koru_free(ctx: *anyopaque, memory: []u8, alignment: @import("std").mem.Alignment, ret_addr: usize) void {
_ = ctx;
__koru_backing.rawFree(memory, alignment, ret_addr);
if (comptime @import("builtin").mode == .Debug) {
_ = __koru_leak_count.fetchSub(1, .monotonic);
}
}
const __koru_vtable = @import("std").mem.Allocator.VTable{ .alloc = __koru_alloc, .resize = __koru_resize, .remap = __koru_remap, .free = __koru_free };
pub fn koru_allocator() @import("std").mem.Allocator {
return .{ .ptr = undefined, .vtable = &__koru_vtable };
}
pub inline fn __koru_intcast(comptime T: type, x: anytype) T {
if (comptime (@import("builtin").mode == .Debug or @import("builtin").mode == .ReleaseSafe))
return @as(T, @intCast(x));
const dst = @typeInfo(T);
const src = @typeInfo(@TypeOf(x));
if (comptime (dst == .int and src == .int and dst.int.bits == src.int.bits and dst.int.signedness != src.int.signedness))
return @as(T, @bitCast(x));
return @as(T, @intCast(x));
}
pub fn koru_leak_check() void {
if (comptime @import("builtin").mode != .Debug) return;
if (__koru_leak_count.load(.acquire) == 0) return;
if (comptime @import("builtin").target.os.tag == .freestanding) {
if (comptime @import("builtin").cpu.arch == .wasm32 or @import("builtin").cpu.arch == .wasm64) {
@panic("KORU LEAK CHECK FAILED: the produced program leaked");
} else {
const __klc = struct { extern var stdout: ?*anyopaque; extern fn fputs(__s: [*:0]const u8, __st: ?*anyopaque) c_int; };
var __lb: [128]u8 = undefined;
const __lm = "KORU LEAK CHECK FAILED: allocations still outstanding at end of run: ";
@memcpy(__lb[0..__lm.len], __lm);
var __ln: usize = __lm.len;
var __lv = __koru_leak_count.load(.acquire);
var __ld: [20]u8 = undefined;
var __lk: usize = 0;
while (__lv > 0) : (__lk += 1) { __ld[__lk] = @intCast('0' + __lv % 10); __lv /= 10; }
for (0..__lk) |__li| { __lb[__ln] = __ld[__lk - 1 - __li]; __ln += 1; }
__lb[__ln] = '\n'; __ln += 1; __lb[__ln] = 0;
_ = __klc.fputs(@as([*:0]const u8, @ptrCast(&__lb)), __klc.stdout);
@trap();
}
} else {
@import("std").debug.print("KORU LEAK CHECK FAILED: the produced program leaked (trace above)\n", .{});
@import("std").process.exit(1);
}
}
pub const main_module = struct {
// std/store: 'board' created (cell + write-subflow at module scope); fields alive: i64, kills: i64, pool: i64
// std/store: plural store 'arena' created (SoA cell + insert/query/write/take/stripe units); fields hp: i64, kind: i64
// >>> FLOW: tests/regression/600_STDLIB/690_STORE/690_041_store_arena_live_hp_aggregate/input.k:35 ~input:__store_insertf_arena()
pub fn flow0() void {
const result_0 = main_module.__store_insertf_arena_event.handler(.{ .hp = 30, .kind = 1, .__site_line = 35 });
switch (result_0) {
// >>> BRANCH: tests/regression/600_STDLIB/690_STORE/690_041_store_arena_live_hp_aggregate/input.k:36 | row _auto_6 |>
.row => |_| {
},
// >>> BRANCH: tests/regression/600_STDLIB/690_STORE/690_041_store_arena_live_hp_aggregate/input.k:37 | full |>
.full => {
},
}
}
// >>> FLOW: tests/regression/600_STDLIB/690_STORE/690_041_store_arena_live_hp_aggregate/input.k:38 ~input:__store_insertf_arena()
pub fn flow1() void {
const result_0 = main_module.__store_insertf_arena_event.handler(.{ .hp = 12, .kind = 1, .__site_line = 38 });
switch (result_0) {
// >>> BRANCH: tests/regression/600_STDLIB/690_STORE/690_041_store_arena_live_hp_aggregate/input.k:39 | row _auto_7 |>
.row => |_| {
},
// >>> BRANCH: tests/regression/600_STDLIB/690_STORE/690_041_store_arena_live_hp_aggregate/input.k:40 | full |>
.full => {
},
}
}
// >>> FLOW: tests/regression/600_STDLIB/690_STORE/690_041_store_arena_live_hp_aggregate/input.k:41 ~input:__store_insertf_arena()
pub fn flow2() void {
const result_0 = main_module.__store_insertf_arena_event.handler(.{ .hp = 40, .kind = 2, .__site_line = 41 });
switch (result_0) {
// >>> BRANCH: tests/regression/600_STDLIB/690_STORE/690_041_store_arena_live_hp_aggregate/input.k:42 | row _auto_8 |>
.row => |_| {
},
// >>> BRANCH: tests/regression/600_STDLIB/690_STORE/690_041_store_arena_live_hp_aggregate/input.k:43 | full |>
.full => {
},
}
}
// >>> FLOW: tests/regression/600_STDLIB/690_STORE/690_041_store_arena_live_hp_aggregate/input.k:45 ~input:__store_qsweep_arena_L45_690_041_store_arena_live_hp_aggregate_input_a229be()
pub fn flow3() void {
_ = main_module.__store_qsweep_arena_L45_690_041_store_arena_live_hp_aggregate_input_a229be_event.handler(.{ });
}
// >>> FLOW: tests/regression/600_STDLIB/690_STORE/690_041_store_arena_live_hp_aggregate/input.k:48 ~input:__store_qsweep_arena_L48_690_041_store_arena_live_hp_aggregate_input_a229be()
pub fn flow4() void {
_ = main_module.__store_qsweep_arena_L48_690_041_store_arena_live_hp_aggregate_input_a229be_event.handler(.{ });
}
pub fn koru_start_flow() void {
const result_0 = koru_koru.start_event.handler(.{ });
const result_0_done = result_0.done;
_ = &result_0_done;
}
pub fn koru_end_flow() void {
const result_0 = koru_koru.end_event.handler(.{ });
const result_0_done = result_0.done;
_ = &result_0_done;
}
const __KoruStoreT_board = blk: {
const __info = @typeInfo(@TypeOf(.{ .alive = @as(i64, 0), .kills = @as(i64, 0), .pool = @as(i64, 0) }));
var __fields: [__info.@"struct".fields.len]@import("std").builtin.Type.StructField = undefined;
for (__info.@"struct".fields, 0..) |__f, __i| {
__fields[__i] = .{ .name = __f.name, .type = __f.type, .default_value_ptr = null, .is_comptime = false, .alignment = __f.alignment };
}
break :blk @Type(.{ .@"struct" = .{ .layout = .auto, .fields = &__fields, .decls = &.{}, .is_tuple = false } });
};
var __koru_store_board: __KoruStoreT_board = .{ .alive = @as(i64, 0), .kills = @as(i64, 0), .pool = @as(i64, 0) };
pub const __store_apply_board_event = struct {
pub const Input = struct {
field: i64,
value: i64,
};
pub const Output = union(enum(u8)) {
alive: i64,
kills: i64,
pool: i64,
};
pub fn handler(__koru_event_input: @This().Input) @This().Output {
// >>> PROC: __store_apply_board [tests/regression/600_STDLIB/690_STORE/690_041_store_arena_live_hp_aggregate/input.k:20]
const field = __koru_event_input.field;
const value = __koru_event_input.value;
_ = &field;
_ = &value;
_ = &__koru_event_input;
return switch (field) {
0 => blk: { __koru_store_board.alive = value; break :blk .{ .alive = value }; },
1 => blk: { __koru_store_board.kills = value; break :blk .{ .kills = value }; },
2 => blk: { __koru_store_board.pool = value; break :blk .{ .pool = value }; },
else => unreachable,
};
}
};
pub const __store_write_board_event = struct {
pub const Input = struct {
field: i64,
value: i64,
};
pub const Output = void;
pub fn handler(__koru_event_input: @This().Input) @This().Output {
// >>> SUBFLOW: tests/regression/600_STDLIB/690_STORE/690_041_store_arena_live_hp_aggregate/input.k:20
const field = __koru_event_input.field;
const value = __koru_event_input.value;
_ = &field;
_ = &value;
_ = &__koru_event_input;
const result = main_module.__store_apply_board_event.handler(.{ .field = field, .value = value });
switch (result) {
// >>> BRANCH: tests/regression/600_STDLIB/690_STORE/690_041_store_arena_live_hp_aggregate/input.k:29 | kills k |>
.kills => |k| {
_ = &k;
(struct { fn __kout(__fd: i32, __b: []const u8) void { if (@import("builtin").os.tag == .freestanding) { const __kc = struct { extern var stdout: ?*anyopaque; extern var stderr: ?*anyopaque; extern fn fputs(__s: [*:0]const u8, __st: ?*anyopaque) c_int; }; var __kt: [4096]u8 = undefined; for (0..(__b.len + __kt.len - 2) / (__kt.len - 1)) |__ki| { const __kn = @min(__kt.len - 1, __b.len - __ki * (__kt.len - 1)); @memcpy(__kt[0..__kn], __b[__ki * (__kt.len - 1)..][0..__kn]); __kt[__kn] = 0; @import("std").mem.doNotOptimizeAway(__kc.fputs(@as([*:0]const u8, @ptrCast(&__kt)), if (__fd == 2) __kc.stderr else __kc.stdout)); } } else { @import("std").mem.doNotOptimizeAway(@import("std").posix.write(__fd, __b) catch @as(usize, 0)); } } fn __kw(comptime __f: []const u8, __a: anytype) void { var __kb: [65536]u8 = undefined; const __ks = @import("std").fmt.bufPrint(&__kb, __f, __a) catch __kb[0..0]; __kout(1, __ks); } }).__kw("board: {d} killed\n", .{k});
},
// >>> BRANCH: tests/regression/600_STDLIB/690_STORE/690_041_store_arena_live_hp_aggregate/input.k:28 | alive a |>
.alive => |a| {
_ = &a;
(struct { fn __kout(__fd: i32, __b: []const u8) void { if (@import("builtin").os.tag == .freestanding) { const __kc = struct { extern var stdout: ?*anyopaque; extern var stderr: ?*anyopaque; extern fn fputs(__s: [*:0]const u8, __st: ?*anyopaque) c_int; }; var __kt: [4096]u8 = undefined; for (0..(__b.len + __kt.len - 2) / (__kt.len - 1)) |__ki| { const __kn = @min(__kt.len - 1, __b.len - __ki * (__kt.len - 1)); @memcpy(__kt[0..__kn], __b[__ki * (__kt.len - 1)..][0..__kn]); __kt[__kn] = 0; @import("std").mem.doNotOptimizeAway(__kc.fputs(@as([*:0]const u8, @ptrCast(&__kt)), if (__fd == 2) __kc.stderr else __kc.stdout)); } } else { @import("std").mem.doNotOptimizeAway(@import("std").posix.write(__fd, __b) catch @as(usize, 0)); } } fn __kw(comptime __f: []const u8, __a: anytype) void { var __kb: [65536]u8 = undefined; const __ks = @import("std").fmt.bufPrint(&__kb, __f, __a) catch __kb[0..0]; __kout(1, __ks); } }).__kw("board: {d} alive\n", .{a});
},
// >>> BRANCH: tests/regression/600_STDLIB/690_STORE/690_041_store_arena_live_hp_aggregate/input.k:30 | pool p |>
.pool => |p| {
_ = &p;
(struct { fn __kout(__fd: i32, __b: []const u8) void { if (@import("builtin").os.tag == .freestanding) { const __kc = struct { extern var stdout: ?*anyopaque; extern var stderr: ?*anyopaque; extern fn fputs(__s: [*:0]const u8, __st: ?*anyopaque) c_int; }; var __kt: [4096]u8 = undefined; for (0..(__b.len + __kt.len - 2) / (__kt.len - 1)) |__ki| { const __kn = @min(__kt.len - 1, __b.len - __ki * (__kt.len - 1)); @memcpy(__kt[0..__kn], __b[__ki * (__kt.len - 1)..][0..__kn]); __kt[__kn] = 0; @import("std").mem.doNotOptimizeAway(__kc.fputs(@as([*:0]const u8, @ptrCast(&__kt)), if (__fd == 2) __kc.stderr else __kc.stdout)); } } else { @import("std").mem.doNotOptimizeAway(@import("std").posix.write(__fd, __b) catch @as(usize, 0)); } } fn __kw(comptime __f: []const u8, __a: anytype) void { var __kb: [65536]u8 = undefined; const __ks = @import("std").fmt.bufPrint(&__kb, __f, __a) catch __kb[0..0]; __kout(1, __ks); } }).__kw("board: hp pool {d}\n", .{p});
},
}
}
};
pub const __store_peek_board_event = struct {
pub const Input = struct {
field: i64,
};
pub const Output = union(enum(u8)) {
alive: i64,
kills: i64,
pool: i64,
};
pub inline fn handler(__koru_event_input: @This().Input) @This().Output {
return __koru_handler_impl(__koru_event_input.field);
}
fn __koru_handler_impl(__koru_p_0: i64) @This().Output {
const __koru_event_input: @This().Input = .{ .field = __koru_p_0 };
// >>> PROC: __store_peek_board [tests/regression/600_STDLIB/690_STORE/690_041_store_arena_live_hp_aggregate/input.k:20]
const field = __koru_event_input.field;
_ = &field;
_ = &__koru_event_input;
return switch (field) {
0 => .{ .alive = __koru_store_board.alive },
1 => .{ .kills = __koru_store_board.kills },
2 => .{ .pool = __koru_store_board.pool },
else => unreachable,
};
}
};
pub const __store_announce_board_event = struct {
pub const Input = struct {
field: i64,
};
pub const Output = void;
pub inline fn handler(__koru_event_input: @This().Input) @This().Output {
return __koru_handler_impl(__koru_event_input.field);
}
fn __koru_handler_impl(__koru_p_0: i64) @This().Output {
const __koru_event_input: @This().Input = .{ .field = __koru_p_0 };
// >>> SUBFLOW: tests/regression/600_STDLIB/690_STORE/690_041_store_arena_live_hp_aggregate/input.k:20
const field = __koru_event_input.field;
_ = &field;
_ = &__koru_event_input;
const result = main_module.__store_peek_board_event.handler(.{ .field = field });
switch (result) {
// >>> BRANCH: tests/regression/600_STDLIB/690_STORE/690_041_store_arena_live_hp_aggregate/input.k:29 | kills k |>
.kills => |k| {
_ = &k;
(struct { fn __kout(__fd: i32, __b: []const u8) void { if (@import("builtin").os.tag == .freestanding) { const __kc = struct { extern var stdout: ?*anyopaque; extern var stderr: ?*anyopaque; extern fn fputs(__s: [*:0]const u8, __st: ?*anyopaque) c_int; }; var __kt: [4096]u8 = undefined; for (0..(__b.len + __kt.len - 2) / (__kt.len - 1)) |__ki| { const __kn = @min(__kt.len - 1, __b.len - __ki * (__kt.len - 1)); @memcpy(__kt[0..__kn], __b[__ki * (__kt.len - 1)..][0..__kn]); __kt[__kn] = 0; @import("std").mem.doNotOptimizeAway(__kc.fputs(@as([*:0]const u8, @ptrCast(&__kt)), if (__fd == 2) __kc.stderr else __kc.stdout)); } } else { @import("std").mem.doNotOptimizeAway(@import("std").posix.write(__fd, __b) catch @as(usize, 0)); } } fn __kw(comptime __f: []const u8, __a: anytype) void { var __kb: [65536]u8 = undefined; const __ks = @import("std").fmt.bufPrint(&__kb, __f, __a) catch __kb[0..0]; __kout(1, __ks); } }).__kw("board: {d} killed\n", .{k});
},
// >>> BRANCH: tests/regression/600_STDLIB/690_STORE/690_041_store_arena_live_hp_aggregate/input.k:28 | alive a |>
.alive => |a| {
_ = &a;
(struct { fn __kout(__fd: i32, __b: []const u8) void { if (@import("builtin").os.tag == .freestanding) { const __kc = struct { extern var stdout: ?*anyopaque; extern var stderr: ?*anyopaque; extern fn fputs(__s: [*:0]const u8, __st: ?*anyopaque) c_int; }; var __kt: [4096]u8 = undefined; for (0..(__b.len + __kt.len - 2) / (__kt.len - 1)) |__ki| { const __kn = @min(__kt.len - 1, __b.len - __ki * (__kt.len - 1)); @memcpy(__kt[0..__kn], __b[__ki * (__kt.len - 1)..][0..__kn]); __kt[__kn] = 0; @import("std").mem.doNotOptimizeAway(__kc.fputs(@as([*:0]const u8, @ptrCast(&__kt)), if (__fd == 2) __kc.stderr else __kc.stdout)); } } else { @import("std").mem.doNotOptimizeAway(@import("std").posix.write(__fd, __b) catch @as(usize, 0)); } } fn __kw(comptime __f: []const u8, __a: anytype) void { var __kb: [65536]u8 = undefined; const __ks = @import("std").fmt.bufPrint(&__kb, __f, __a) catch __kb[0..0]; __kout(1, __ks); } }).__kw("board: {d} alive\n", .{a});
},
// >>> BRANCH: tests/regression/600_STDLIB/690_STORE/690_041_store_arena_live_hp_aggregate/input.k:30 | pool p |>
.pool => |p| {
_ = &p;
(struct { fn __kout(__fd: i32, __b: []const u8) void { if (@import("builtin").os.tag == .freestanding) { const __kc = struct { extern var stdout: ?*anyopaque; extern var stderr: ?*anyopaque; extern fn fputs(__s: [*:0]const u8, __st: ?*anyopaque) c_int; }; var __kt: [4096]u8 = undefined; for (0..(__b.len + __kt.len - 2) / (__kt.len - 1)) |__ki| { const __kn = @min(__kt.len - 1, __b.len - __ki * (__kt.len - 1)); @memcpy(__kt[0..__kn], __b[__ki * (__kt.len - 1)..][0..__kn]); __kt[__kn] = 0; @import("std").mem.doNotOptimizeAway(__kc.fputs(@as([*:0]const u8, @ptrCast(&__kt)), if (__fd == 2) __kc.stderr else __kc.stdout)); } } else { @import("std").mem.doNotOptimizeAway(@import("std").posix.write(__fd, __b) catch @as(usize, 0)); } } fn __kw(comptime __f: []const u8, __a: anytype) void { var __kb: [65536]u8 = undefined; const __ks = @import("std").fmt.bufPrint(&__kb, __f, __a) catch __kb[0..0]; __kout(1, __ks); } }).__kw("board: hp pool {d}\n", .{p});
},
}
}
};
const __KoruStoreT_arena = struct {
hp: [64]i64 = undefined,
kind: [64]i64 = undefined,
len: usize = 0,
__koru_hslot_row: [64]usize = undefined,
__koru_hslot_gen: [64]u32 = [_]u32{0} ** 64,
__koru_row_hslot: [64]usize = undefined,
__koru_hslot_free: [64]usize = undefined,
__koru_hslot_free_len: usize = 0,
__koru_hslot_next: usize = 0,
// `__koru_ident` — no removal has run, so slot == dense row
// for every l
... [truncated - 45KB total]Emitted C# source
static class main_module {
public static void __koru_stdout_write(dynamic s) => global::System.Console.Out.Write(s);
public static void __koru_stderr_write(dynamic s) => global::System.Console.Error.Write(s);
// The mutable handle carrier — `*String`-style resources are
// `new __KoruBox { data = … }` because C# anonymous types are
// read-only: `s.data = …` (std/string append/clear, handle
// mutation generally) needs a settable member.
public class __KoruBox { public dynamic data; }
// Textification for `{{ … }}` operands: C# bool ToStrings as
// `True` where Koru prints `true`, and the operand's static type
// is unknown at this boundary — a `(x) is bool` inline test would
// be a compile error on statically-typed operands instead. Generic
// on purpose: `dynamic` boxed every value-type operand — measured
// ~1s/10M elements on 012_threat_scanner — while T specializes to
// the operand's own ToString() with no box.
public static string __koru_str<T>(T v) => v is bool b ? (b ? "true" : "false") : v?.ToString();
// std/store: 'board' created (cell + write-subflow at module scope); fields alive: i64, kills: i64, pool: i64
// std/store: plural store 'arena' created (SoA cell + insert/query/write/take/stripe units); fields hp: i64, kind: i64
static class __koru_store_board {
public static long alive = 0;
public static long kills = 0;
public static long pool = 0;
public static long __koru_brand = -1;
}
static class __koru_store_arena {
public static long[] hp = new long[64];
public static dynamic __koru_read_hp(long __h) { long __r = __koru_resolve(__h); return hp[(int)__r]; }
public static long[] kind = new long[64];
public static dynamic __koru_read_kind(long __h) { long __r = __koru_resolve(__h); return kind[(int)__r]; }
public static long len = 0;
public static long[] __koru_hslot_row = new long[64];
public static long[] __koru_hslot_gen = new long[64];
public static long[] __koru_row_hslot = new long[64];
public static long[] __koru_hslot_free = new long[64];
public static long __koru_hslot_free_len = 0;
public static long __koru_hslot_next = 0;
public static long __koru_brand = 2;
public static bool __koru_ident = true;
public static bool __koru_gen0 = true;
public static void __koru_materialize() {
if (!__koru_ident) return;
for (long __i = 0; __i < len; __i++) { __koru_hslot_row[__i] = __i; __koru_row_hslot[__i] = __i; }
__koru_ident = false;
}
public static long __koru_row_of(long h) {
if (h < 0) return -1;
ulong __u = (ulong)h;
long __slot32 = (long)(__u & 0xFFFFFFFFUL);
if ((__slot32 >> 24) != __koru_brand) return -1;
long __slot = __slot32 & 0xFFFFFF;
if (__slot >= __koru_hslot_next) return -1;
if (__koru_gen0) { if ((__u >> 32) != 0) return -1; return __slot; }
if ((long)(__u >> 32) != __koru_hslot_gen[__slot]) return -1;
if (__koru_ident) return __slot;
long __r = __koru_hslot_row[__slot];
if (__r >= len) return -1;
return __r;
}
public static long __koru_resolve(long h) {
if (h >= 0) {
ulong __u = (ulong)h;
long __slot32 = (long)(__u & 0xFFFFFFFFUL);
if ((__slot32 >> 24) != __koru_brand) throw new global::System.Exception("std/store: 'arena[...]' does not address a row - the value is not a handle this store issued (handles come from `| row` and row cursors)");
long __slot = __slot32 & 0xFFFFFF;
if (__koru_gen0) {
if ((__u >> 32) != 0 && __slot < __koru_hslot_next) throw new global::System.Exception("std/store: stale row handle into store 'arena' - the row it addressed was removed (stale-handle trap pinned at 690_115)");
} else if (__slot < __koru_hslot_next && (long)(__u >> 32) != __koru_hslot_gen[__slot]) throw new global::System.Exception("std/store: stale row handle into store 'arena' - the row it addressed was removed (stale-handle trap pinned at 690_115)");
}
long __r = __koru_row_of(h);
if (__r < 0) throw new global::System.Exception("std/store: 'arena[...]' does not address a row - the value is not a handle this store issued (handles come from `| row` and row cursors)");
return __r;
}
public static long __koru_handle_of(long dense) {
if (__koru_gen0) return dense | (__koru_brand << 24);
long __slot = dense;
if (!__koru_ident) __slot = __koru_row_hslot[dense];
return (__slot | (__koru_brand << 24)) | (__koru_hslot_gen[__slot] << 32);
}
}
public static class __store_apply_board_event {
public struct Input {
public long field;
public long value;
}
public struct Output {
public string tag;
public long alive;
public long kills;
public long pool;
}
public static Output handler(Input __koru_input) {
var field = __koru_input.field;
var value = __koru_input.value;
switch (field) {
case 0: { __koru_store_board.alive = value; return new Output { tag = "alive", alive = value }; }
case 1: { __koru_store_board.kills = value; return new Output { tag = "kills", kills = value }; }
case 2: { __koru_store_board.pool = value; return new Output { tag = "pool", pool = value }; }
}
throw new global::System.Exception("__store_apply_board: field index " + field + " is not a column of store 'board'");
return default;
}
}
public static class __store_write_board_event {
public struct Input {
public long field;
public long value;
}
public static dynamic handler(Input __koru_input) {
var field = __koru_input.field;
var value = __koru_input.value;
var result_0 = main_module.__store_apply_board_event.handler(new __store_apply_board_event.Input { field = (long)(field), value = (long)(value)});
if (result_0.tag == "alive") {
var a = result_0.alive;
__koru_stdout_write("board: " + __koru_str(a) + " alive" + "\n");
}
if (result_0.tag == "kills") {
var k = result_0.kills;
__koru_stdout_write("board: " + __koru_str(k) + " killed" + "\n");
}
if (result_0.tag == "pool") {
var p = result_0.pool;
__koru_stdout_write("board: hp pool " + __koru_str(p) + "\n");
}
return default;
}
}
public static class __store_peek_board_event {
public struct Input {
public long field;
}
public struct Output {
public string tag;
public long alive;
public long kills;
public long pool;
}
public static Output handler(Input __koru_input) {
var field = __koru_input.field;
switch (field) {
case 0: return new Output { tag = "alive", alive = __koru_store_board.alive };
case 1: return new Output { tag = "kills", kills = __koru_store_board.kills };
case 2: return new Output { tag = "pool", pool = __koru_store_board.pool };
}
throw new global::System.Exception("__store_peek_board: field index " + field + " is not a column of store 'board'");
return default;
}
}
public static class __store_announce_board_event {
public struct Input {
public long field;
}
public static dynamic handler(Input __koru_input) {
var field = __koru_input.field;
var result_1 = main_module.__store_peek_board_event.handler(new __store_peek_board_event.Input { field = (long)(field)});
if (result_1.tag == "alive") {
var a = result_1.alive;
__koru_stdout_write("board: " + __koru_str(a) + " alive" + "\n");
}
if (result_1.tag == "kills") {
var k = result_1.kills;
__koru_stdout_write("board: " + __koru_str(k) + " killed" + "\n");
}
if (result_1.tag == "pool") {
var p = result_1.pool;
__koru_stdout_write("board: hp pool " + __koru_str(p) + "\n");
}
return default;
}
}
public static class __store_insertf_arena_event {
public struct Input {
public long hp;
public long kind;
public long __site_line;
}
public struct Output {
public string tag;
public long row;
public dynamic full;
}
public static Output handler(Input __koru_input) {
var hp = __koru_input.hp;
var kind = __koru_input.kind;
var __site_line = __koru_input.__site_line;
if (__koru_store_arena.len >= 64) return new Output { tag = "full", full = new { } };
if (__koru_store_arena.len >= 64) throw new global::System.Exception("std/store: store 'arena' is full (capacity 64) - declared capacity and the `| full` branch are pinned at 690_011");
long __koru_new_row = __koru_store_arena.len;
long __koru_hslot;
if (__koru_store_arena.__koru_hslot_free_len > 0) {
__koru_store_arena.__koru_hslot_free_len -= 1;
__koru_hslot = __koru_store_arena.__koru_hslot_free[__koru_store_arena.__koru_hslot_free_len];
} else {
__koru_hslot = __koru_store_arena.__koru_hslot_next;
__koru_store_arena.__koru_hslot_next += 1;
}
if (!__koru_store_arena.__koru_ident) {
__koru_store_arena.__koru_hslot_row[__koru_hslot] = __koru_new_row;
__koru_store_arena.__koru_row_hslot[__koru_new_row] = __koru_hslot;
}
__koru_store_arena.hp[__koru_new_row] = hp;
__koru_store_arena.kind[__koru_new_row] = kind;
__koru_store_arena.len += 1;
main_module.__store_inserted_arena_0_event.handler(new main_module.__store_inserted_arena_0_event.Input { hp = hp });
if (__site_line > 45) {
main_module.__store_qrow_arena_L45_690_041_store_arena_live_hp_aggregate_input_a229be_event.handler(new main_module.__store_qrow_arena_L45_690_041_store_arena_live_hp_aggregate_input_a229be_event.Input { row = __koru_new_row });
}
if (__site_line > 48) {
main_module.__store_qrow_arena_L48_690_041_store_arena_live_hp_aggregate_input_a229be_event.handler(new main_module.__store_qrow_arena_L48_690_041_store_arena_live_hp_aggregate_input_a229be_event.Input { row = __koru_new_row });
}
return new Output { tag = "row", row = __koru_store_arena.__koru_handle_of(__koru_new_row) };
return default;
}
}
public static class __store_apply_arena_event {
public struct Input {
public long row;
public long field;
public long value_0;
public long value_1;
}
public struct Output {
public string tag;
public long hp;
public long kind;
}
public static Output handler(Input __koru_input) {
var row = __koru_input.row;
var field = __koru_input.field;
var value_0 = __koru_input.value_0;
var value_1 = __koru_input.value_1;
var __koru_r = row;
switch (field) {
case 0: { var __koru_old = __koru_store_arena.hp[__koru_r]; __koru_store_arena.hp[__koru_r] = value_0; main_module.__store_updated_arena_0_event.handler(new main_module.__store_updated_arena_0_event.Input { old = __koru_old, @new = value_0 }); return new Output { tag = "hp", hp = value_0 }; }
case 1: { var __koru_old = __koru_store_arena.kind[__koru_r]; __koru_store_arena.kind[__koru_r] = value_1; main_module.__store_updated_arena_0_event.handler(new main_module.__store_updated_arena_0_event.Input { old = __koru_old, @new = value_1 }); return new Output { tag = "kind", kind = value_1 }; }
}
throw new global::System.Exception("__store_apply_arena: field index " + field + " is not a column of store 'arena'");
return default;
}
}
public static class __store_write_arena_event {
public struct Input {
public long row;
public long field;
public long value_0;
public long value_1;
}
public static dynamic handler(Input __koru_input) {
var row = __koru_input.row;
var field = __koru_input.field;
var value_0 = __koru_input.value_0;
var value_1 = __koru_input.value_1;
var result_2 = main_module.__store_apply_arena_event.handler(new __store_apply_arena_event.Input { row = (long)(row), field = (long)(field), value_0 = (long)(value_0), value_1 = (long)(value_1)});
var __matched_3 = false;
if (!__matched_3 && result_2.tag == "hp") {
var h = result_2.hp;
if (h <= 0) {
__matched_3 = true;
__koru_stdout_write("a foe reels (" + __koru_str(h) + " hp)" + "\n");
}
}
if (!__matched_3 && result_2.tag == "hp") {
var _auto_9 = result_2.hp;
__matched_3 = true;
}
if (!__matched_3 && result_2.tag == "kind") {
var _auto_10 = result_2.kind;
__matched_3 = true;
}
return default;
}
}
public static class __store_peek_arena_event {
public struct Input {
public long row;
public long field;
}
public struct Output {
public string tag;
public long hp;
public long kind;
}
public static Output handler(Input __koru_input) {
var row = __koru_input.row;
var field = __koru_input.field;
var __koru_r = row;
switch (field) {
case 0: { return new Output { tag = "hp", hp = __koru_store_arena.hp[__koru_r] }; }
case 1: { return new Output { tag = "kind", kind = __koru_store_arena.kind[__koru_r] }; }
}
throw new global::System.Exception("__store_peek_arena: field index " + field + " is not a column of store 'arena'");
return default;
}
}
public static class __store_qrow_arena_L45_690_041_store_arena_live_hp_aggregate_input_a229be_event {
public struct Input {
public long row;
}
public static dynamic handler(Input __koru_input) {
var row = __koru_input.row;
var __koru_r = row;
var kind = __koru_store_arena.kind[__koru_r];
if (!(kind == 1)) return default;
main_module.__store_qbody_arena_L45_690_041_store_arena_live_hp_aggregate_input_a229be_event.handler(new main_module.__store_qbody_arena_L45_690_041_store_arena_live_hp_aggregate_input_a229be_event.Input { kind = kind, __koru_sdix_rule_L45 = __koru_r });
return default;
}
}
public static class __store_qbody_arena_L45_690_041_store_arena_live_hp_aggregate_input_a229be_event {
public struct Input {
public long kind;
public long __koru_sdix_rule_L45;
}
public static dynamic handler(Input __koru_input) {
var kind = __koru_input.kind;
var __koru_sdix_rule_L45 = __koru_input.__koru_sdix_rule_L45;
main_module.__store_write_arena_event.handler(new __store_write_arena_event.Input { row = (long)(__koru_sdix_rule_L45), field = (long)(0), value_0 = (long)(__koru_store_arena.hp[(__koru_sdix_rule_L45)] - 20), value_1 = (long)(0)});
return default;
}
}
public static class __store_qsweep_arena_L45_690_041_store_arena_live_hp_aggregate_input_a229be_event {
public struct Input {
}
public static dynamic handler(Input __koru_input) {
for (long __koru_i = 0; __koru_i < __koru_store_arena.len; __koru_i++) {
main_module.__store_qrow_arena_L45_690_041_store_arena_live_hp_aggregate_input_a229be_event.handler(new main_module.__store_qrow_arena_L45_690_041_store_arena_live_hp_aggregate_input_a229be_event.Input { row = __koru_i });
}
return default;
}
}
public static class __store_qrow_arena_L48_690_041_store_arena_live_hp_aggregate_input_a229be_event {
public struct Input {
public long row;
}
public static dynamic handler(Input __koru_input) {
var row = __koru_input.row;
var __koru_r = row;
var hp = __koru_store_arena.hp[__koru_r];
if (!(hp <= 0)) return default;
main_module.__store_qbody_arena_L48_690_041_store_arena_live_hp_aggregate_input_a229be_event.handler(new main_module.__store_qbody_arena_L48_690_041_store_arena_live_hp_aggregate_input_a229be_event.Input { hp = hp, __koru_qrow = __koru_store_arena.__koru_handle_of(__koru_r) });
return default;
}
}
public static class __store_qbody_arena_L48_690_041_store_arena_live_hp_aggregate_input_a229be_event {
public struct Input {
public long hp;
public long __koru_qrow;
}
public static dynamic handler(Input __koru_input) {
var hp = __koru_input.hp;
var __koru_qrow = __koru_input.__koru_qrow;
var result_4 = main_module.__store_take_arena_event.handler(new __store_take_arena_event.Input { row = (long)(__koru_qrow)});
if (result_4.tag == "item") {
var i = result_4.item;
__koru_stdout_write("culled a foe at " + __koru_str(i.hp) + " hp" + "\n");
}
if (result_4.tag == "empty") {
var _auto_13 = result_4.empty;
throw new global::System.Exception("__store_take_arena: unhandled panic branch 'empty' fired at runtime");
}
return default;
}
}
public static class __store_qsweep_arena_L48_690_041_store_arena_live_hp_aggregate_input_a229be_event {
public struct Input {
}
public static dynamic handler(Input __koru_input) {
long __koru_i = 0;
while (__koru_i < __koru_store_arena.len) {
long __koru_len_before = __koru_store_arena.len;
main_module.__store_qrow_arena_L48_690_041_store_arena_live_hp_aggregate_input_a229be_event.handler(new main_module.__store_qrow_arena_L48_690_041_store_arena_live_hp_aggregate_input_a229be_event.Input { row = __koru_i });
if (__koru_store_arena.len >= __koru_len_before) __koru_i += 1;
}
return default;
}
}
public static class __store_take_arena_event {
public struct Input {
public long row;
}
public struct Output {
public string tag;
public dynamic item;
public dynamic empty;
}
public static Output handler(Input __koru_input) {
var row = __koru_input.row;
__koru_store_arena.__koru_materialize();
long __koru_r = __koru_store_arena.__koru_row_of(row);
if (__koru_r < 0) return new Output { tag = "empty", empty = new { } };
long __koru_gone_slot = __koru_store_arena.__koru_row_hslot[__koru_r];
var __koru_out_hp = __koru_store_arena.hp[__koru_r];
var __koru_out_kind = __koru_store_arena.kind[__koru_r];
main_module.__store_removed_arena_0_event.handler(new main_module.__store_removed_arena_0_event.Input { hp = __koru_out_hp });
var __koru_last = __koru_store_arena.len - 1;
if (__koru_r != __koru_last) {
__koru_store_arena.hp[__koru_r] = __koru_store_arena.hp[__koru_last];
__koru_store_arena.kind[__koru_r] = __koru_store_arena.kind[__koru_last];
var __koru_mv_slot = __koru_store_arena.__koru_row_hslot[__koru_last];
__koru_store_arena.__koru_hslot_row[__koru_mv_slot] = __koru_r;
__koru_store_arena.__koru_row_hslot[__koru_r] = __koru_mv_slot;
}
__koru_store_arena.__koru_hslot_row[__koru_gone_slot] = -1;
__koru_store_arena.len = __koru_last;
__koru_store_arena.__koru_hslot_gen[__koru_gone_slot] = ((__koru_store_arena.__koru_hslot_gen[__koru_gone_slot] + 1) & 4294967295L);
__koru_store_arena.__koru_hslot_free[__koru_store_arena.__koru_hslot_free_len] = __koru_gone_slot;
__koru_store_arena.__koru_hslot_free_len += 1;
__koru_store_arena.__koru_gen0 = false;
return new Output { tag = "item", item = new { hp = __koru_out_hp, kind = __koru_out_kind } };
return default;
}
}
public static class __store_inserted_arena_0_event {
public struct Input {
public long hp;
}
public static dynamic handler(Input __koru_input) {
var hp = __koru_input.hp;
main_module.__store_write_board_event.handler(new __store_write_board_event.Input { field = (long)(0), value = (long)(__koru_store_board.alive + 1)});
main_module.__store_write_board_event.handler(new __store_write_board_event.Input { field = (long)(2), value = (long)(__koru_store_board.pool + hp)});
return default;
}
}
public static class __store_removed_arena_0_event
... [truncated - 23KB total]Flows
flow ~new click a branch to expand · @labels scroll to their anchor
new (board, source: alive: 0[i64], kills: 0[i64], pool: 0[i64])
flow ~new click a branch to expand · @labels scroll to their anchor
new (arena, capacity: 64, source: hp: i64, kind: i64)
flow ~std/store click a branch to expand · @labels scroll to their anchor
std/store (board)
flow ~std/store click a branch to expand · @labels scroll to their anchor
std/store (arena)
flow ~insert click a branch to expand · @labels scroll to their anchor
insert (arena, source: hp: 30, kind: 1)
flow ~insert click a branch to expand · @labels scroll to their anchor
insert (arena, source: hp: 12, kind: 1)
flow ~insert click a branch to expand · @labels scroll to their anchor
insert (arena, source: hp: 40, kind: 2)
flow ~rule click a branch to expand · @labels scroll to their anchor
rule (arena)
flow ~rule click a branch to expand · @labels scroll to their anchor
rule (arena)
Test Configuration
MUST_RUN LANGUAGES: zig cs