✓
Passing This code compiles and runs correctly.
Code
// `__pump_<name>_retired_<i>` — the per-participant retirement unit a
// capture-aware participant emits — fires exactly once, on the first pass
// whose `live` answers 0, ahead of `| drained`. `a` burns out after two
// steps while `b` keeps the pump alive past the crossing: a refire per idle
// pass would print the line three times — the one-shot flag is the pin.
import std/io
import std/pump
import lib/flicker
lib/flicker:light(a: 2, b: 4)
std/pump:create(main)
| drained |> std/io:print.ln("all retired")
// Hand-declared here; a capture transform emits this pair itself — the unit
// name is the convention `run` enumerates.
tor __pump_main_retired_0 {}
__pump_main_retired_0() |> std/io:print.ln("a retired")
std/pump(main)
! step |> lib/flicker:a-step()
! live |> lib/flicker:a-live()
std/pump(main)
! step |> lib/flicker:b-step()
! live |> lib/flicker:b-live()
std/pump:run(main)
Supporting Files
using static KoruHost;
static class KoruHost {
public static long a_left = 0;
public static long b_left = 0;
}
~proc light|cs { a_left = a; b_left = b;
}
~proc a-step|cs { if (a_left > 0) { a_left -= 1; return 1; } return 0;
}
~proc a-live|cs { return a_left;
}
~proc b-step|cs { if (b_left > 0) { b_left -= 1; return 1; } return 0;
}
~proc b-live|cs { return b_left;
}// Two countdown participants — module-level burn counters behind the
// step/live surface. `a` burns out after `a` steps, `b` after `b` — enough to
// make one join cross to live() == 0 while the pump is still driven by the
// other.
const std = @import("std");
var a_left: i64 = 0;
var b_left: i64 = 0;
~pub tor light { a: i64, b: i64 }
~proc light|zig { a_left = a; b_left = b; }
~pub tor a-step {} -> i32
~proc a-step|zig { if (a_left > 0) { a_left -= 1; return 1; } return 0; }
~pub tor a-live {} -> i64
~proc a-live|zig { return a_left; }
~pub tor b-step {} -> i32
~proc b-step|zig { if (b_left > 0) { b_left -= 1; return 1; } return 0; }
~pub tor b-live {} -> i64
~proc b-live|zig { return b_left; }
Actual · Zig
✓ passa retired
all retired
Actual · C#
✗ cs-compileExpected output
✓ Zig✗ C#a retired
all retired
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 {
// >>> FLOW: tests/regression/600_STDLIB/690_STORE/690_351_pump_retired_unit_fires_once/input.k:11 ~lib.flicker:light()
pub fn flow0() void {
_ = koru_lib.koru_flicker.light_event.handler(.{ .a = 2, .b = 4 });
}
pub const __pump_main_retired_0_event = struct {
pub const Input = struct {
};
pub const Output = void;
pub fn handler(__koru_event_input: @This().Input) @This().Output {
_ = &__koru_event_input;
return undefined;
}
};
// >>> FLOW: tests/regression/600_STDLIB/690_STORE/690_351_pump_retired_unit_fires_once/input.k:19 ~input:__pump_main_retired_0()
pub fn flow1() void {
_ = main_module.__pump_main_retired_0_event.handler(.{ });
(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("a retired\n", .{});
}
// >>> FLOW: tests/regression/600_STDLIB/690_STORE/690_351_pump_retired_unit_fires_once/input.k:29 ~input:__pump_run_main()
pub fn flow2() void {
const __koru_eff_disc_0: main_module.__pump_run_main_event.Output = __koru_proc_0: {
var __koru_retired = [_]bool{false} ** 2;
while (true) {
var __koru_live: i64 = 0;
const __koru_l0: i64 = main_module.__pump_main_live_0_event.handler(.{});
__koru_live += __koru_l0;
if (__koru_l0 == 0 and !__koru_retired[0]) { __koru_retired[0] = true; main_module.__pump_main_retired_0_event.handler(.{}); }
__koru_live += main_module.__pump_main_live_1_event.handler(.{});
if (__koru_live == 0) break;
var __koru_worked: i64 = 0;
__koru_worked += main_module.__pump_main_step_0_event.handler(.{});
__koru_worked += main_module.__pump_main_step_1_event.handler(.{});
if (__koru_worked == 0) { if (false) { _ = {}; } else {
@import("std").Thread.sleep(1_000_000);
} }
}
main_module.__pump_drained_main_event.handler(.{});
break :__koru_proc_0;
};
_ = __koru_eff_disc_0;
}
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;
}
pub const __pump_drained_main_event = struct {
pub const Input = struct {
};
pub const Output = void;
pub fn handler(__koru_event_input: @This().Input) @This().Output {
// >>> SUBFLOW: tests/regression/600_STDLIB/690_STORE/690_351_pump_retired_unit_fires_once/input.k:13
_ = &__koru_event_input;
(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("all retired\n", .{});
}
};
pub const __pump_main_step_0_event = struct {
pub const Input = struct {
};
pub const Output = i32;
pub fn handler(__koru_event_input: @This().Input) @This().Output {
// >>> SUBFLOW: tests/regression/600_STDLIB/690_STORE/690_351_pump_retired_unit_fires_once/input.k:21
_ = &__koru_event_input;
const result = koru_lib.koru_flicker.a_step_event.handler(.{ });
const __koru_r = result;
_ = &result;
return __koru_r;
}
};
pub const __pump_main_live_0_event = struct {
pub const Input = struct {
};
pub const Output = i64;
pub fn handler(__koru_event_input: @This().Input) @This().Output {
// >>> SUBFLOW: tests/regression/600_STDLIB/690_STORE/690_351_pump_retired_unit_fires_once/input.k:21
_ = &__koru_event_input;
const result = koru_lib.koru_flicker.a_live_event.handler(.{ });
const __koru_r = result;
_ = &result;
return __koru_r;
}
};
pub const __pump_main_step_1_event = struct {
pub const Input = struct {
};
pub const Output = i32;
pub fn handler(__koru_event_input: @This().Input) @This().Output {
// >>> SUBFLOW: tests/regression/600_STDLIB/690_STORE/690_351_pump_retired_unit_fires_once/input.k:25
_ = &__koru_event_input;
const result = koru_lib.koru_flicker.b_step_event.handler(.{ });
const __koru_r = result;
_ = &result;
return __koru_r;
}
};
pub const __pump_main_live_1_event = struct {
pub const Input = struct {
};
pub const Output = i64;
pub fn handler(__koru_event_input: @This().Input) @This().Output {
// >>> SUBFLOW: tests/regression/600_STDLIB/690_STORE/690_351_pump_retired_unit_fires_once/input.k:25
_ = &__koru_event_input;
const result = koru_lib.koru_flicker.b_live_event.handler(.{ });
const __koru_r = result;
_ = &result;
return __koru_r;
}
};
pub const __pump_run_main_event = struct {
pub const Input = struct {
};
pub const Output = void;
pub fn handler(__koru_event_input: @This().Input, comptime __H: type) @This().Output {
const idle = if (@hasDecl(__H, "idle")) __H.idle else struct { fn __koru_noop() void {} }.__koru_noop;
_ = &idle;
// >>> PROC: __pump_run_main [tests/regression/600_STDLIB/690_STORE/690_351_pump_retired_unit_fires_once/input.k:29]
_ = &__koru_event_input;
var __koru_retired = [_]bool{false} ** 2;
while (true) {
var __koru_live: i64 = 0;
const __koru_l0: i64 = main_module.__pump_main_live_0_event.handler(.{});
__koru_live += __koru_l0;
if (__koru_l0 == 0 and !__koru_retired[0]) { __koru_retired[0] = true; main_module.__pump_main_retired_0_event.handler(.{}); }
__koru_live += main_module.__pump_main_live_1_event.handler(.{});
if (__koru_live == 0) break;
var __koru_worked: i64 = 0;
__koru_worked += main_module.__pump_main_step_0_event.handler(.{});
__koru_worked += main_module.__pump_main_step_1_event.handler(.{});
if (__koru_worked == 0) { if (@hasDecl(__H, "idle")) { idle(); } else {
@import("std").Thread.sleep(1_000_000);
} }
}
main_module.__pump_drained_main_event.handler(.{});
return;
}
};
};
pub const koru_lib = struct {
pub const koru_flicker = struct {
const std = @import("std");
var a_left: i64 = 0;
var b_left: i64 = 0;
pub const light_event = struct {
pub const Input = struct {
a: i64,
b: i64,
};
pub const Output = void;
pub inline fn handler(__koru_event_input: @This().Input) @This().Output {
return __koru_handler_impl(__koru_event_input.a, __koru_event_input.b);
}
fn __koru_handler_impl(__koru_p_0: i64, __koru_p_1: i64) @This().Output {
const __koru_event_input: @This().Input = .{ .a = __koru_p_0, .b = __koru_p_1 };
// >>> PROC: light [/Users/larsde/src/koru/tests/regression/600_STDLIB/690_STORE/690_351_pump_retired_unit_fires_once/lib/flicker.kz:10]
const a = __koru_event_input.a;
const b = __koru_event_input.b;
_ = &a;
_ = &b;
_ = &__koru_event_input;
a_left = a; b_left = b;
}
};
pub const a_step_event = struct {
pub const Input = struct {
};
pub const Output = i32;
pub fn handler(__koru_event_input: @This().Input) @This().Output {
// >>> PROC: a_step [/Users/larsde/src/koru/tests/regression/600_STDLIB/690_STORE/690_351_pump_retired_unit_fires_once/lib/flicker.kz:13]
_ = &__koru_event_input;
if (a_left > 0) { a_left -= 1; return 1; } return 0;
}
};
pub const a_live_event = struct {
pub const Input = struct {
};
pub const Output = i64;
pub fn handler(__koru_event_input: @This().Input) @This().Output {
// >>> PROC: a_live [/Users/larsde/src/koru/tests/regression/600_STDLIB/690_STORE/690_351_pump_retired_unit_fires_once/lib/flicker.kz:16]
_ = &__koru_event_input;
return a_left;
}
};
pub const b_step_event = struct {
pub const Input = struct {
};
pub const Output = i32;
pub fn handler(__koru_event_input: @This().Input) @This().Output {
// >>> PROC: b_step [/Users/larsde/src/koru/tests/regression/600_STDLIB/690_STORE/690_351_pump_retired_unit_fires_once/lib/flicker.kz:19]
_ = &__koru_event_input;
if (b_left > 0) { b_left -= 1; return 1; } return 0;
}
};
pub const b_live_event = struct {
pub const Input = struct {
};
pub const Output = i64;
pub fn handler(__koru_event_input: @This().Input) @This().Output {
// >>> PROC: b_live [/Users/larsde/src/koru/tests/regression/600_STDLIB/690_STORE/690_351_pump_retired_unit_fires_once/lib/flicker.kz:22]
_ = &__koru_event_input;
return b_left;
}
};
};
};
pub const koru_koru = struct {
pub const start_event = struct {
pub const Input = struct {
};
pub const Output = union(enum(u8)) {
done: struct {
},
};
pub fn handler(__koru_event_input: @This().Input) @This().Output {
_ = &__koru_event_input;
return .{ .done = .{} };
}
};
pub const end_event = struct {
pub const Input = struct {
};
pub const Output = union(enum(u8)) {
done: struct {
},
};
pub fn handler(__koru_event_input: @This().Input) @This().Output {
_ = &__koru_event_input;
return .{ .done = .{} };
}
};
};
pub fn main() void {
main_module.koru_start_flow();
main_module.flow0();
main_module.flow1();
main_module.flow2();
main_module.koru_end_flow();
if (comptime @import("builtin").mode == .Debug) koru_leak_check();
}
test {
@import("std").testing.refAllDeclsRecursive(@This());
}
Flows
flow ~light click a branch to expand · @labels scroll to their anchor
light (a: 2, b: 4)
flow ~create click a branch to expand · @labels scroll to their anchor
create (expr: main)
flow ~__pump_main_retired_0 click a branch to expand · @labels scroll to their anchor
__pump_main_retired_0
flow ~std/pump click a branch to expand · @labels scroll to their anchor
std/pump (main)
flow ~std/pump click a branch to expand · @labels scroll to their anchor
std/pump (main)
flow ~run click a branch to expand · @labels scroll to their anchor
run (main)
Test Configuration
MUST_RUN
koru.json:
{
"name": "probe",
"version": "0.1.0"
}