Merge branch 'master' into bill/sdl3

This commit is contained in:
gingerBill
2025-02-07 07:53:47 +00:00
10 changed files with 50 additions and 54 deletions
+2
View File
@@ -13,6 +13,8 @@ _load_library :: proc(path: string, global_symbols: bool, allocator: runtime.All
flags := posix.RTLD_Flags{.NOW} flags := posix.RTLD_Flags{.NOW}
if global_symbols { if global_symbols {
flags += {.GLOBAL} flags += {.GLOBAL}
} else {
flags += posix.RTLD_LOCAL
} }
cpath := strings.clone_to_cstring(path, allocator) cpath := strings.clone_to_cstring(path, allocator)
+2 -2
View File
@@ -126,7 +126,7 @@ _i64_err :: #force_inline proc "contextless" (n: int, err: Error) -> (i64, Error
} }
// read reads up to len(p) bytes into s. It returns the number of bytes read and any error if occurred. // read reads up to len(p) bytes into p. It returns the number of bytes read and any error if occurred.
// //
// When read encounters an .EOF or error after successfully reading n > 0 bytes, it returns the number of // When read encounters an .EOF or error after successfully reading n > 0 bytes, it returns the number of
// bytes read along with the error. // bytes read along with the error.
@@ -142,7 +142,7 @@ read :: proc(s: Reader, p: []byte, n_read: ^int = nil) -> (n: int, err: Error) {
return return
} }
// write writes up to len(p) bytes into s. It returns the number of bytes written and any error if occurred. // write writes up to len(p) bytes into p. It returns the number of bytes written and any error if occurred.
write :: proc(s: Writer, p: []byte, n_written: ^int = nil) -> (n: int, err: Error) { write :: proc(s: Writer, p: []byte, n_written: ^int = nil) -> (n: int, err: Error) {
if s.procedure != nil { if s.procedure != nil {
n64: i64 n64: i64
+1 -1
View File
@@ -468,7 +468,7 @@ Example:
Possible Output: Possible Output:
15.312 15.312
673.130 273.130
*/ */
@(require_results) float32_range :: proc(low, high: f32, gen := context.random_generator) -> (val: f32) { @(require_results) float32_range :: proc(low, high: f32, gen := context.random_generator) -> (val: f32) {
+9 -6
View File
@@ -1031,14 +1031,17 @@ Returns:
*/ */
@private @private
_split_iterator :: proc(s: ^string, sep: string, sep_save: int) -> (res: string, ok: bool) { _split_iterator :: proc(s: ^string, sep: string, sep_save: int) -> (res: string, ok: bool) {
m: int
if sep == "" { if sep == "" {
res = s[:] if len(s) == 0 {
ok = true m = -1
s^ = s[len(s):] } else {
return _, w := utf8.decode_rune_in_string(s^)
m = w
}
} else {
m = index(s^, sep)
} }
m := index(s^, sep)
if m < 0 { if m < 0 {
// not found // not found
res = s[:] res = s[:]
+2 -2
View File
@@ -532,9 +532,9 @@ gb_internal void report_os_info() {
return; return;
} }
uint32_t major, minor, patch; uint32_t major, minor, patch = 0;
if (sscanf(cast(const char *)sw_vers, "%u.%u.%u", &major, &minor, &patch) != 3) { if (sscanf(cast(const char *)sw_vers, "%u.%u.%u", &major, &minor, &patch) < 1) {
gb_printf("macOS Unknown\n"); gb_printf("macOS Unknown\n");
return; return;
} }
+3
View File
@@ -5544,6 +5544,9 @@ gb_internal bool check_builtin_procedure(CheckerContext *c, Operand *operand, As
// NOTE(bill): Is this even correct? // NOTE(bill): Is this even correct?
new_type->Union.node = operand->expr; new_type->Union.node = operand->expr;
new_type->Union.scope = bt->Union.scope; new_type->Union.scope = bt->Union.scope;
if (bt->Union.kind == UnionType_no_nil) {
new_type->Union.kind = UnionType_no_nil;
}
operand->type = new_type; operand->type = new_type;
} }
+6
View File
@@ -169,11 +169,17 @@ gb_internal void lb_correct_entity_linkage(lbGenerator *gen) {
other_global = LLVMGetNamedGlobal(ec.other_module->mod, ec.cname); other_global = LLVMGetNamedGlobal(ec.other_module->mod, ec.cname);
if (other_global) { if (other_global) {
LLVMSetLinkage(other_global, LLVMWeakAnyLinkage); LLVMSetLinkage(other_global, LLVMWeakAnyLinkage);
if (!ec.e->Variable.is_export) {
LLVMSetVisibility(other_global, LLVMHiddenVisibility);
}
} }
} else if (ec.e->kind == Entity_Procedure) { } else if (ec.e->kind == Entity_Procedure) {
other_global = LLVMGetNamedFunction(ec.other_module->mod, ec.cname); other_global = LLVMGetNamedFunction(ec.other_module->mod, ec.cname);
if (other_global) { if (other_global) {
LLVMSetLinkage(other_global, LLVMWeakAnyLinkage); LLVMSetLinkage(other_global, LLVMWeakAnyLinkage);
if (!ec.e->Procedure.is_export) {
LLVMSetVisibility(other_global, LLVMHiddenVisibility);
}
} }
} }
} }
+2 -6
View File
@@ -3364,9 +3364,7 @@ gb_internal lbValue lb_build_unary_and(lbProcedure *p, Ast *expr) {
auto args = array_make<lbValue>(permanent_allocator(), arg_count); auto args = array_make<lbValue>(permanent_allocator(), arg_count);
args[0] = ok; args[0] = ok;
args[1] = lb_find_or_add_entity_string(p->module, get_file_path_string(pos.file_id)); lb_set_file_line_col(p, array_slice(args, 1, args.count), pos);
args[2] = lb_const_int(p->module, t_i32, pos.line);
args[3] = lb_const_int(p->module, t_i32, pos.column);
if (!build_context.no_rtti) { if (!build_context.no_rtti) {
args[4] = lb_typeid(p->module, src_type); args[4] = lb_typeid(p->module, src_type);
@@ -3393,9 +3391,7 @@ gb_internal lbValue lb_build_unary_and(lbProcedure *p, Ast *expr) {
auto args = array_make<lbValue>(permanent_allocator(), 6); auto args = array_make<lbValue>(permanent_allocator(), 6);
args[0] = ok; args[0] = ok;
args[1] = lb_find_or_add_entity_string(p->module, get_file_path_string(pos.file_id)); lb_set_file_line_col(p, array_slice(args, 1, args.count), pos);
args[2] = lb_const_int(p->module, t_i32, pos.line);
args[3] = lb_const_int(p->module, t_i32, pos.column);
args[4] = any_id; args[4] = any_id;
args[5] = id; args[5] = id;
+21 -31
View File
@@ -15,7 +15,6 @@ gb_global isize lb_global_type_info_member_offsets_index = 0;
gb_global isize lb_global_type_info_member_usings_index = 0; gb_global isize lb_global_type_info_member_usings_index = 0;
gb_global isize lb_global_type_info_member_tags_index = 0; gb_global isize lb_global_type_info_member_tags_index = 0;
gb_internal void lb_init_module(lbModule *m, Checker *c) { gb_internal void lb_init_module(lbModule *m, Checker *c) {
m->info = &c->info; m->info = &c->info;
@@ -540,6 +539,22 @@ gb_internal lbValue lb_build_addr_ptr(lbProcedure *p, Ast *expr) {
return lb_addr_get_ptr(p, addr); return lb_addr_get_ptr(p, addr);
} }
gb_internal void lb_set_file_line_col(lbProcedure *p, Array<lbValue> arr, TokenPos pos) {
String file = get_file_path_string(pos.file_id);
i32 line = pos.line;
i32 col = pos.column;
if (build_context.obfuscate_source_code_locations) {
file = obfuscate_string(file, "F");
line = obfuscate_i32(line);
col = obfuscate_i32(col);
}
arr[0] = lb_find_or_add_entity_string(p->module, file);
arr[1] = lb_const_int(p->module, t_i32, line);
arr[2] = lb_const_int(p->module, t_i32, col);
}
gb_internal void lb_emit_bounds_check(lbProcedure *p, Token token, lbValue index, lbValue len) { gb_internal void lb_emit_bounds_check(lbProcedure *p, Token token, lbValue index, lbValue len) {
if (build_context.no_bounds_check) { if (build_context.no_bounds_check) {
return; return;
@@ -553,14 +568,8 @@ gb_internal void lb_emit_bounds_check(lbProcedure *p, Token token, lbValue index
index = lb_emit_conv(p, index, t_int); index = lb_emit_conv(p, index, t_int);
len = lb_emit_conv(p, len, t_int); len = lb_emit_conv(p, len, t_int);
lbValue file = lb_find_or_add_entity_string(p->module, get_file_path_string(token.pos.file_id));
lbValue line = lb_const_int(p->module, t_i32, token.pos.line);
lbValue column = lb_const_int(p->module, t_i32, token.pos.column);
auto args = array_make<lbValue>(temporary_allocator(), 5); auto args = array_make<lbValue>(temporary_allocator(), 5);
args[0] = file; lb_set_file_line_col(p, args, token.pos);
args[1] = line;
args[2] = column;
args[3] = index; args[3] = index;
args[4] = len; args[4] = len;
@@ -582,14 +591,8 @@ gb_internal void lb_emit_matrix_bounds_check(lbProcedure *p, Token token, lbValu
row_count = lb_emit_conv(p, row_count, t_int); row_count = lb_emit_conv(p, row_count, t_int);
column_count = lb_emit_conv(p, column_count, t_int); column_count = lb_emit_conv(p, column_count, t_int);
lbValue file = lb_find_or_add_entity_string(p->module, get_file_path_string(token.pos.file_id));
lbValue line = lb_const_int(p->module, t_i32, token.pos.line);
lbValue column = lb_const_int(p->module, t_i32, token.pos.column);
auto args = array_make<lbValue>(temporary_allocator(), 7); auto args = array_make<lbValue>(temporary_allocator(), 7);
args[0] = file; lb_set_file_line_col(p, args, token.pos);
args[1] = line;
args[2] = column;
args[3] = row_index; args[3] = row_index;
args[4] = column_index; args[4] = column_index;
args[5] = row_count; args[5] = row_count;
@@ -610,14 +613,8 @@ gb_internal void lb_emit_multi_pointer_slice_bounds_check(lbProcedure *p, Token
low = lb_emit_conv(p, low, t_int); low = lb_emit_conv(p, low, t_int);
high = lb_emit_conv(p, high, t_int); high = lb_emit_conv(p, high, t_int);
lbValue file = lb_find_or_add_entity_string(p->module, get_file_path_string(token.pos.file_id));
lbValue line = lb_const_int(p->module, t_i32, token.pos.line);
lbValue column = lb_const_int(p->module, t_i32, token.pos.column);
auto args = array_make<lbValue>(permanent_allocator(), 5); auto args = array_make<lbValue>(permanent_allocator(), 5);
args[0] = file; lb_set_file_line_col(p, args, token.pos);
args[1] = line;
args[2] = column;
args[3] = low; args[3] = low;
args[4] = high; args[4] = high;
@@ -632,16 +629,11 @@ gb_internal void lb_emit_slice_bounds_check(lbProcedure *p, Token token, lbValue
return; return;
} }
lbValue file = lb_find_or_add_entity_string(p->module, get_file_path_string(token.pos.file_id));
lbValue line = lb_const_int(p->module, t_i32, token.pos.line);
lbValue column = lb_const_int(p->module, t_i32, token.pos.column);
high = lb_emit_conv(p, high, t_int); high = lb_emit_conv(p, high, t_int);
if (!lower_value_used) { if (!lower_value_used) {
auto args = array_make<lbValue>(permanent_allocator(), 5); auto args = array_make<lbValue>(permanent_allocator(), 5);
args[0] = file; lb_set_file_line_col(p, args, token.pos);
args[1] = line;
args[2] = column;
args[3] = high; args[3] = high;
args[4] = len; args[4] = len;
@@ -651,9 +643,7 @@ gb_internal void lb_emit_slice_bounds_check(lbProcedure *p, Token token, lbValue
low = lb_emit_conv(p, low, t_int); low = lb_emit_conv(p, low, t_int);
auto args = array_make<lbValue>(permanent_allocator(), 6); auto args = array_make<lbValue>(permanent_allocator(), 6);
args[0] = file; lb_set_file_line_col(p, args, token.pos);
args[1] = line;
args[2] = column;
args[3] = low; args[3] = low;
args[4] = high; args[4] = high;
args[5] = len; args[5] = len;
+2 -6
View File
@@ -771,9 +771,7 @@ gb_internal lbValue lb_emit_union_cast(lbProcedure *p, lbValue value, Type *type
auto args = array_make<lbValue>(permanent_allocator(), arg_count); auto args = array_make<lbValue>(permanent_allocator(), arg_count);
args[0] = ok; args[0] = ok;
args[1] = lb_const_string(m, get_file_path_string(pos.file_id)); lb_set_file_line_col(p, array_slice(args, 1, args.count), pos);
args[2] = lb_const_int(m, t_i32, pos.line);
args[3] = lb_const_int(m, t_i32, pos.column);
if (!build_context.no_rtti) { if (!build_context.no_rtti) {
args[4] = lb_typeid(m, src_type); args[4] = lb_typeid(m, src_type);
@@ -847,9 +845,7 @@ gb_internal lbAddr lb_emit_any_cast_addr(lbProcedure *p, lbValue value, Type *ty
auto args = array_make<lbValue>(permanent_allocator(), arg_count); auto args = array_make<lbValue>(permanent_allocator(), arg_count);
args[0] = ok; args[0] = ok;
args[1] = lb_const_string(m, get_file_path_string(pos.file_id)); lb_set_file_line_col(p, array_slice(args, 1, args.count), pos);
args[2] = lb_const_int(m, t_i32, pos.line);
args[3] = lb_const_int(m, t_i32, pos.column);
if (!build_context.no_rtti) { if (!build_context.no_rtti) {
args[4] = any_typeid; args[4] = any_typeid;