** Simple insertion sort
** cmp should return >0 if left > right
*/
-sort :: (arr: ^[..] $T, cmp: (T, T) -> i32) {
- for i: 1 .. arr.count {
- x := arr.data[i];
- j := i - 1;
-
- @ShortCircuitLogicalOps // This is written this way because '&&' does not short circuit right now.
- while j >= 0 {
- if cmp(arr.data[j], x) > 0 {
- arr.data[j + 1] = arr.data[j];
- j -= 1;
- } else {
- break;
+sort :: proc {
+ (arr: ^[..] $T, cmp: (T, T) -> i32) {
+ for i: 1 .. arr.count {
+ x := arr.data[i];
+ j := i - 1;
+
+ @ShortCircuitLogicalOps // This is written this way because '&&' does not short circuit right now.
+ while j >= 0 {
+ if cmp(arr.data[j], x) > 0 {
+ arr.data[j + 1] = arr.data[j];
+ j -= 1;
+ } else {
+ break;
+ }
}
- }
-
- arr.data[j + 1] = x;
- }
-}
-sort_ptr :: (arr: ^[..] $T, cmp: (^T, ^T) -> i32) {
- for i: 1 .. arr.count {
- j := i;
+ arr.data[j + 1] = x;
+ }
+ },
- while j > 0 {
- if cmp(^arr.data[j - 1], ^arr.data[j]) > 0 {
- arr.data[j], arr.data[j - 1] = arr.data[j - 1], arr.data[j];
- j -= 1;
- } else {
- break;
+ (arr: ^[..] $T, cmp: (^T, ^T) -> i32) {
+ for i: 1 .. arr.count {
+ j := i;
+
+ while j > 0 {
+ if cmp(^arr.data[j - 1], ^arr.data[j]) > 0 {
+ arr.data[j], arr.data[j - 1] = arr.data[j - 1], arr.data[j];
+ j -= 1;
+ } else {
+ break;
+ }
}
}
}
func->type = type_build_function_type(context.ast_alloc, func);
- /*
- CLEANUP: These checks need to be ported to a process directive check.
- if ((func->flags & Ast_Flag_Exported) != 0) {
- if ((func->flags & Ast_Flag_Foreign) != 0) {
- onyx_report_error(func->token->pos, "exporting a foreign function");
- return Check_Error;
- }
-
- if ((func->flags & Ast_Flag_Intrinsic) != 0) {
- onyx_report_error(func->token->pos, "exporting a intrinsic function");
- return Check_Error;
- }
-
- if (func->exported_name == NULL) {
- onyx_report_error(func->token->pos, "exporting function without a name");
- return Check_Error;
- }
- }
- */
-
return Check_Success;
}
// Variables used during the symbol resolution phase.
static Scope* curr_scope = NULL;
-static Package* curr_package = NULL;
-static AstFunction* curr_function = NULL;
bh_arr(AstBlock *) block_stack = NULL;
static b32 report_unresolved_symbols = 1;
if (param->default_value != NULL) {
SYMRES(expression, ¶m->default_value);
if (onyx_has_errors()) return Symres_Error;
-
- // HACK: It shouldn't be necessary to do this twice, but right now
- // if `null` is the default parameter and it hasn't been used anywhere in
- // code yet, it doesn't resolve properly. So for now I am just checking symbols twice.
- // -brendanfh 2020/12/24
- SYMRES(expression, ¶m->default_value);
- if (onyx_has_errors()) return Symres_Error;
}
}
}
}
- curr_function = func;
SYMRES(block, func->body);
scope_leave();
if (export->export->kind == Ast_Kind_Function) {
AstFunction *func = (AstFunction *) export->export;
func->exported_name = export->export_name;
+
+ if ((func->flags & Ast_Flag_Exported) != 0) {
+ if ((func->flags & Ast_Flag_Foreign) != 0) {
+ onyx_report_error(export->token->pos, "exporting a foreign function");
+ return Symres_Error;
+ }
+
+ if ((func->flags & Ast_Flag_Intrinsic) != 0) {
+ onyx_report_error(export->token->pos, "exporting a intrinsic function");
+ return Symres_Error;
+ }
+
+ // NOTE: This should never happen
+ if (func->exported_name == NULL) {
+ onyx_report_error(export->token->pos, "exporting function without a name");
+ return Symres_Error;
+ }
+ }
}
break;
void symres_entity(Entity* ent) {
if (block_stack == NULL) bh_arr_new(global_heap_allocator, block_stack, 16);
- if (ent->package) curr_package = ent->package;
-
Scope* old_scope = NULL;
if (ent->scope) {
old_scope = curr_scope;
switch (ent->type) {
case Entity_Type_Binding: {
symbol_introduce(curr_scope, ent->binding->token, ent->binding->node);
- package_reinsert_use_packages(curr_package);
+ package_reinsert_use_packages(ent->package);
next_state = Entity_State_Finalized;
break;
}
if (ss == Symres_Yield_Micro) ent->micro_attempts++;
if (ent->scope) curr_scope = old_scope;
- curr_package = NULL;
}