cresize :: proc (ptr: rawptr, size: u32) -> rawptr do return resize(context.allocator, ptr, size);
cfree :: proc (ptr: rawptr) do free(context.allocator, ptr);
-array_init :: proc(arr: ^[..] $T) {
+array_init :: proc(arr: ^[..] $T, initial_cap := 4) {
arr.count = 0;
- arr.capacity = 4;
+ arr.capacity = initial_cap;
arr.data = calloc(sizeof T * arr.capacity);
}
arr.count += 1;
}
+array_remove_at :: proc (arr: ^[..] $T, idx: u32) {
+ if idx >= arr.count do return;
+
+ for i: idx, arr.count - 1 {
+ arr.data[i] = arr.data[i + 1];
+ }
+
+ arr.count -= 1;
+}
+
+array_remove :: proc (arr: ^[..] $T, elem: T) {
+ move := 0;
+
+ for i: 0, arr.count - move {
+ if arr.data[i + move] == elem do move += 1;
+ if move != 0 do arr.data[i] = arr.data[i + move];
+ }
+
+ arr.count -= move;
+}
+
context : struct {
allocator : Allocator;
temp_allocator : Allocator;
package main
-#include_folder "/usr/share/onyx/core"
+#include_folder "./core"
#include_file "builtin"
#include_file "wasi"
print("\n\n");
}
-print_arr :: proc (arr: [..] $T) {
+print_arr :: proc (arr: ^[..] $T) {
for i: 0, arr.count {
- print(arr[i]);
+ print(arr.data[i]);
print(" ");
}
main :: proc (args: [] cstring) {
arr : [..] i32;
- array_init(^arr);
+ array_init(^arr, 24);
print_arr_details(^arr);
array_add(^arr, 1234);
- for i: 0, 12 do array_add(^arr, i * 2 + 2);
+ for i: 0, 12 do array_add(^arr, i % 5);
print_arr_details(^arr);
+ print_arr(^arr);
- print_arr(arr);
+ array_remove_at(^arr, 4);
+
+ print_arr_details(^arr);
+ print_arr(^arr);
+
+ array_remove(^arr, 1);
+ array_remove(^arr, 4);
+
+ print_arr_details(^arr);
+ print_arr(^arr);
}
\ No newline at end of file
bh_table_put(AstFunction *, pp->concrete_funcs, key_buf, func);
symres_function(func);
+ if (onyx_message_has_errors()) return NULL;
if (check_function_header(func)) return NULL;
if (check_function(func)) return NULL;
+ if (onyx_message_has_errors()) return NULL;
bh_arr_push(semstate.other_entities, ((Entity) {
.type = Entity_Type_Function_Header,