cHeader: "\nimport { types as t, struct, member, sizeof } from 'utilium';\n\ntype int8 = number;\ntype uint8 = number;\ntype int16 = number;\ntype uint16 = number;\ntype int32 = number;\ntype uint32 = number;\ntype int64 = bigint;\ntype uint64 = bigint;\ntype int128 = bigint;\ntype uint128 = bigint;\ntype float32 = number;\ntype float64 = number;\ntype float128 = number;\n\ntype bool = boolean | number;\ntype Ref<T> = bigint & { __ref__?: T };\ntype ConstArray<T, L extends number> = Array<T> & { length: L } & Ref<T>;\n\ndeclare function $__assert(condition: boolean, message?: Ref<int8>): void;\ndeclare function $__ref<T>(value: T): Ref<T>;\ndeclare function $__deref<T>(value: Ref<T>): T;\ndeclare function $__array<T>(start: Ref<T>, i: bigint): T | undefined;\ndeclare function $__array<T>(start: Ref<T>, i: bigint, value?: T): void;\ndeclare function $__str(value: string): Ref<int8>;\ndeclare function $__allocConstArray<T, L extends number>(length: L, ...init: T[]): ConstArray<T, L>;\n\ndeclare let __func__: string | undefined;\n" = ...
Boilerplate to make stuff with C work
Ref<T>
Pointer to
T
. Note__ref__
doesn't actually exist and is only here to keep TS types when passing it aroundConstArray<T, L>
Constant array
T[L]
.$__ref<T>(value: T): Ref<T>;
Equivalent to C
&value
$__deref<T>(value: Ref<T>): T;
Equivalent to C
(*value)
$__deref_set<T>(left: Ref<T>, right: Ref<T> | T): void;
Equivalent to C
(*value) = ...
$__array<T>(start: Ref<T>, i: bigint): T;
Access an element of an array, but using the pointer type (e.g. accessing
x[0]
wherex
ischar*
)$__array<T>(start: Ref<T>, i: bigint, value?: T): void;
Set an element of an array, but using the pointer type (e.g.
x[0] = ...
wherex
ischar*
)$__str(value: string): Ref<int8>;
Converts a JS string literal into a
char*
/Ref<int8>
$__allocConstArray<T, L extends number>(length: L, ...init: T[]): ConstArray<T, L>;
Allocates an array of length
L
with elements of typeT
. Takes in optional initializers