diff options
| author | gingerBill <bill@gingerbill.org> | 2022-08-11 13:35:24 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2022-08-11 13:35:24 +0100 |
| commit | 9eeed9d5bde1348d16d3c3790ba3178f3e0bb09d (patch) | |
| tree | b1bd1944012b94cbe6c2de52baba7d58c6587da8 /src/check_builtin.cpp | |
| parent | a054c2934eb0caa027a1663cca839cb422621558 (diff) | |
Simplify `#load_or` for the time being
Diffstat (limited to 'src/check_builtin.cpp')
| -rw-r--r-- | src/check_builtin.cpp | 34 |
1 files changed, 3 insertions, 31 deletions
diff --git a/src/check_builtin.cpp b/src/check_builtin.cpp index 70b5a0a13..b0c7f8d4b 100644 --- a/src/check_builtin.cpp +++ b/src/check_builtin.cpp @@ -1392,45 +1392,17 @@ bool check_builtin_procedure_directive(CheckerContext *c, Operand *operand, Ast gb_string_free(str); return false; } - - gbAllocator a = heap_allocator(); - GB_ASSERT(o.value.kind == ExactValue_String); - String base_dir = dir_from_path(get_file_path_string(bd->token.pos.file_id)); String original_string = o.value.value_string; - - BlockingMutex *ignore_mutex = nullptr; - String path = {}; - bool ok = determine_path_from_string(ignore_mutex, call, base_dir, original_string, &path); - gb_unused(ok); - - char *c_str = alloc_cstring(a, path); - defer (gb_free(a, c_str)); - - - gbFile f = {}; - gbFileError file_err = gb_file_open(&f, c_str); - defer (gb_file_close(&f)); - operand->type = t_u8_slice; operand->mode = Addressing_Constant; - if (file_err == gbFileError_None) { - String result = {}; - isize file_size = cast(isize)gb_file_size(&f); - if (file_size > 0) { - u8 *data = cast(u8 *)gb_alloc(a, file_size+1); - gb_file_read_at(&f, data, file_size, 0); - data[file_size] = '\0'; - result.text = data; - result.len = file_size; - } - - operand->value = exact_value_string(result); + LoadFileCache *cache = nullptr; + if (cache_load_file_directive(c, call, original_string, false, &cache)) { + operand->value = exact_value_string(cache->data); } else { operand->value = default_op.value; } - } else if (name == "assert") { if (ce->args.count != 1 && ce->args.count != 2) { error(call, "'#assert' expects either 1 or 2 arguments, got %td", ce->args.count); |