aboutsummaryrefslogtreecommitdiff
path: root/core/runtime
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2019-01-05 15:56:47 +0000
committergingerBill <bill@gingerbill.org>2019-01-05 15:56:47 +0000
commit5acea1bceb3af71e8014115fd73530cb3ec9d46a (patch)
tree718b34bfa60d358e573c010359026beed49afbeb /core/runtime
parentaac643f47601dac174212b1976aadb9ae2c1a927 (diff)
Source_Code_Location.hash; %#v printing for Source_Code_Location; allow typeid for map keys
Diffstat (limited to 'core/runtime')
-rw-r--r--core/runtime/core.odin20
-rw-r--r--core/runtime/internal.odin8
2 files changed, 22 insertions, 6 deletions
diff --git a/core/runtime/core.odin b/core/runtime/core.odin
index 382c73864..6730621c8 100644
--- a/core/runtime/core.odin
+++ b/core/runtime/core.odin
@@ -196,6 +196,7 @@ Source_Code_Location :: struct {
file_path: string,
line, column: int,
procedure: string,
+ hash: u64,
}
Assertion_Failure_Proc :: #type proc(prefix, message: string, loc: Source_Code_Location);
@@ -253,8 +254,6 @@ Map_Header :: struct {
-
-
type_info_base :: proc "contextless" (info: ^Type_Info) -> ^Type_Info {
if info == nil do return nil;
@@ -842,6 +841,23 @@ default_hash :: proc(data: []byte) -> u64 {
default_hash_string :: proc(s: string) -> u64 do return default_hash(([]byte)(s));
+source_code_location_hash :: proc(s: Source_Code_Location) -> u64 {
+ fnv64a :: proc(data: []byte, seed: u64 = 0xcbf29ce484222325) -> u64 {
+ h: u64 = seed;
+ for b in data {
+ h = (h ~ u64(b)) * 0x100000001b3;
+ }
+ return h;
+ }
+ hash := fnv64a(cast([]byte)s.file_path);
+ hash = hash ~ (u64(s.line) * 0x100000001b3);
+ hash = hash ~ (u64(s.column) * 0x100000001b3);
+ return hash;
+}
+
+
+
+
__slice_resize :: proc(array_: ^$T/[]$E, new_count: int, allocator: mem.Allocator, loc := #caller_location) -> bool {
array := (^mem.Raw_Slice)(array_);
diff --git a/core/runtime/internal.odin b/core/runtime/internal.odin
index d6fa36167..4fdb01cdf 100644
--- a/core/runtime/internal.odin
+++ b/core/runtime/internal.odin
@@ -274,7 +274,7 @@ bounds_check_error :: proc "contextless" (file: string, line, column: int, index
if 0 <= index && index < count do return;
handle_error :: proc "contextless" (file: string, line, column: int, index, count: int) {
fd := os.stderr;
- print_caller_location(fd, Source_Code_Location{file, line, column, ""});
+ print_caller_location(fd, Source_Code_Location{file, line, column, "", 0});
os.write_string(fd, " Index ");
print_i64(fd, i64(index));
os.write_string(fd, " is out of bounds range 0:");
@@ -289,7 +289,7 @@ slice_expr_error :: proc "contextless" (file: string, line, column: int, lo, hi:
if 0 <= lo && lo <= hi && hi <= len do return;
handle_error :: proc "contextless" (file: string, line, column: int, lo, hi: int, len: int) {
fd := os.stderr;
- print_caller_location(fd, Source_Code_Location{file, line, column, ""});
+ print_caller_location(fd, Source_Code_Location{file, line, column, "", 0});
os.write_string(fd, " Invalid slice indices: ");
print_i64(fd, i64(lo));
os.write_string(fd, ":");
@@ -306,7 +306,7 @@ dynamic_array_expr_error :: proc "contextless" (file: string, line, column: int,
if 0 <= low && low <= high && high <= max do return;
handle_error :: proc "contextless" (file: string, line, column: int, low, high, max: int) {
fd := os.stderr;
- print_caller_location(fd, Source_Code_Location{file, line, column, ""});
+ print_caller_location(fd, Source_Code_Location{file, line, column, "", 0});
os.write_string(fd, " Invalid dynamic array values: ");
print_i64(fd, i64(low));
os.write_string(fd, ":");
@@ -324,7 +324,7 @@ type_assertion_check :: proc "contextless" (ok: bool, file: string, line, column
if ok do return;
handle_error :: proc "contextless" (file: string, line, column: int, from, to: typeid) {
fd := os.stderr;
- print_caller_location(fd, Source_Code_Location{file, line, column, ""});
+ print_caller_location(fd, Source_Code_Location{file, line, column, "", 0});
os.write_string(fd, " Invalid type assertion from ");
print_typeid(fd, from);
os.write_string(fd, " to ");