feat: add stdlib module support with auto-import resolution
- Parse module paths in stdlib (module Std::Array { ... })
- Collect stdlib declarations and inject into user modules before sema
- Add dkExternFunc support throughout pipeline (parser, sema, hir, c backend)
- Auto-dereference pointer types for field access (arr->field)
- Add hArrowField HIR node for cleaner C emission
- Fix resolveTypeExpr for pointer and cast types
- Fix struct field lowering to use resolveTypeExpr
- Allow int <-> uint implicit conversion for bootstrap convenience
- Add stdlib/Std/Array.bux with dynamic array primitives
- Add stdlib_test demonstrating Array usage via import Std::Array::{Array};
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
module Std::Array {
|
||||
|
||||
extern func bux_alloc(size: uint) -> *void;
|
||||
extern func bux_realloc(ptr: *void, size: uint) -> *void;
|
||||
extern func bux_free(ptr: *void);
|
||||
extern func bux_bounds_check(index: uint, len: uint);
|
||||
|
||||
struct Array {
|
||||
data: *int,
|
||||
len: uint,
|
||||
cap: uint,
|
||||
}
|
||||
|
||||
func Array_New(cap: uint) -> Array {
|
||||
let data = bux_alloc(cap * 8) as *int;
|
||||
return Array { data: data, len: 0, cap: cap };
|
||||
}
|
||||
|
||||
func Array_Push(arr: *Array, value: int) {
|
||||
if arr.len >= arr.cap {
|
||||
arr.cap = arr.cap * 2;
|
||||
arr.data = bux_realloc(arr.data as *void, arr.cap * 8) as *int;
|
||||
}
|
||||
arr.data[arr.len] = value;
|
||||
arr.len = arr.len + 1;
|
||||
}
|
||||
|
||||
func Array_Get(arr: *Array, index: uint) -> int {
|
||||
bux_bounds_check(index, arr.len);
|
||||
return arr.data[index];
|
||||
}
|
||||
|
||||
func Array_Len(arr: *Array) -> uint {
|
||||
return arr.len;
|
||||
}
|
||||
|
||||
func Array_Free(arr: *Array) {
|
||||
bux_free(arr.data as *void);
|
||||
arr.data = null as *int;
|
||||
arr.len = 0;
|
||||
arr.cap = 0;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user