feat: Phase 8.3 Concurrency — tasks, channels, spawn

- Add async/await/spawn keywords to lexer
- C runtime: pthread wrappers (bux_task_spawn, bux_task_join, bux_task_sleep)
- C runtime: mutex/condvar channel implementation (bux_channel_new/send/recv/close/free)
- Build command adds -pthread flag for C compilation
- Std::Task module: TaskHandle, Task_Spawn, Task_Join, Task_Sleep
- Std::Channel module: generic Channel<T> with Send, Recv, Close, Free
- Parser: spawn Expr() expression
- Sema: ekSpawn returns *void
- HIR: hSpawn node lowered from ekSpawn
- C backend: emit bux_task_spawn(FuncName, arg) for spawn expressions
- Example: examples/concurrency.bux (thread + channel demo)
- Example: examples_pkg/concurrency working project
This commit is contained in:
2026-06-01 00:04:48 +03:00
parent 8e255b2125
commit ac8b25935f
12 changed files with 271 additions and 2 deletions
+12
View File
@@ -444,6 +444,18 @@ proc parsePrimary(p: var Parser): Expr =
let ty = p.parseType()
discard p.expect(tkRParen, "expected ')'")
return Expr(kind: ekSizeOf, loc: loc, exprSizeOfType: ty)
of tkSpawn:
discard p.advance() # spawn
let callee = p.parsePrimary()
var args: seq[Expr] = @[]
if p.check(tkLParen):
discard p.advance() # (
while not p.check(tkRParen) and not p.isAtEnd:
args.add(p.parseExpr())
if p.check(tkComma):
discard p.advance()
discard p.expect(tkRParen, "expected ')' after spawn arguments")
return Expr(kind: ekSpawn, loc: loc, exprSpawnCallee: callee, exprSpawnArgs: args)
of tkHashLine:
discard p.advance()
return Expr(kind: ekIntrinsic, loc: loc, exprIntrinsic: ikLine)