feat: Phase 8.3 true non-blocking async/await with stackful coroutines
- C runtime: ucontext-based coroutines (bux_async_spawn/yield/await/run) - Round-robin scheduler in bux_async_run() manages ready queue - spawn Func() without args → bux_async_spawn() creates coroutine - await → blocks/yields until coroutine completes - async func → emitted as regular C function, runs on dedicated stack - Interleaved execution: multiple coroutines yield cooperatively - Example: examples/async.bux demonstrates WorkA/WorkB interleaving - All 20 examples pass, selfhost build works
This commit is contained in:
+4
-4
@@ -253,14 +253,14 @@ proc emitExpr(be: var CBackend, node: HirNode): string =
|
||||
return &"sizeof({typ})"
|
||||
|
||||
of hSpawn:
|
||||
var argsStr = ""
|
||||
if node.spawnArgs.len > 0:
|
||||
# Package arguments into a heap-allocated struct (simplified: single arg)
|
||||
# Fallback to OS thread spawn for functions with arguments
|
||||
var argsStr = ""
|
||||
let arg = be.emitExpr(node.spawnArgs[0])
|
||||
argsStr = &"(void*){arg}"
|
||||
return &"bux_task_spawn({node.spawnCallee}, {argsStr})"
|
||||
else:
|
||||
argsStr = "NULL"
|
||||
return &"bux_task_spawn({node.spawnCallee}, {argsStr})"
|
||||
return &"bux_async_spawn({node.spawnCallee})"
|
||||
|
||||
of hIf:
|
||||
# Ternary expression
|
||||
|
||||
Reference in New Issue
Block a user