f63cbd1bf0
- AST: add typeParam0Bound/typeParam1Bound to Decl, strValue2 to dkImpl - Parser: parse <T: Trait> bounds, Self type in interfaces, extend-for blocks - Sema: add interfaceTable/methodTable, Sema_CheckTraitBounds, Sema_TypeImplements - HIR lower: two-pass decl iteration — collect generic funcs before lowering bodies Fixes Max<Circle>(...) not generating Max_Circle when caller precedes callee - C backend: skip generic funcs in emission (only emit monomorphized instances) - Array.bux: fix for-loop over monomorphized Array types - All debug prints removed; selfhost loop passes (C output IDENTICAL)
50 lines
1.1 KiB
Plaintext
50 lines
1.1 KiB
Plaintext
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<T> {
|
|
data: *T,
|
|
len: uint,
|
|
cap: uint,
|
|
}
|
|
|
|
func Array_New<T>(cap: uint) -> Array<T> {
|
|
let data = bux_alloc(cap * sizeof(T)) as *T;
|
|
return Array<T> { data: data, len: 0, cap: cap };
|
|
}
|
|
|
|
func Array_Push<T>(self: *Array<T>, value: T) {
|
|
if self.len >= self.cap {
|
|
self.cap = self.cap * 2;
|
|
self.data = bux_realloc(self.data as *void, self.cap * sizeof(T)) as *T;
|
|
}
|
|
self.data[self.len] = value;
|
|
self.len = self.len + 1;
|
|
}
|
|
|
|
func Array_Get<T>(self: *Array<T>, index: uint) -> T {
|
|
bux_bounds_check(index, self.len);
|
|
return self.data[index];
|
|
}
|
|
|
|
func Array_Set<T>(self: *Array<T>, index: uint, value: T) {
|
|
bux_bounds_check(index, self.len);
|
|
self.data[index] = value;
|
|
}
|
|
|
|
func Array_Len<T>(self: *Array<T>) -> uint {
|
|
return self.len;
|
|
}
|
|
|
|
func Array_Free<T>(self: *Array<T>) {
|
|
bux_free(self.data as *void);
|
|
self.data = null as *T;
|
|
self.len = 0;
|
|
self.cap = 0;
|
|
}
|
|
|
|
}
|