Merge branch 'master' into new-sys-unix

This commit is contained in:
gingerBill
2023-10-31 12:16:25 +00:00
committed by GitHub
64 changed files with 739 additions and 101 deletions

2
.gitignore vendored
View File

@@ -24,6 +24,8 @@ bld/
![Cc]ore/[Ll]og/
tests/documentation/verify/
tests/documentation/all.odin-doc
tests/internal/test_map
tests/internal/test_rtti
# Visual Studio 2015 cache/options directory
.vs/
# Visual Studio Code options directory

View File

@@ -1,7 +1,7 @@
package crypto
when ODIN_OS != .Linux && ODIN_OS != .OpenBSD && ODIN_OS != .Windows {
_rand_bytes :: proc (dst: []byte) {
when ODIN_OS != .Linux && ODIN_OS != .OpenBSD && ODIN_OS != .Windows && ODIN_OS != .JS {
_rand_bytes :: proc(dst: []byte) {
unimplemented("crypto: rand_bytes not supported on this OS")
}
}

20
core/crypto/rand_js.odin Normal file
View File

@@ -0,0 +1,20 @@
package crypto
foreign import "odin_env"
foreign odin_env {
@(link_name = "rand_bytes")
env_rand_bytes :: proc "contextless" (buf: []byte) ---
}
_MAX_PER_CALL_BYTES :: 65536 // 64kiB
_rand_bytes :: proc(dst: []byte) {
dst := dst
for len(dst) > 0 {
to_read := min(len(dst), _MAX_PER_CALL_BYTES)
env_rand_bytes(dst[:to_read])
dst = dst[to_read:]
}
}

View File

@@ -0,0 +1,14 @@
package rand
foreign import "odin_env"
foreign odin_env {
@(link_name = "rand_bytes")
env_rand_bytes :: proc "contextless" (buf: []byte) ---
}
@(require_results)
_system_random :: proc() -> u64 {
buf: [8]u8
env_rand_bytes(buf[:])
return transmute(u64)buf
}

View File

@@ -63,8 +63,8 @@ read_at_least :: proc(fd: Handle, buf: []byte, min: int) -> (n: int, err: Errno)
if len(buf) < min {
return 0, -1
}
for n < min && err == 0 {
nn: int
nn := max(int)
for nn > 0 && n < min && err == 0 {
nn, err = read(fd, buf[n:])
n += nn
}

View File

@@ -159,9 +159,9 @@ join :: proc(elems: []string, allocator := context.allocator) -> string {
return ""
}
// ext returns the file name extension used by "path"
// The extension is the suffix beginning at the file fot in the last slash separated element of "path"
// The path is empty if there is no dot
// ext returns the file name extension used by "path".
// The extension is the suffix beginning at the dot character in the last slash separated element of "path".
// The path is empty if there is no dot character.
ext :: proc(path: string, new := false, allocator := context.allocator) -> string {
for i := len(path)-1; i >= 0 && !is_separator(path[i]); i -= 1 {
if path[i] == '.' {

View File

@@ -39,14 +39,6 @@ import TTF "vendor:sdl2/ttf"
import vk "vendor:vulkan"
// NOTE(flysand): Since conditional imports are disabled for now I'll have to just disable these
// when ODIN_OS == "darwin" {
// import NS "vendor:darwin/Foundation"
// import MTL "vendor:darwin/Metal"
// import MTK "vendor:darwin/MetalKit"
// import CA "vendor:darwin/QuartzCore"
// }
// NOTE(bill): only one can be checked at a time
import lua_5_4 "vendor:lua/5.4"
@@ -94,11 +86,6 @@ _ :: TTF
_ :: vk
// _ :: NS
// _ :: MTL
// _ :: MTK
// _ :: CA
_ :: lua_5_4
_ :: nvg

View File

@@ -0,0 +1,12 @@
//+build darwin
package all
import NS "vendor:darwin/Foundation"
import MTL "vendor:darwin/Metal"
import MTK "vendor:darwin/MetalKit"
import CA "vendor:darwin/QuartzCore"
_ :: NS
_ :: MTL
_ :: MTK
_ :: CA

View File

@@ -1388,8 +1388,10 @@ gb_internal void init_build_context(TargetMetrics *cross_target, Subtarget subta
bc->optimization_level = gb_clamp(bc->optimization_level, -1, 3);
// ENFORCE DYNAMIC MAP CALLS
bc->dynamic_map_calls = true;
if (bc->metrics.os != TargetOs_windows) {
// ENFORCE DYNAMIC MAP CALLS
bc->dynamic_map_calls = true;
}
bc->ODIN_VALGRIND_SUPPORT = false;
if (build_context.metrics.os != TargetOs_windows) {

View File

@@ -5170,7 +5170,7 @@ gb_internal bool check_builtin_procedure(CheckerContext *c, Operand *operand, As
Operand op = {};
check_expr(c, &op, ce->args[1]);
if (op.mode != Addressing_Constant && !is_type_integer(op.type)) {
if (op.mode != Addressing_Constant || !is_type_integer(op.type)) {
error(op.expr, "Expected a constant integer for the index of procedure parameter value");
return false;
}
@@ -5229,7 +5229,7 @@ gb_internal bool check_builtin_procedure(CheckerContext *c, Operand *operand, As
Operand op = {};
check_expr(c, &op, ce->args[1]);
if (op.mode != Addressing_Constant && !is_type_integer(op.type)) {
if (op.mode != Addressing_Constant || !is_type_integer(op.type)) {
error(op.expr, "Expected a constant integer for the index of procedure parameter value");
return false;
}
@@ -5307,7 +5307,7 @@ gb_internal bool check_builtin_procedure(CheckerContext *c, Operand *operand, As
} else {
Operand op = {};
check_expr(c, &op, ce->args[1]);
if (op.mode != Addressing_Constant && !is_type_integer(op.type)) {
if (op.mode != Addressing_Constant || !is_type_integer(op.type)) {
error(op.expr, "Expected a constant integer for the index of record parameter value");
return false;
}

View File

@@ -506,9 +506,9 @@ gb_internal lbValue lb_map_get_proc_for_type(lbModule *m, Type *type) {
LLVMSetLinkage(p->value, LLVMInternalLinkage);
lb_add_attribute_to_proc(m, p->value, "nounwind");
// if (build_context.ODIN_DEBUG) {
if (build_context.ODIN_DEBUG) {
lb_add_attribute_to_proc(m, p->value, "noinline");
// }
}
LLVMValueRef x = LLVMGetParam(p->value, 0);
LLVMValueRef y = LLVMGetParam(p->value, 1);
@@ -692,7 +692,7 @@ gb_internal lbValue lb_map_set_proc_for_type(lbModule *m, Type *type) {
}
lbValue map_ptr = {LLVMGetParam(p->value, 0), t_rawptr};
lbValue hash = {LLVMGetParam(p->value, 1), t_uintptr};
lbValue hash_param = {LLVMGetParam(p->value, 1), t_uintptr};
lbValue key_ptr = {LLVMGetParam(p->value, 2), t_rawptr};
lbValue value_ptr = {LLVMGetParam(p->value, 3), t_rawptr};
lbValue location_ptr = {LLVMGetParam(p->value, 4), t_source_code_location_ptr};
@@ -700,6 +700,12 @@ gb_internal lbValue lb_map_set_proc_for_type(lbModule *m, Type *type) {
map_ptr = lb_emit_conv(p, map_ptr, alloc_type_pointer(type));
key_ptr = lb_emit_conv(p, key_ptr, alloc_type_pointer(type->Map.key));
LLVM_SET_VALUE_NAME(map_ptr.value, "map_ptr");
LLVM_SET_VALUE_NAME(hash_param.value, "hash_param");
LLVM_SET_VALUE_NAME(key_ptr.value, "key_ptr");
LLVM_SET_VALUE_NAME(value_ptr.value, "value_ptr");
LLVM_SET_VALUE_NAME(location_ptr.value, "location");
lb_add_proc_attribute_at_index(p, 1+0, "nonnull");
lb_add_proc_attribute_at_index(p, 1+0, "noalias");
@@ -719,6 +725,10 @@ gb_internal lbValue lb_map_set_proc_for_type(lbModule *m, Type *type) {
lb_add_proc_attribute_at_index(p, 1+4, "noalias");
lb_add_proc_attribute_at_index(p, 1+4, "readonly");
lbAddr hash_addr = lb_add_local_generated(p, t_uintptr, false);
lb_addr_store(p, hash_addr, hash_param);
LLVM_SET_VALUE_NAME(hash_addr.addr.value, "hash");
////
lbValue found_ptr = {};
{
@@ -726,17 +736,19 @@ gb_internal lbValue lb_map_set_proc_for_type(lbModule *m, Type *type) {
auto args = array_make<lbValue>(temporary_allocator(), 3);
args[0] = lb_emit_conv(p, map_ptr, t_rawptr);
args[1] = hash;
args[1] = lb_addr_load(p, hash_addr);
args[2] = key_ptr;
found_ptr = lb_emit_call(p, map_get_proc, args);
}
LLVM_SET_VALUE_NAME(found_ptr.value, "found_ptr");
lbBlock *found_block = lb_create_block(p, "found");
lbBlock *check_grow_block = lb_create_block(p, "check-grow");
lbBlock *grow_fail_block = lb_create_block(p, "grow-fail");
lbBlock *insert_block = lb_create_block(p, "insert");
lbBlock *check_has_grown_block = lb_create_block(p, "check-has-grown");
lbBlock *rehash_block = lb_create_block(p, "rehash");
lb_emit_if(p, lb_emit_comp_against_nil(p, Token_NotEq, found_ptr), found_block, check_grow_block);
@@ -749,6 +761,7 @@ gb_internal lbValue lb_map_set_proc_for_type(lbModule *m, Type *type) {
lbValue map_info = lb_gen_map_info_ptr(p->module, type);
LLVM_SET_VALUE_NAME(map_info.value, "map_info");
{
auto args = array_make<lbValue>(temporary_allocator(), 3);
@@ -758,16 +771,23 @@ gb_internal lbValue lb_map_set_proc_for_type(lbModule *m, Type *type) {
lbValue grow_err_and_has_grown = lb_emit_runtime_call(p, "__dynamic_map_check_grow", args);
lbValue grow_err = lb_emit_struct_ev(p, grow_err_and_has_grown, 0);
lbValue has_grown = lb_emit_struct_ev(p, grow_err_and_has_grown, 1);
LLVM_SET_VALUE_NAME(grow_err.value, "grow_err");
LLVM_SET_VALUE_NAME(has_grown.value, "has_grown");
lb_emit_if(p, lb_emit_comp_against_nil(p, Token_NotEq, grow_err), grow_fail_block, insert_block);
lb_emit_if(p, lb_emit_comp_against_nil(p, Token_NotEq, grow_err), grow_fail_block, check_has_grown_block);
lb_start_block(p, grow_fail_block);
LLVMBuildRet(p->builder, LLVMConstNull(lb_type(m, t_rawptr)));
lb_emit_if(p, has_grown, grow_fail_block, rehash_block);
lb_start_block(p, check_has_grown_block);
lb_emit_if(p, has_grown, rehash_block, insert_block);
lb_start_block(p, rehash_block);
lbValue key = lb_emit_load(p, key_ptr);
hash = lb_gen_map_key_hash(p, map_ptr, key, nullptr);
lbValue new_hash = lb_gen_map_key_hash(p, map_ptr, key, nullptr);
LLVM_SET_VALUE_NAME(new_hash.value, "new_hash");
lb_addr_store(p, hash_addr, new_hash);
lb_emit_jump(p, insert_block);
}
lb_start_block(p, insert_block);
@@ -775,7 +795,7 @@ gb_internal lbValue lb_map_set_proc_for_type(lbModule *m, Type *type) {
auto args = array_make<lbValue>(temporary_allocator(), 5);
args[0] = lb_emit_conv(p, map_ptr, t_rawptr);
args[1] = map_info;
args[2] = hash;
args[2] = lb_addr_load(p, hash_addr);
args[3] = lb_emit_conv(p, key_ptr, t_uintptr);
args[4] = lb_emit_conv(p, value_ptr, t_uintptr);
@@ -1471,13 +1491,390 @@ gb_internal WORKER_TASK_PROC(lb_llvm_module_pass_worker_proc) {
array_add(&passes, "function(annotation-remarks)");
break;
case 1:
array_add(&passes, "default<Os>");
// default<Os>
// Passes removed: coro, openmp, sroa
array_add(&passes, u8R"(
annotation2metadata,
forceattrs,
inferattrs,
function<eager-inv>(
lower-expect,
simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;no-switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-sink-common-insts;speculate-blocks;simplify-cond-branch>,
early-cse<>
),
ipsccp,
called-value-propagation,
globalopt,
function<eager-inv>(
mem2reg,
instcombine<max-iterations=1000;no-use-loop-info>,
simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-sink-common-insts;speculate-blocks;simplify-cond-branch>),
require<globals-aa>,
function(
invalidate<aa>
),
require<profile-summary>,
cgscc(
devirt<4>(
inline<only-mandatory>,
inline,
function-attrs<skip-non-recursive>,
function<eager-inv;no-rerun>(
early-cse<memssa>,
speculative-execution,
jump-threading,
correlated-propagation,
simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-sink-common-insts;speculate-blocks;simplify-cond-branch>,
instcombine<max-iterations=1000;no-use-loop-info>,
aggressive-instcombine,
constraint-elimination,
tailcallelim,
simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-sink-common-insts;speculate-blocks;simplify-cond-branch>,
reassociate,
loop-mssa(
loop-instsimplify,
loop-simplifycfg,
licm<no-allowspeculation>,
loop-rotate<header-duplication;no-prepare-for-lto>,
licm<allowspeculation>,
simple-loop-unswitch<no-nontrivial;trivial>
),
simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-sink-common-insts;speculate-blocks;simplify-cond-branch>,
instcombine<max-iterations=1000;no-use-loop-info>,
loop(
loop-idiom,
indvars,
loop-deletion,
loop-unroll-full
),
vector-combine,
mldst-motion<no-split-footer-bb>,
gvn<>,
sccp,
bdce,
instcombine<max-iterations=1000;no-use-loop-info>,
jump-threading,
correlated-propagation,
adce,
memcpyopt,
dse,
move-auto-init,
loop-mssa(
licm<allowspeculation>
),
simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;hoist-common-insts;sink-common-insts;speculate-blocks;simplify-cond-branch>,
instcombine<max-iterations=1000;no-use-loop-info>
),
function-attrs,
function(
require<should-not-run-function-passes>
)
)
),
deadargelim,
globalopt,
globaldce,
elim-avail-extern,
rpo-function-attrs,
recompute-globalsaa,
function<eager-inv>(
float2int,
lower-constant-intrinsics,
loop(
loop-rotate<header-duplication;no-prepare-for-lto>,
loop-deletion
),
loop-distribute,
inject-tli-mappings,
loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>,
loop-load-elim,
instcombine<max-iterations=1000;no-use-loop-info>,
simplifycfg<bonus-inst-threshold=1;forward-switch-cond;switch-range-to-icmp;switch-to-lookup;no-keep-loops;hoist-common-insts;sink-common-insts;speculate-blocks;simplify-cond-branch>,
slp-vectorizer,
vector-combine,
instcombine<max-iterations=1000;no-use-loop-info>,
loop-unroll<O2>,
transform-warning,
instcombine<max-iterations=1000;no-use-loop-info>,
loop-mssa(
licm<allowspeculation>
),
alignment-from-assumptions,
loop-sink,
instsimplify,
div-rem-pairs,
tailcallelim,
simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-sink-common-insts;speculate-blocks;simplify-cond-branch>
),
globaldce,
constmerge,
cg-profile,
rel-lookup-table-converter,
function(
annotation-remarks
),
verify
)");
break;
// default<O2>
// Passes removed: coro, openmp, sroa
case 2:
array_add(&passes, "default<O2>");
array_add(&passes, u8R"(
annotation2metadata,
forceattrs,
inferattrs,
function<eager-inv>(
lower-expect,
simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;no-switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-sink-common-insts;speculate-blocks;simplify-cond-branch>,
early-cse<>
),
ipsccp,
called-value-propagation,
globalopt,
function<eager-inv>(
mem2reg,
instcombine<max-iterations=1000;no-use-loop-info>,
simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-sink-common-insts;speculate-blocks;simplify-cond-branch>
),
require<globals-aa>,
function(
invalidate<aa>
),
require<profile-summary>,
cgscc(
devirt<4>(
inline<only-mandatory>,
inline,
function-attrs<skip-non-recursive>,
function<eager-inv;no-rerun>(
early-cse<memssa>,
speculative-execution,
jump-threading,
correlated-propagation,
simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-sink-common-insts;speculate-blocks;simplify-cond-branch>,
instcombine<max-iterations=1000;no-use-loop-info>,
aggressive-instcombine,
constraint-elimination,
libcalls-shrinkwrap,
tailcallelim,
simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-sink-common-insts;speculate-blocks;simplify-cond-branch>,
reassociate,
loop-mssa(
loop-instsimplify,
loop-simplifycfg,
licm<no-allowspeculation>,
loop-rotate<header-duplication;no-prepare-for-lto>,
licm<allowspeculation>,
simple-loop-unswitch<no-nontrivial;trivial>
),
simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-sink-common-insts;speculate-blocks;simplify-cond-branch>,
instcombine<max-iterations=1000;no-use-loop-info>,
loop(
loop-idiom,
indvars,
loop-deletion,
loop-unroll-full
),
vector-combine,
mldst-motion<no-split-footer-bb>,
gvn<>,
sccp,
bdce,
instcombine<max-iterations=1000;no-use-loop-info>,
jump-threading,
correlated-propagation,
adce,
memcpyopt,
dse,
move-auto-init,
loop-mssa(
licm<allowspeculation>
),
simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;hoist-common-insts;sink-common-insts;speculate-blocks;simplify-cond-branch>,
instcombine<max-iterations=1000;no-use-loop-info>
),
function-attrs,
function(
require<should-not-run-function-passes>
)
)
),
deadargelim,
globalopt,
globaldce,
elim-avail-extern,
rpo-function-attrs,
recompute-globalsaa,
function<eager-inv>(
float2int,
lower-constant-intrinsics,
loop(
loop-rotate<header-duplication;no-prepare-for-lto>,
loop-deletion
),
loop-distribute,
inject-tli-mappings,
loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>,
loop-load-elim,
instcombine<max-iterations=1000;no-use-loop-info>,
simplifycfg<bonus-inst-threshold=1;forward-switch-cond;switch-range-to-icmp;switch-to-lookup;no-keep-loops;hoist-common-insts;sink-common-insts;speculate-blocks;simplify-cond-branch>,
slp-vectorizer,
vector-combine,
instcombine<max-iterations=1000;no-use-loop-info>,
loop-unroll<O2>,
transform-warning,
instcombine<max-iterations=1000;no-use-loop-info>,
loop-mssa(
licm<allowspeculation>
),
alignment-from-assumptions,
loop-sink,
instsimplify,
div-rem-pairs,
tailcallelim,
simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-sink-common-insts;speculate-blocks;simplify-cond-branch>
),
globaldce,
constmerge,
cg-profile,
rel-lookup-table-converter,
function(
annotation-remarks
),
verify
)");
break;
case 3:
array_add(&passes, "default<O3>");
// default<O3>
// Passes removed: coro, openmp, sroa
array_add(&passes, u8R"(
annotation2metadata,
forceattrs,
inferattrs,
function<eager-inv>(
lower-expect,
simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;no-switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-sink-common-insts;speculate-blocks;simplify-cond-branch>,
early-cse<>,
callsite-splitting
),
ipsccp,
called-value-propagation,
globalopt,
function<eager-inv>(
mem2reg,
instcombine<max-iterations=1000;no-use-loop-info>,
simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-sink-common-insts;speculate-blocks;simplify-cond-branch>
),
require<globals-aa>,
function(
invalidate<aa>
),
require<profile-summary>,
cgscc(
devirt<4>(
inline<only-mandatory>,
inline,
function-attrs<skip-non-recursive>,
argpromotion,
function<eager-inv;no-rerun>(
early-cse<memssa>,
speculative-execution,
jump-threading,
correlated-propagation,
simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-sink-common-insts;speculate-blocks;simplify-cond-branch>,
instcombine<max-iterations=1000;no-use-loop-info>,
aggressive-instcombine,
constraint-elimination,
libcalls-shrinkwrap,
tailcallelim,
simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-sink-common-insts;speculate-blocks;simplify-cond-branch>,
reassociate,
loop-mssa(
loop-instsimplify,
loop-simplifycfg,
licm<no-allowspeculation>,
loop-rotate<header-duplication;no-prepare-for-lto>,
licm<allowspeculation>,
simple-loop-unswitch<nontrivial;trivial>
),
simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-sink-common-insts;speculate-blocks;simplify-cond-branch>,
instcombine<max-iterations=1000;no-use-loop-info>,
loop(
loop-idiom,
indvars,
loop-deletion,
loop-unroll-full
),
vector-combine,
mldst-motion<no-split-footer-bb>,
gvn<>,
sccp,
bdce,
instcombine<max-iterations=1000;no-use-loop-info>,
jump-threading,
correlated-propagation,
adce,
memcpyopt,
dse,
move-auto-init,
loop-mssa(
licm<allowspeculation>
),
simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;hoist-common-insts;sink-common-insts;speculate-blocks;simplify-cond-branch>,
instcombine<max-iterations=1000;no-use-loop-info>
),
function-attrs,
function(
require<should-not-run-function-passes>
),
)
),
deadargelim,
globalopt,
globaldce,
elim-avail-extern,
rpo-function-attrs,
recompute-globalsaa,
function<eager-inv>(
float2int,
lower-constant-intrinsics,
chr,
loop(
loop-rotate<header-duplication;no-prepare-for-lto>,
loop-deletion
),
loop-distribute,
inject-tli-mappings,
loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>,
loop-load-elim,
instcombine<max-iterations=1000;no-use-loop-info>,
simplifycfg<bonus-inst-threshold=1;forward-switch-cond;switch-range-to-icmp;switch-to-lookup;no-keep-loops;hoist-common-insts;sink-common-insts;speculate-blocks;simplify-cond-branch>,
slp-vectorizer,
vector-combine,
instcombine<max-iterations=1000;no-use-loop-info>,
loop-unroll<O3>,
transform-warning,
instcombine<max-iterations=1000;no-use-loop-info>,
loop-mssa(
licm<allowspeculation>
),
alignment-from-assumptions,
loop-sink,
instsimplify,
div-rem-pairs,
tailcallelim,
simplifycfg<bonus-inst-threshold=1;no-forward-switch-cond;switch-range-to-icmp;no-switch-to-lookup;keep-loops;no-hoist-common-insts;no-sink-common-insts;speculate-blocks;simplify-cond-branch>
),
globaldce,
constmerge,
cg-profile,
rel-lookup-table-converter,
function(
annotation-remarks
),
verify
)");
break;
}
@@ -1508,6 +1905,19 @@ gb_internal WORKER_TASK_PROC(lb_llvm_module_pass_worker_proc) {
}
passes_str = gb_string_appendc(passes_str, passes[i]);
}
for (isize i = 0; i < gb_string_length(passes_str); /**/) {
switch (passes_str[i]) {
case ' ':
case '\n':
case '\t':
gb_memmove(&passes_str[i], &passes_str[i+1], gb_string_length(passes_str)-i);
GB_STRING_HEADER(passes_str)->length -= 1;
continue;
default:
i += 1;
break;
}
}
LLVMErrorRef llvm_err = LLVMRunPasses(wd->m->mod, passes_str, wd->target_machine, pb_options);
@@ -2247,7 +2657,9 @@ gb_internal bool lb_generate_code(lbGenerator *gen) {
lb_add_entity(m, lb_global_type_info_data_entity, value);
if (LB_USE_GIANT_PACKED_STRUCT) {
lb_make_global_private_const(g);
LLVMSetLinkage(g, LLVMPrivateLinkage);
LLVMSetUnnamedAddress(g, LLVMGlobalUnnamedAddr);
LLVMSetGlobalConstant(g, /*true*/false);
}
}
{ // Type info member buffer

View File

@@ -94,6 +94,9 @@ gb_internal LLVMValueRef llvm_const_cast(LLVMValueRef val, LLVMTypeRef dst) {
LLVMTypeKind kind = LLVMGetTypeKind(dst);
switch (kind) {
case LLVMPointerTypeKind:
if (LB_USE_NEW_PASS_SYSTEM) {
return val;
}
return LLVMConstPointerCast(val, dst);
case LLVMStructTypeKind:
// GB_PANIC("%s -> %s", LLVMPrintValueToString(val), LLVMPrintTypeToString(dst));

View File

@@ -962,8 +962,12 @@ gb_internal bool lb_is_type_proc_recursive(Type *t) {
gb_internal void lb_emit_store(lbProcedure *p, lbValue ptr, lbValue value) {
GB_ASSERT(value.value != nullptr);
Type *a = type_deref(ptr.type);
if (LLVMIsUndef(value.value)) {
return;
}
Type *a = type_deref(ptr.type);
if (LLVMIsNull(value.value)) {
LLVMTypeRef src_t = llvm_addr_type(p->module, ptr);
if (is_type_proc(a)) {

View File

@@ -322,7 +322,11 @@ gb_internal void lb_run_remove_dead_instruction_pass(lbProcedure *p) {
// NOTE(bill): Explicit instructions are set here because some instructions could have side effects
switch (LLVMGetInstructionOpcode(curr_instr)) {
// case LLVMAlloca:
case LLVMLoad:
if (LLVMGetVolatile(curr_instr)) {
break;
}
/*fallthrough*/
case LLVMFNeg:
case LLVMAdd:
case LLVMFAdd:
@@ -342,7 +346,6 @@ gb_internal void lb_run_remove_dead_instruction_pass(lbProcedure *p) {
case LLVMAnd:
case LLVMOr:
case LLVMXor:
case LLVMLoad:
case LLVMGetElementPtr:
case LLVMTrunc:
case LLVMZExt:

View File

@@ -2769,7 +2769,7 @@ gb_internal lbValue lb_build_builtin_proc(lbProcedure *p, Ast *expr, TypeAndValu
{
GB_ASSERT(arg_count <= 7);
char asm_string_default[] = "int $0x80";
char asm_string_default[] = "int $$0x80";
char *asm_string = asm_string_default;
gbString constraints = gb_string_make(heap_allocator(), "={eax}");

View File

@@ -175,7 +175,8 @@ gb_internal lbValue lb_type_info_member_tags_offset(lbModule *m, isize count, i6
return offset;
}
enum {LB_USE_GIANT_PACKED_STRUCT = LB_USE_NEW_PASS_SYSTEM};
// enum {LB_USE_GIANT_PACKED_STRUCT = LB_USE_NEW_PASS_SYSTEM};
enum {LB_USE_GIANT_PACKED_STRUCT = 0};
gb_internal LLVMTypeRef lb_setup_type_info_data_internal_type(lbModule *m, isize max_type_info_count) {
if (!LB_USE_GIANT_PACKED_STRUCT) {
@@ -269,7 +270,7 @@ gb_internal LLVMTypeRef lb_setup_type_info_data_internal_type(lbModule *m, isize
return LLVMStructType(element_types, cast(unsigned)max_type_info_count, true);
}
gb_internal void lb_setup_type_info_data_giant_packed_struct(lbModule *m, i64 global_type_info_data_entity_count) { // NOTE(bill): Setup type_info data
gb_internal void lb_setup_type_info_data_giant_packed_struct(lbModule *m, i64 global_type_info_data_entity_count, lbProcedure *p) { // NOTE(bill): Setup type_info data
CheckerInfo *info = m->info;
// Useful types
@@ -286,7 +287,6 @@ gb_internal void lb_setup_type_info_data_giant_packed_struct(lbModule *m, i64 gl
defer (gb_free(heap_allocator(), entries_handled.data));
entries_handled[0] = true;
LLVMValueRef giant_struct = lb_global_type_info_data_ptr(m).value;
LLVMTypeRef giant_struct_type = LLVMGlobalGetValueType(giant_struct);
GB_ASSERT(LLVMGetTypeKind(giant_struct_type) == LLVMStructTypeKind);
@@ -320,6 +320,30 @@ gb_internal void lb_setup_type_info_data_giant_packed_struct(lbModule *m, i64 gl
type_info_allocate_values(lb_global_type_info_member_usings);
type_info_allocate_values(lb_global_type_info_member_tags);
i64 const type_info_struct_size = type_size_of(t_type_info);
LLVMTypeRef llvm_u8 = lb_type(m, t_u8);
LLVMTypeRef llvm_int = lb_type(m, t_int);
// LLVMTypeRef llvm_type_info_ptr = lb_type(m, t_type_info_ptr);
auto const get_type_info_ptr = [&](lbModule *m, Type *type) -> LLVMValueRef {
type = default_type(type);
isize index = lb_type_info_index(m->info, type);
GB_ASSERT(index >= 0);
u64 offset = cast(u64)(index * type_info_struct_size);
LLVMValueRef indices[1] = {
LLVMConstInt(llvm_int, offset, false)
};
// LLVMValueRef ptr = LLVMConstInBoundsGEP2(llvm_u8, giant_struct, indices, gb_count_of(indices));
LLVMValueRef ptr = LLVMConstGEP2(llvm_u8, giant_struct, indices, gb_count_of(indices));
return ptr;
// return LLVMConstPointerCast(ptr, llvm_type_info_ptr);
};
for_array(type_info_type_index, info->type_info_types) {
Type *t = info->type_info_types[type_info_type_index];
if (t == nullptr || t == t_invalid) {
@@ -394,7 +418,7 @@ gb_internal void lb_setup_type_info_data_giant_packed_struct(lbModule *m, i64 gl
LLVMValueRef vals[4] = {
lb_const_string(m, t->Named.type_name->token.string).value,
lb_type_info(m, t->Named.base).value,
get_type_info_ptr(m, t->Named.base),
pkg_name,
loc.value
};
@@ -541,10 +565,8 @@ gb_internal void lb_setup_type_info_data_giant_packed_struct(lbModule *m, i64 gl
case Type_Pointer: {
tag_type = t_type_info_pointer;
lbValue gep = lb_type_info(m, t->Pointer.elem);
LLVMValueRef vals[1] = {
gep.value,
get_type_info_ptr(m, t->Pointer.elem),
};
@@ -553,10 +575,9 @@ gb_internal void lb_setup_type_info_data_giant_packed_struct(lbModule *m, i64 gl
}
case Type_MultiPointer: {
tag_type = t_type_info_multi_pointer;
lbValue gep = lb_type_info(m, t->MultiPointer.elem);
LLVMValueRef vals[1] = {
gep.value,
get_type_info_ptr(m, t->MultiPointer.elem),
};
variant_value = llvm_const_named_struct(m, tag_type, vals, gb_count_of(vals));
@@ -564,10 +585,9 @@ gb_internal void lb_setup_type_info_data_giant_packed_struct(lbModule *m, i64 gl
}
case Type_SoaPointer: {
tag_type = t_type_info_soa_pointer;
lbValue gep = lb_type_info(m, t->SoaPointer.elem);
LLVMValueRef vals[1] = {
gep.value,
get_type_info_ptr(m, t->SoaPointer.elem),
};
variant_value = llvm_const_named_struct(m, tag_type, vals, gb_count_of(vals));
@@ -578,7 +598,7 @@ gb_internal void lb_setup_type_info_data_giant_packed_struct(lbModule *m, i64 gl
i64 ez = type_size_of(t->Array.elem);
LLVMValueRef vals[3] = {
lb_type_info(m, t->Array.elem).value,
get_type_info_ptr(m, t->Array.elem),
lb_const_int(m, t_int, ez).value,
lb_const_int(m, t_int, t->Array.count).value,
};
@@ -590,8 +610,8 @@ gb_internal void lb_setup_type_info_data_giant_packed_struct(lbModule *m, i64 gl
tag_type = t_type_info_enumerated_array;
LLVMValueRef vals[7] = {
lb_type_info(m, t->EnumeratedArray.elem).value,
lb_type_info(m, t->EnumeratedArray.index).value,
get_type_info_ptr(m, t->EnumeratedArray.elem),
get_type_info_ptr(m, t->EnumeratedArray.index),
lb_const_int(m, t_int, type_size_of(t->EnumeratedArray.elem)).value,
lb_const_int(m, t_int, t->EnumeratedArray.count).value,
@@ -609,7 +629,7 @@ gb_internal void lb_setup_type_info_data_giant_packed_struct(lbModule *m, i64 gl
tag_type = t_type_info_dynamic_array;
LLVMValueRef vals[2] = {
lb_type_info(m, t->DynamicArray.elem).value,
get_type_info_ptr(m, t->DynamicArray.elem),
lb_const_int(m, t_int, type_size_of(t->DynamicArray.elem)).value,
};
@@ -620,7 +640,7 @@ gb_internal void lb_setup_type_info_data_giant_packed_struct(lbModule *m, i64 gl
tag_type = t_type_info_slice;
LLVMValueRef vals[2] = {
lb_type_info(m, t->Slice.elem).value,
get_type_info_ptr(m, t->Slice.elem),
lb_const_int(m, t_int, type_size_of(t->Slice.elem)).value,
};
@@ -633,10 +653,10 @@ gb_internal void lb_setup_type_info_data_giant_packed_struct(lbModule *m, i64 gl
LLVMValueRef params = LLVMConstNull(lb_type(m, t_type_info_ptr));
LLVMValueRef results = LLVMConstNull(lb_type(m, t_type_info_ptr));
if (t->Proc.params != nullptr) {
params = lb_type_info(m, t->Proc.params).value;
params = get_type_info_ptr(m, t->Proc.params);
}
if (t->Proc.results != nullptr) {
results = lb_type_info(m, t->Proc.results).value;
results = get_type_info_ptr(m, t->Proc.results);
}
LLVMValueRef vals[4] = {
@@ -663,7 +683,7 @@ gb_internal void lb_setup_type_info_data_giant_packed_struct(lbModule *m, i64 gl
lbValue index = lb_const_int(m, t_int, i);
lbValue type_info = lb_const_ptr_offset(m, memory_types, index);
lb_global_type_info_member_types_values[type_offset+i] = lb_type_info(m, f->type).value;
lb_global_type_info_member_types_values[type_offset+i] = get_type_info_ptr(m, f->type);
if (f->token.string.len > 0) {
lb_global_type_info_member_names_values[name_offset+i] = lb_const_string(m, f->token.string).value;
}
@@ -692,7 +712,7 @@ gb_internal void lb_setup_type_info_data_giant_packed_struct(lbModule *m, i64 gl
LLVMValueRef vals[3] = {};
vals[0] = lb_type_info(m, t->Enum.base_type).value;
vals[0] = get_type_info_ptr(m, t->Enum.base_type);
if (t->Enum.fields.count > 0) {
auto fields = t->Enum.fields;
lbValue name_array = lb_generate_global_array(m, t_string, fields.count,
@@ -744,9 +764,7 @@ gb_internal void lb_setup_type_info_data_giant_packed_struct(lbModule *m, i64 gl
for (isize variant_index = 0; variant_index < variant_count; variant_index++) {
Type *vt = t->Union.variants[variant_index];
lbValue tip = lb_type_info(m, vt);
lb_global_type_info_member_types_values[variant_offset+variant_index] = lb_type_info(m, vt).value;
lb_global_type_info_member_types_values[variant_offset+variant_index] = get_type_info_ptr(m, vt);
}
lbValue count = lb_const_int(m, t_int, variant_count);
@@ -756,7 +774,7 @@ gb_internal void lb_setup_type_info_data_giant_packed_struct(lbModule *m, i64 gl
if (tag_size > 0) {
i64 tag_offset = align_formula(t->Union.variant_block_size, tag_size);
vals[1] = lb_const_int(m, t_uintptr, tag_offset).value;
vals[2] = lb_type_info(m, union_tag_type(t)).value;
vals[2] = get_type_info_ptr(m, union_tag_type(t));
} else {
vals[1] = lb_const_int(m, t_uintptr, 0).value;
vals[2] = LLVMConstNull(lb_type(m, t_type_info_ptr));
@@ -805,11 +823,11 @@ gb_internal void lb_setup_type_info_data_giant_packed_struct(lbModule *m, i64 gl
Type *kind_type = get_struct_field_type(tag_type, 10);
lbValue soa_kind = lb_const_value(m, kind_type, exact_value_i64(t->Struct.soa_kind));
lbValue soa_type = lb_type_info(m, t->Struct.soa_elem);
LLVMValueRef soa_type = get_type_info_ptr(m, t->Struct.soa_elem);
lbValue soa_len = lb_const_int(m, t_int, t->Struct.soa_count);
vals[10] = soa_kind.value;
vals[11] = soa_type.value;
vals[11] = soa_type;
vals[12] = soa_len.value;
}
}
@@ -831,7 +849,6 @@ gb_internal void lb_setup_type_info_data_giant_packed_struct(lbModule *m, i64 gl
type_set_offsets(t); // NOTE(bill): Just incase the offsets have not been set yet
for (isize source_index = 0; source_index < count; source_index++) {
Entity *f = t->Struct.fields[source_index];
lbValue tip = lb_type_info(m, f->type);
i64 foffset = 0;
if (!t->Struct.is_raw_union) {
GB_ASSERT(t->Struct.offsets != nullptr);
@@ -841,7 +858,7 @@ gb_internal void lb_setup_type_info_data_giant_packed_struct(lbModule *m, i64 gl
GB_ASSERT(f->kind == Entity_Variable && f->flags & EntityFlag_Field);
lb_global_type_info_member_types_values[types_offset+source_index] = lb_type_info(m, f->type).value;
lb_global_type_info_member_types_values[types_offset+source_index] = get_type_info_ptr(m, f->type);
lb_global_type_info_member_offsets_values[offsets_offset+source_index] = lb_const_int(m, t_uintptr, foffset).value;
lb_global_type_info_member_usings_values[usings_offset+source_index] = lb_const_bool(m, t_bool, (f->flags&EntityFlag_Using) != 0).value;
@@ -880,8 +897,8 @@ gb_internal void lb_setup_type_info_data_giant_packed_struct(lbModule *m, i64 gl
init_map_internal_types(t);
LLVMValueRef vals[3] = {
lb_type_info(m, t->Map.key).value,
lb_type_info(m, t->Map.value).value,
get_type_info_ptr(m, t->Map.key),
get_type_info_ptr(m, t->Map.value),
lb_gen_map_info_ptr(m, t).value
};
@@ -897,13 +914,13 @@ gb_internal void lb_setup_type_info_data_giant_packed_struct(lbModule *m, i64 gl
LLVMValueRef vals[4] = {
lb_type_info(m, t->BitSet.elem).value,
get_type_info_ptr(m, t->BitSet.elem),
LLVMConstNull(lb_type(m, t_type_info_ptr)),
lb_const_int(m, t_i64, t->BitSet.lower).value,
lb_const_int(m, t_i64, t->BitSet.upper).value,
};
if (t->BitSet.underlying != nullptr) {
vals[1] = lb_type_info(m, t->BitSet.underlying).value;
vals[1] = get_type_info_ptr(m, t->BitSet.underlying);
}
variant_value = llvm_const_named_struct(m, tag_type, vals, gb_count_of(vals));
@@ -916,7 +933,7 @@ gb_internal void lb_setup_type_info_data_giant_packed_struct(lbModule *m, i64 gl
LLVMValueRef vals[3] = {};
vals[0] = lb_type_info(m, t->SimdVector.elem).value;
vals[0] = get_type_info_ptr(m, t->SimdVector.elem);
vals[1] = lb_const_int(m, t_int, type_size_of(t->SimdVector.elem)).value;
vals[2] = lb_const_int(m, t_int, t->SimdVector.count).value;
@@ -928,8 +945,8 @@ gb_internal void lb_setup_type_info_data_giant_packed_struct(lbModule *m, i64 gl
{
tag_type = t_type_info_relative_pointer;
LLVMValueRef vals[2] = {
lb_type_info(m, t->RelativePointer.pointer_type).value,
lb_type_info(m, t->RelativePointer.base_integer).value,
get_type_info_ptr(m, t->RelativePointer.pointer_type),
get_type_info_ptr(m, t->RelativePointer.base_integer),
};
variant_value = llvm_const_named_struct(m, tag_type, vals, gb_count_of(vals));
@@ -940,8 +957,8 @@ gb_internal void lb_setup_type_info_data_giant_packed_struct(lbModule *m, i64 gl
{
tag_type = t_type_info_relative_multi_pointer;
LLVMValueRef vals[2] = {
lb_type_info(m, t->RelativeMultiPointer.pointer_type).value,
lb_type_info(m, t->RelativeMultiPointer.base_integer).value,
get_type_info_ptr(m, t->RelativeMultiPointer.pointer_type),
get_type_info_ptr(m, t->RelativeMultiPointer.base_integer),
};
variant_value = llvm_const_named_struct(m, tag_type, vals, gb_count_of(vals));
@@ -954,7 +971,7 @@ gb_internal void lb_setup_type_info_data_giant_packed_struct(lbModule *m, i64 gl
i64 ez = type_size_of(t->Matrix.elem);
LLVMValueRef vals[5] = {
lb_type_info(m, t->Matrix.elem).value,
get_type_info_ptr(m, t->Matrix.elem),
lb_const_int(m, t_int, ez).value,
lb_const_int(m, t_int, matrix_type_stride_in_elems(t)).value,
lb_const_int(m, t_int, t->Matrix.row_count).value,
@@ -1037,7 +1054,7 @@ gb_internal void lb_setup_type_info_data(lbProcedure *p) { // NOTE(bill): Setup
}
if (LB_USE_GIANT_PACKED_STRUCT) {
lb_setup_type_info_data_giant_packed_struct(m, global_type_info_data_entity_count);
lb_setup_type_info_data_giant_packed_struct(m, global_type_info_data_entity_count, p);
return;
}

View File

@@ -1032,22 +1032,22 @@ gb_internal void cg_build_assignment(cgProcedure *p, Array<cgAddr> const &lvals,
continue;
}
Type *type = cg_addr_type(lval);
Type *type = cg_addr_type(lval);
if (!cg_addr_is_empty(lval)) {
GB_ASSERT_MSG(are_types_identical(init.type, type), "%s = %s", type_to_string(init.type), type_to_string(type));
}
if (init.kind == cgValue_Addr &&
!cg_addr_is_empty(lval)) {
// NOTE(bill): This is needed for certain constructs such as this:
// a, b = b, a
// NOTE(bill): This is a bodge and not necessarily a good way of doing things whatsoever
TB_CharUnits size = cast(TB_CharUnits)type_size_of(type);
TB_CharUnits align = cast(TB_CharUnits)type_align_of(type);
TB_Node *copy = tb_inst_local(p->func, size, align);
tb_inst_memcpy(p->func, copy, init.node, tb_inst_uint(p->func, TB_TYPE_INT, size), align);
// use the copy instead
init.node = copy;
// NOTE(bill): This is needed for certain constructs such as this:
// a, b = b, a
// NOTE(bill): This is a bodge and not necessarily a good way of doing things whatsoever
TB_CharUnits size = cast(TB_CharUnits)type_size_of(type);
TB_CharUnits align = cast(TB_CharUnits)type_align_of(type);
TB_Node *copy = tb_inst_local(p->func, size, align);
tb_inst_memcpy(p->func, copy, init.node, tb_inst_uint(p->func, TB_TYPE_INT, size), align);
// use the copy instead
init.node = copy;
}
inits[i] = init;
}

View File

@@ -1,6 +1,9 @@
ODIN=../../odin
all: map_test
map_test:
ODIN=../../odin
all: rtti_test map_test
rtti_test:
$(ODIN) run test_rtti.odin -file -vet -strict-style -o:minimal
map_test:
$(ODIN) run test_map.odin -file -vet -strict-style -o:minimal

View File

@@ -1,4 +1,5 @@
@echo off
set PATH_TO_ODIN==..\..\odin
%PATH_TO_ODIN% run test_map.odin -file -vet -strict-style -o:minimal || exit /b
@echo off
set PATH_TO_ODIN==..\..\odin
rem %PATH_TO_ODIN% run test_rtti.odin -file -vet -strict-style -o:minimal || exit /b
%PATH_TO_ODIN% run test_map.odin -file -vet -strict-style -o:minimal || exit /b
rem -define:SEED=42

View File

@@ -0,0 +1,101 @@
package test_internal_rtti
import "core:fmt"
import "core:mem"
import "core:os"
import "core:testing"
Buggy_Struct :: struct {
a: int,
b: bool,
c: [3]^string,
}
#assert(size_of(Buggy_Struct) == 40)
g_buggy: Buggy_Struct = {}
EXPECTED_REPR := "%!s(Buggy_Struct=Buggy_Struct{a = 0, b = false, c = [0x0, 0x0, 0x0]})"
@test
rtti_test :: proc(t: ^testing.T) {
l_buggy: Buggy_Struct = {}
g_b := ([^]u8)(&g_buggy)[:size_of(Buggy_Struct)]
l_b := ([^]u8)(&l_buggy)[:size_of(Buggy_Struct)]
{
checksum := 0
for v, i in g_b {
checksum += (i+1) * int(v)
}
expect(t, checksum == 0, fmt.tprintf("Expected g_b to be zero-initialized, got %v", g_b))
}
{
checksum := 0
for v, i in l_b {
checksum += (i+1) * int(v)
}
expect(t, checksum == 0, fmt.tprintf("Expected l_b to be zero-initialized, got %v", l_b))
}
expect(t, size_of(Buggy_Struct) == 40, fmt.tprintf("Expected size_of(Buggy_Struct) == 40, got %v", size_of(Buggy_Struct)))
expect(t, size_of(g_buggy) == 40, fmt.tprintf("Expected size_of(g_buggy) == 40, got %v", size_of(g_buggy)))
expect(t, size_of(l_buggy) == 40, fmt.tprintf("Expected size_of(l_buggy) == 40, got %v", size_of(l_buggy)))
g_s := fmt.tprintf("%s", g_buggy)
l_s := fmt.tprintf("%s", l_buggy)
expect(t, g_s == EXPECTED_REPR, fmt.tprintf("Expected fmt.tprintf(\"%%s\", g_s)) to return \"%v\", got \"%v\"", EXPECTED_REPR, g_s))
expect(t, l_s == EXPECTED_REPR, fmt.tprintf("Expected fmt.tprintf(\"%%s\", l_s)) to return \"%v\", got \"%v\"", EXPECTED_REPR, l_s))
}
// -------- -------- -------- -------- -------- -------- -------- -------- -------- --------
main :: proc() {
t := testing.T{}
mem_track_test(&t, rtti_test)
fmt.printf("%v/%v tests successful.\n", TEST_count - TEST_fail, TEST_count)
if TEST_fail > 0 {
os.exit(1)
}
}
mem_track_test :: proc(t: ^testing.T, test: proc(t: ^testing.T)) {
track: mem.Tracking_Allocator
mem.tracking_allocator_init(&track, context.allocator)
context.allocator = mem.tracking_allocator(&track)
test(t)
expect(t, len(track.allocation_map) == 0, "Expected no leaks.")
expect(t, len(track.bad_free_array) == 0, "Expected no leaks.")
for _, leak in track.allocation_map {
fmt.printf("%v leaked %v bytes\n", leak.location, leak.size)
}
for bad_free in track.bad_free_array {
fmt.printf("%v allocation %p was freed badly\n", bad_free.location, bad_free.memory)
}
}
TEST_count := 0
TEST_fail := 0
when ODIN_TEST {
expect :: testing.expect
log :: testing.log
} else {
expect :: proc(t: ^testing.T, condition: bool, message: string, loc := #caller_location) {
TEST_count += 1
if !condition {
TEST_fail += 1
fmt.printf("[%v] %v\n", loc, message)
return
}
}
log :: proc(t: ^testing.T, v: any, loc := #caller_location) {
fmt.printf("[%v] ", loc)
fmt.printf("log: %v\n", v)
}
}

View File

@@ -1,3 +1,4 @@
//+build darwin
package CoreVideo
DisplayLinkRef :: distinct rawptr

View File

@@ -1,3 +1,4 @@
//+build darwin
package objc_Foundation
foreign import "system:Foundation.framework"

View File

@@ -1,3 +1,4 @@
//+build darwin
package objc_Foundation
import "core:intrinsics"

View File

@@ -1,3 +1,4 @@
//+build darwin
package objc_Foundation
@(objc_class="NSAutoreleasePool")

View File

@@ -1,3 +1,4 @@
//+build darwin
package objc_Foundation
import "core:intrinsics"

View File

@@ -1,3 +1,4 @@
//+build darwin
package objc_Foundation
@(objc_class="NSBundle")

View File

@@ -1,3 +1,4 @@
//+build darwin
package objc_Foundation
@(objc_class="NSColorSpace")

View File

@@ -1,3 +1,4 @@
//+build darwin
package objc_Foundation
@(objc_class="NSData")

View File

@@ -1,3 +1,4 @@
//+build darwin
package objc_Foundation
@(objc_class="NSDate")

View File

@@ -1,3 +1,4 @@
//+build darwin
package objc_Foundation
@(objc_class="NSDictionary")

View File

@@ -1,3 +1,4 @@
//+build darwin
package objc_Foundation
import "core:c"

View File

@@ -1,3 +1,4 @@
//+build darwin
package objc_Foundation
foreign import "system:Foundation.framework"

View File

@@ -1,3 +1,4 @@
//+build darwin
package objc_Foundation
@(objc_class="NSEvent")

View File

@@ -1,3 +1,4 @@
//+build darwin
package objc_Foundation
Locking :: struct($T: typeid) {using _: Object}

View File

@@ -1,3 +1,4 @@
//+build darwin
package objc_Foundation
import "core:builtin"

View File

@@ -1,3 +1,4 @@
//+build darwin
package objc_Foundation
@(objc_class="NSNotification")

View File

@@ -1,3 +1,4 @@
//+build darwin
package objc_Foundation
import "core:c"

View File

@@ -1,3 +1,4 @@
//+build darwin
package objc_Foundation
import "core:intrinsics"

View File

@@ -1,3 +1,4 @@
//+build darwin
package objc_Foundation
@(objc_class="NSOpenPanel")

View File

@@ -1,3 +1,4 @@
//+build darwin
package objc_Foundation
ModalResponse :: enum UInteger {

View File

@@ -1,3 +1,4 @@
//+build darwin
package objc_Foundation
@(objc_class="NSPasteboard")

View File

@@ -1,3 +1,4 @@
//+build darwin
package objc_Foundation
Range :: struct {

View File

@@ -1,3 +1,4 @@
//+build darwin
package objc_Foundation
@(objc_class="NSSavePanel")

View File

@@ -1,3 +1,4 @@
//+build darwin
package objc_Foundation
@(objc_class="NSScreen")

View File

@@ -1,3 +1,4 @@
//+build darwin
package objc_Foundation
@(objc_class="NSSet")

View File

@@ -1,3 +1,4 @@
//+build darwin
package objc_Foundation
foreign import "system:Foundation.framework"

View File

@@ -1,3 +1,4 @@
//+build darwin
package objc_Foundation
import "core:intrinsics"

View File

@@ -1,3 +1,4 @@
//+build darwin
package objc_Foundation
@(objc_class="NSURL")

View File

@@ -1,3 +1,4 @@
//+build darwin
package objc_Foundation
@(objc_class="NSUndoManager")

View File

@@ -1,3 +1,4 @@
//+build darwin
package objc_Foundation
@(objc_class="NSUserActivity")

View File

@@ -1,3 +1,4 @@
//+build darwin
package objc_Foundation
@(objc_class="NSUserDefaults")

View File

@@ -1,3 +1,4 @@
//+build darwin
package objc_Foundation
import "core:strings"

View File

@@ -1,3 +1,4 @@
//+build darwin
package objc_Foundation
foreign import "system:Foundation.framework"

View File

@@ -1,3 +1,4 @@
//+build darwin
package objc_Metal
import NS "vendor:darwin/Foundation"

View File

@@ -1,3 +1,4 @@
//+build darwin
package objc_Metal
import NS "vendor:darwin/Foundation"

View File

@@ -1,3 +1,4 @@
//+build darwin
package objc_Metal
import NS "vendor:darwin/Foundation"

View File

@@ -1,3 +1,4 @@
//+build darwin
package objc_Metal
import NS "vendor:darwin/Foundation"

View File

@@ -1,3 +1,4 @@
//+build darwin
package objc_Metal
import NS "vendor:darwin/Foundation"

View File

@@ -1,3 +1,4 @@
//+build darwin
package objc_MetalKit
import NS "vendor:darwin/Foundation"

View File

@@ -1,3 +1,4 @@
//+build darwin
package objc_QuartzCore
import NS "vendor:darwin/Foundation"

View File

@@ -39,7 +39,7 @@ when ODIN_OS == .Windows {
/*** Functions ***/
@(default_calling_convention="c", link_prefix="glfw")
foreign glfw {
Init :: proc() -> c.int ---
Init :: proc() -> b32 ---
Terminate :: proc() ---
InitHint :: proc(hint, value: c.int) ---

View File

@@ -41,7 +41,7 @@ WindowMaximizeProc :: #type proc "c" (window: WindowHandle, iconified: c.int
WindowContentScaleProc :: #type proc "c" (window: WindowHandle, xscale, yscale: f32)
FramebufferSizeProc :: #type proc "c" (window: WindowHandle, width, height: c.int)
DropProc :: #type proc "c" (window: WindowHandle, count: c.int, paths: [^]cstring)
MonitorProc :: #type proc "c" (window: WindowHandle)
MonitorProc :: #type proc "c" (window: WindowHandle, event: c.int)
KeyProc :: #type proc "c" (window: WindowHandle, key, scancode, action, mods: c.int)
MouseButtonProc :: #type proc "c" (window: WindowHandle, button, action, mods: c.int)

View File

@@ -49,7 +49,19 @@ SetGammaRamp :: glfw.SetGammaRamp
CreateWindow :: glfw.CreateWindow
DestroyWindow :: glfw.DestroyWindow
WindowHint :: glfw.WindowHint
WindowHint_int :: proc "contextless" (hint: c.int, value: c.int) {
glfw.WindowHint(hint, value)
}
WindowHint_bool :: proc "contextless" (hint: c.int, value: b32) {
glfw.WindowHint(hint, cast(c.int) value)
}
WindowHint :: proc {
WindowHint_int,
WindowHint_bool,
}
DefaultWindowHints :: glfw.DefaultWindowHints
WindowHintString :: glfw.WindowHintString
WindowShouldClose :: glfw.WindowShouldClose

View File

@@ -1349,6 +1349,11 @@ function odinSetupDefaultImports(wasmMemoryInterface, consoleElement) {
ln: Math.log,
exp: Math.exp,
ldexp: (x, exp) => x * Math.pow(2, exp),
rand_bytes: (ptr, len) => {
const view = new Uint8Array(wasmMemoryInterface.memory.buffer, ptr, len)
crypto.getRandomValues(view)
},
},
"odin_dom": {
init_event_raw: (ep) => {