feat: async functions with return values

- runtime: bux_async_return(value, size) copies result to task->result
- runtime: bux_async_await returns void* result pointer
- runtime: bux_async_result(handle) to retrieve result
- sema: ekAwait returns *void
- HIR: await lowered to bux_async_await returning *void
- Example: async Compute() -> int with interleaved execution and result await
This commit is contained in:
2026-06-01 01:13:48 +03:00
parent 5ec755743d
commit 42041dfd74
4 changed files with 48 additions and 22 deletions
+1 -1
View File
@@ -770,7 +770,7 @@ proc lowerExpr(ctx: var LowerCtx, expr: Expr): HirNode =
of ekAwait:
let lowered = ctx.lowerExpr(expr.exprAwaitOperand)
return hirCall("bux_async_await", @[lowered], makeVoid(), loc)
return hirCall("bux_async_await", @[lowered], makePointer(makeVoid()), loc)
else:
return HirNode(kind: hLit, litToken: Token(kind: tkIntLiteral, text: "0", loc: loc),
+2 -2
View File
@@ -1010,8 +1010,8 @@ proc checkExpr(sema: var Sema, expr: Expr, scope: Scope): Type =
return makePointer(makeVoid())
of ekAwait:
let operand = sema.checkExpr(expr.exprAwaitOperand, scope)
# await on a task handle returns void for now
return makeVoid()
# await on a task handle returns *void (result pointer)
return makePointer(makeVoid())
of ekSpread:
return sema.checkExpr(expr.exprSpreadOperand, scope)