0dade151d2
Bootstrap compiler improvements: - Extract findStdlibDir() to remove hardcoded path and deduplicate - Extract prepareProject()/mergeProject() to share code between cmdCheck/cmdBuild - Fix C backend to emit warning on unknown types instead of silent 'int' - Clean up all unused imports across 7 modules - Makefile: add strip, debug target, clean-all, selfhost strip QBE removal: - Remove vendor/qbe/ (74K lines) - Remove compiler/selfhost/qbe_backend.bux, nim_backend.bux Stdlib improvements: - Add Result.bux + Option.bux modules - Fix Json.bux memory leak (removed double String_Copy) - Add missing imports in Crypto.bux (Alloc/Free) and Test.bux (PrintLine/PrintInt) - Clean stale buxc_debug binary
57 lines
1.4 KiB
Plaintext
57 lines
1.4 KiB
Plaintext
module Std::Channel {
|
|
|
|
extern func bux_channel_new(capacity: int64, elem_size: int64) -> *void;
|
|
extern func bux_channel_send(handle: *void, elem: *void);
|
|
extern func bux_channel_recv(handle: *void, out: *void) -> int;
|
|
extern func bux_channel_close(handle: *void);
|
|
extern func bux_channel_free(handle: *void);
|
|
|
|
struct Channel<T> {
|
|
handle: *void;
|
|
}
|
|
|
|
func Channel_New<T>(capacity: int64) -> Channel<T> {
|
|
return Channel<T> { handle: bux_channel_new(capacity, sizeof(T)) };
|
|
}
|
|
|
|
func Channel_Send<T>(ch: *Channel<T>, value: T) {
|
|
bux_channel_send(ch.handle, (&value) as *void);
|
|
}
|
|
|
|
func Channel_Recv<T>(ch: *Channel<T>) -> T {
|
|
var result: T;
|
|
bux_channel_recv(ch.handle, (&result) as *void);
|
|
return result;
|
|
}
|
|
|
|
func Channel_Close<T>(ch: *Channel<T>) {
|
|
bux_channel_close(ch.handle);
|
|
}
|
|
|
|
func Channel_Free<T>(ch: *Channel<T>) {
|
|
bux_channel_free(ch.handle);
|
|
}
|
|
|
|
/* Convenience wrappers for common types */
|
|
func Channel_SendInt(ch: *Channel<int>, value: int) {
|
|
bux_channel_send(ch.handle, (&value) as *void);
|
|
}
|
|
|
|
func Channel_RecvInt(ch: *Channel<int>) -> int {
|
|
var result: int = 0;
|
|
bux_channel_recv(ch.handle, (&result) as *void);
|
|
return result;
|
|
}
|
|
|
|
func Channel_SendFloat64(ch: *Channel<float64>, value: float64) {
|
|
bux_channel_send(ch.handle, (&value) as *void);
|
|
}
|
|
|
|
func Channel_RecvFloat64(ch: *Channel<float64>) -> float64 {
|
|
var result: float64 = 0.0;
|
|
bux_channel_recv(ch.handle, (&result) as *void);
|
|
return result;
|
|
}
|
|
|
|
}
|