21f8b2e85a
Self-hosted compiler (buxc2):
- Add async/await/spawn tokens, parsing, HIR, lowering, C emission
- Fix pointer type emission (*T -> T*) in C backend
- Fix sizeof(Type) parsing with parentheses
- Fix import ::{...} infinite loop guard
- Fix int64 emission by avoiding else-if chain workaround
- Add debug-free cli and hir_lower
Bootstrap compiler (Nim):
- Fix critical else-if lowering bug in hir_lower.nim:
when both elseIfs and else block exist, elseIfs were dropped
causing all else-if chains to collapse to if+else only
Runtime:
- Fix bux_async_await memory corruption (don't free in run)
- Add bux_remove_from_ready for safe cleanup
- Fix forward declaration and deduplicate bux_now_ms
Docs & examples:
- Update async.bux example with proper int64 params
- Update README, LanguageRef, Stdlib, PLAN for async features
- Mark Phase 7.10 bootstrap loop as completed
All 27 examples pass. buxc2 check/build work on all examples.
44 lines
1.1 KiB
Plaintext
44 lines
1.1 KiB
Plaintext
import Std::Io::{PrintLine, PrintInt};
|
|
|
|
extern func bux_async_yield();
|
|
extern func bux_async_run();
|
|
extern func bux_async_spawn(fn: *void) -> *void;
|
|
extern func bux_async_await(handle: *void) -> *void;
|
|
extern func bux_async_return(value: *void, size: int64);
|
|
extern func bux_async_sleep(ms: int64);
|
|
|
|
async func Compute() -> int {
|
|
PrintLine("Compute: start");
|
|
bux_async_sleep(100);
|
|
PrintLine("Compute: after 100ms");
|
|
let result: int = 42;
|
|
bux_async_return((&result) as *void, sizeof(int));
|
|
return result;
|
|
}
|
|
|
|
async func Double() -> int {
|
|
PrintLine("Double: start");
|
|
bux_async_sleep(50);
|
|
PrintLine("Double: after 50ms");
|
|
let result: int = 84;
|
|
bux_async_return((&result) as *void, sizeof(int));
|
|
return result;
|
|
}
|
|
|
|
func Main() -> int {
|
|
PrintLine("Main: start");
|
|
let h1: *void = spawn Compute();
|
|
let h2: *void = spawn Double();
|
|
let r1Ptr: *int = h1.await as *int;
|
|
let r2Ptr: *int = h2.await as *int;
|
|
let r1: int = *r1Ptr;
|
|
let r2: int = *r2Ptr;
|
|
PrintLine("Results:");
|
|
PrintInt(r1);
|
|
PrintLine("");
|
|
PrintInt(r2);
|
|
PrintLine("");
|
|
PrintLine("Main: done");
|
|
return 0;
|
|
}
|