-static bh_imap implicit_cast_to_bool_cache;
-
TypeMatch implicit_cast_to_bool(AstTyped **pnode) {
AstTyped *node = *pnode;
return TYPE_MATCH_SUCCESS;
}
- if (implicit_cast_to_bool_cache.entries == NULL) {
- bh_imap_init(&implicit_cast_to_bool_cache, global_heap_allocator, 8);
+ if (context.caches.implicit_cast_to_bool_cache.entries == NULL) {
+ bh_imap_init(&context.caches.implicit_cast_to_bool_cache, global_heap_allocator, 8);
}
- if (!bh_imap_has(&implicit_cast_to_bool_cache, (u64) node)) {
+ if (!bh_imap_has(&context.caches.implicit_cast_to_bool_cache, (u64) node)) {
AstArgument *implicit_arg = make_argument(context.ast_alloc, node);
Arguments *args = bh_alloc_item(context.ast_alloc, Arguments);
bh_arr_new(context.ast_alloc, args->values, 1);
bh_arr_push(args->values, (AstTyped *) implicit_arg);
- bh_imap_put(&implicit_cast_to_bool_cache, (u64) node, (u64) args);
+ bh_imap_put(&context.caches.implicit_cast_to_bool_cache, (u64) node, (u64) args);
}
- Arguments *args = (Arguments *) bh_imap_get(&implicit_cast_to_bool_cache, (u64) node);
+ Arguments *args = (Arguments *) bh_imap_get(&context.caches.implicit_cast_to_bool_cache, (u64) node);
AstFunction *overload = (AstFunction *) find_matching_overload_by_arguments(builtin_implicit_bool_cast->overloads, args);
if (overload == NULL) return TYPE_MATCH_FAILED;
implicit_call->args.values = args->values;
*(AstCall **) pnode = implicit_call;
- bh_imap_delete(&implicit_cast_to_bool_cache, (u64) node);
+ bh_imap_delete(&context.caches.implicit_cast_to_bool_cache, (u64) node);
return TYPE_MATCH_YIELD;
}
#include "errors.h"
#include "utils.h"
-OnyxErrors errors;
-static b32 errors_enabled = 1;
-
void onyx_errors_init(bh_arr(bh_file_contents)* files) {
- errors.file_contents = files;
+ context.errors.file_contents = files;
- bh_arena_init(&errors.msg_arena, global_heap_allocator, 16 * 1024);
- errors.msg_alloc = bh_arena_allocator(&errors.msg_arena);
+ bh_arena_init(&context.errors.msg_arena, global_heap_allocator, 16 * 1024);
+ context.errors.msg_alloc = bh_arena_allocator(&context.errors.msg_arena);
- bh_arr_new(global_heap_allocator, errors.errors, 4);
+ bh_arr_new(global_heap_allocator, context.errors.errors, 4);
}
static void print_detailed_message(OnyxError* err, bh_file_contents* fc) {
//
// - brendanfh 2020/09/03
- qsort(errors.errors, bh_arr_length(errors.errors), sizeof(OnyxError), errors_sort);
+ qsort(context.errors.errors, bh_arr_length(context.errors.errors), sizeof(OnyxError), errors_sort);
- OnyxErrorRank last_rank = errors.errors[0].rank;
- bh_arr_each(OnyxError, err, errors.errors) {
+ OnyxErrorRank last_rank = context.errors.errors[0].rank;
+ bh_arr_each(OnyxError, err, context.errors.errors) {
if (!context.options->show_all_errors && last_rank != err->rank) break;
if (err->pos.filename) {
bh_file_contents file_contents = { 0 };
- bh_arr_each(bh_file_contents, fc, *errors.file_contents) {
+ bh_arr_each(bh_file_contents, fc, *context.errors.file_contents) {
if (!strcmp(fc->filename, err->pos.filename)) {
file_contents = *fc;
break;
}
void onyx_errors_enable() {
- errors_enabled = 1;
+ context.errors_enabled = 1;
}
void onyx_errors_disable() {
if (context.cycle_detected) {
- errors_enabled = 1;
+ context.errors_enabled = 1;
return;
}
- errors_enabled = 0;
+ context.errors_enabled = 0;
}
b32 onyx_errors_are_enabled() {
- return errors_enabled;
+ return context.errors_enabled;
}
b32 onyx_has_errors() {
- bh_arr_each(OnyxError, err, errors.errors) {
+ bh_arr_each(OnyxError, err, context.errors.errors) {
if (err->rank >= Error_Waiting_On) return 1;
}
void onyx_clear_errors() {
if (context.cycle_detected) return;
- bh_arr_set_length(errors.errors, 0);
+ bh_arr_set_length(context.errors.errors, 0);
}
void onyx_submit_error(OnyxError error) {
- if (!errors_enabled) return;
+ if (!context.errors_enabled) return;
- bh_arr_push(errors.errors, error);
+ bh_arr_push(context.errors.errors, error);
}
void onyx_report_error(OnyxFilePos pos, OnyxErrorRank rank, char * format, ...) {
- if (!errors_enabled) return;
+ if (!context.errors_enabled) return;
va_list vargs;
va_start(vargs, format);
OnyxError err = {
.pos = pos,
.rank = rank,
- .text = bh_strdup(errors.msg_alloc, msg),
+ .text = bh_strdup(context.errors.msg_alloc, msg),
};
- bh_arr_push(errors.errors, err);
+ bh_arr_push(context.errors.errors, err);
}
void onyx_submit_warning(OnyxError error) {
- if (!errors_enabled) return;
+ if (!context.errors_enabled) return;
bh_file_contents file_contents = { 0 };
- bh_arr_each(bh_file_contents, fc, *errors.file_contents) {
+ bh_arr_each(bh_file_contents, fc, *context.errors.file_contents) {
if (!strcmp(fc->filename, error.pos.filename)) {
file_contents = *fc;
break;
// This definitely doesn't do what I thought it did?
void onyx_report_warning(OnyxFilePos pos, char* format, ...) {
- if (!errors_enabled) return;
+ if (!context.errors_enabled) return;
va_list vargs;
va_start(vargs, format);
OnyxError err = {
.pos = pos,
.rank = Error_Warning,
- .text = bh_strdup(errors.msg_alloc, msg),
+ .text = bh_strdup(context.errors.msg_alloc, msg),
};
- bh_arr_push(errors.errors, err);
+ bh_arr_push(context.errors.errors, err);
/*
bh_file_contents file_contents = { 0 };
- bh_arr_each(bh_file_contents, fc, *errors.file_contents) {
+ bh_arr_each(bh_file_contents, fc, *context.errors.file_contents) {
if (!strcmp(fc->filename, pos.filename)) {
file_contents = *fc;
break;