feat: async/await/spawn + fix else-if lowering bug

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.
This commit is contained in:
2026-06-01 02:57:46 +03:00
parent 42041dfd74
commit 21f8b2e85a
24 changed files with 448 additions and 110 deletions
+21 -16
View File
@@ -145,6 +145,26 @@ func CBE_EmitExpr(cbe: *CEmitter, node: *HirNode) {
return;
}
// spawn Callee(args)
if kind == hSpawn {
StringBuilder_Append(&cbe.sb, "bux_async_spawn(");
StringBuilder_Append(&cbe.sb, node.strValue);
if node.child1 != null as *HirNode {
StringBuilder_Append(&cbe.sb, ", (void*)");
CBE_EmitExpr(cbe, node.child1);
}
StringBuilder_Append(&cbe.sb, ")");
return;
}
// await
if kind == hAwait {
StringBuilder_Append(&cbe.sb, "bux_async_await(");
CBE_EmitExpr(cbe, node.child1);
StringBuilder_Append(&cbe.sb, ")");
return;
}
// Return
if kind == hReturn {
StringBuilder_Append(&cbe.sb, "return");
@@ -371,24 +391,9 @@ func CBE_EmitFuncDecl(cbe: *CEmitter, f: *HirFunc) {
// Return type
if String_Eq(f.retTypeName, "") || String_Eq(f.retTypeName, "void") {
StringBuilder_Append(&cbe.sb, "void ");
} else if String_Eq(f.retTypeName, "String") || String_Eq(f.retTypeName, "str") {
StringBuilder_Append(&cbe.sb, "String ");
} else if String_Eq(f.retTypeName, "bool") {
StringBuilder_Append(&cbe.sb, "bool ");
} else if String_Eq(f.retTypeName, "int") {
StringBuilder_Append(&cbe.sb, "int ");
} else if String_Eq(f.retTypeName, "int64") {
StringBuilder_Append(&cbe.sb, "int64 ");
} else if String_Eq(f.retTypeName, "uint") {
StringBuilder_Append(&cbe.sb, "uint ");
} else if String_Eq(f.retTypeName, "float64") {
StringBuilder_Append(&cbe.sb, "float64 ");
} else if f.retTypeKind == tyNamed || !String_Eq(f.retTypeName, "") {
// Use the struct name directly (e.g., "Point", "Type")
} else {
StringBuilder_Append(&cbe.sb, f.retTypeName);
StringBuilder_Append(&cbe.sb, " ");
} else {
StringBuilder_Append(&cbe.sb, "int "); // fallback
}
StringBuilder_Append(&cbe.sb, f.name);