mirror of
https://github.com/Ed94/Odin.git
synced 2026-07-10 21:31:37 -07:00
Remove special shared scope for runtime stuff
This commit is contained in:
+64
-64
@@ -1,11 +1,11 @@
|
||||
package fmt
|
||||
|
||||
import "core:runtime"
|
||||
import "core:os"
|
||||
import "core:mem"
|
||||
import "core:unicode/utf8"
|
||||
import "core:types"
|
||||
import "core:strconv"
|
||||
import "core:raw"
|
||||
|
||||
|
||||
_BUFFER_SIZE :: 1<<12;
|
||||
@@ -33,8 +33,8 @@ Fmt_Info :: struct {
|
||||
}
|
||||
|
||||
string_buffer_from_slice :: proc(backing: []byte) -> String_Buffer {
|
||||
s := transmute(raw.Slice)backing;
|
||||
d := raw.Dynamic_Array{
|
||||
s := transmute(mem.Raw_Slice)backing;
|
||||
d := mem.Raw_Dynamic_Array{
|
||||
data = s.data,
|
||||
len = 0,
|
||||
cap = s.len,
|
||||
@@ -145,7 +145,7 @@ bprintf :: proc(buf: []byte, fmt: string, args: ...any) -> string {
|
||||
|
||||
|
||||
|
||||
fprint_type :: proc(fd: os.Handle, info: ^Type_Info) {
|
||||
fprint_type :: proc(fd: os.Handle, info: ^runtime.Type_Info) {
|
||||
data: [_BUFFER_SIZE]byte;
|
||||
buf := string_buffer_from_slice(data[..]);
|
||||
write_type(&buf, info);
|
||||
@@ -156,18 +156,18 @@ write_typeid :: proc(buf: ^String_Buffer, id: typeid) {
|
||||
write_type(buf, type_info_of(id));
|
||||
}
|
||||
|
||||
write_type :: proc(buf: ^String_Buffer, ti: ^Type_Info) {
|
||||
write_type :: proc(buf: ^String_Buffer, ti: ^runtime.Type_Info) {
|
||||
if ti == nil {
|
||||
write_string(buf, "nil");
|
||||
return;
|
||||
}
|
||||
|
||||
switch info in ti.variant {
|
||||
case Type_Info_Named:
|
||||
case runtime.Type_Info_Named:
|
||||
write_string(buf, info.name);
|
||||
case Type_Info_Integer:
|
||||
case runtime.Type_Info_Integer:
|
||||
a := any{typeid = typeid_of(ti)};
|
||||
switch _ in a {
|
||||
switch in a {
|
||||
case int: write_string(buf, "int");
|
||||
case uint: write_string(buf, "uint");
|
||||
case uintptr: write_string(buf, "uintptr");
|
||||
@@ -175,47 +175,47 @@ write_type :: proc(buf: ^String_Buffer, ti: ^Type_Info) {
|
||||
write_byte(buf, info.signed ? 'i' : 'u');
|
||||
write_i64(buf, i64(8*ti.size), 10);
|
||||
}
|
||||
case Type_Info_Rune:
|
||||
case runtime.Type_Info_Rune:
|
||||
write_string(buf, "rune");
|
||||
case Type_Info_Float:
|
||||
case runtime.Type_Info_Float:
|
||||
write_byte(buf, 'f');
|
||||
write_i64(buf, i64(8*ti.size), 10);
|
||||
case Type_Info_Complex:
|
||||
case runtime.Type_Info_Complex:
|
||||
write_string(buf, "complex");
|
||||
write_i64(buf, i64(8*ti.size), 10);
|
||||
case Type_Info_String:
|
||||
case runtime.Type_Info_String:
|
||||
if info.is_cstring {
|
||||
write_string(buf, "cstring");
|
||||
} else {
|
||||
write_string(buf, "string");
|
||||
}
|
||||
case Type_Info_Boolean:
|
||||
case runtime.Type_Info_Boolean:
|
||||
a := any{typeid = typeid_of(ti)};
|
||||
switch _ in a {
|
||||
switch in a {
|
||||
case bool: write_string(buf, "bool");
|
||||
case:
|
||||
write_byte(buf, 'b');
|
||||
write_i64(buf, i64(8*ti.size), 10);
|
||||
}
|
||||
case Type_Info_Any:
|
||||
case runtime.Type_Info_Any:
|
||||
write_string(buf, "any");
|
||||
|
||||
case Type_Info_Type_Id:
|
||||
case runtime.Type_Info_Type_Id:
|
||||
write_string(buf, "typeid");
|
||||
|
||||
case Type_Info_Pointer:
|
||||
case runtime.Type_Info_Pointer:
|
||||
if info.elem == nil {
|
||||
write_string(buf, "rawptr");
|
||||
} else {
|
||||
write_string(buf, "^");
|
||||
write_type(buf, info.elem);
|
||||
}
|
||||
case Type_Info_Procedure:
|
||||
case runtime.Type_Info_Procedure:
|
||||
write_string(buf, "proc");
|
||||
if info.params == nil {
|
||||
write_string(buf, "()");
|
||||
} else {
|
||||
t := info.params.variant.(Type_Info_Tuple);
|
||||
t := info.params.variant.(runtime.Type_Info_Tuple);
|
||||
write_string(buf, "(");
|
||||
for t, i in t.types {
|
||||
if i > 0 do write_string(buf, ", ");
|
||||
@@ -227,7 +227,7 @@ write_type :: proc(buf: ^String_Buffer, ti: ^Type_Info) {
|
||||
write_string(buf, " -> ");
|
||||
write_type(buf, info.results);
|
||||
}
|
||||
case Type_Info_Tuple:
|
||||
case runtime.Type_Info_Tuple:
|
||||
count := len(info.names);
|
||||
if count != 1 do write_string(buf, "(");
|
||||
for name, i in info.names {
|
||||
@@ -243,25 +243,25 @@ write_type :: proc(buf: ^String_Buffer, ti: ^Type_Info) {
|
||||
}
|
||||
if count != 1 do write_string(buf, ")");
|
||||
|
||||
case Type_Info_Array:
|
||||
case runtime.Type_Info_Array:
|
||||
write_string(buf, "[");
|
||||
write_i64(buf, i64(info.count), 10);
|
||||
write_string(buf, "]");
|
||||
write_type(buf, info.elem);
|
||||
case Type_Info_Dynamic_Array:
|
||||
case runtime.Type_Info_Dynamic_Array:
|
||||
write_string(buf, "[dynamic]");
|
||||
write_type(buf, info.elem);
|
||||
case Type_Info_Slice:
|
||||
case runtime.Type_Info_Slice:
|
||||
write_string(buf, "[]");
|
||||
write_type(buf, info.elem);
|
||||
|
||||
case Type_Info_Map:
|
||||
case runtime.Type_Info_Map:
|
||||
write_string(buf, "map[");
|
||||
write_type(buf, info.key);
|
||||
write_byte(buf, ']');
|
||||
write_type(buf, info.value);
|
||||
|
||||
case Type_Info_Struct:
|
||||
case runtime.Type_Info_Struct:
|
||||
write_string(buf, "struct ");
|
||||
if info.is_packed do write_string(buf, "#packed ");
|
||||
if info.is_raw_union do write_string(buf, "#raw_union ");
|
||||
@@ -279,7 +279,7 @@ write_type :: proc(buf: ^String_Buffer, ti: ^Type_Info) {
|
||||
}
|
||||
write_byte(buf, '}');
|
||||
|
||||
case Type_Info_Union:
|
||||
case runtime.Type_Info_Union:
|
||||
write_string(buf, "union {");
|
||||
for variant, i in info.variants {
|
||||
if i > 0 do write_string(buf, ", ");
|
||||
@@ -287,7 +287,7 @@ write_type :: proc(buf: ^String_Buffer, ti: ^Type_Info) {
|
||||
}
|
||||
write_string(buf, "}");
|
||||
|
||||
case Type_Info_Enum:
|
||||
case runtime.Type_Info_Enum:
|
||||
write_string(buf, "enum ");
|
||||
write_type(buf, info.base);
|
||||
if info.is_export do write_string(buf, " #export");
|
||||
@@ -298,7 +298,7 @@ write_type :: proc(buf: ^String_Buffer, ti: ^Type_Info) {
|
||||
}
|
||||
write_string(buf, "}");
|
||||
|
||||
case Type_Info_Bit_Field:
|
||||
case runtime.Type_Info_Bit_Field:
|
||||
write_string(buf, "bit_field ");
|
||||
if ti.align != 1 {
|
||||
write_string(buf, "#align ");
|
||||
@@ -371,7 +371,7 @@ int_from_arg :: proc(args: []any, arg_index: int) -> (int, int, bool) {
|
||||
ok := true;
|
||||
if arg_index < len(args) {
|
||||
arg := args[arg_index];
|
||||
arg.typeid = typeid_base(arg.typeid);
|
||||
arg.typeid = runtime.typeid_base(arg.typeid);
|
||||
switch i in arg {
|
||||
case int: num = i;
|
||||
case i8: num = int(i);
|
||||
@@ -630,13 +630,13 @@ fmt_pointer :: proc(fi: ^Fmt_Info, p: rawptr, verb: rune) {
|
||||
}
|
||||
|
||||
enum_value_to_string :: proc(v: any) -> (string, bool) {
|
||||
v.typeid = typeid_base(v.typeid);
|
||||
v.typeid = runtime.typeid_base(v.typeid);
|
||||
type_info := type_info_of(v.typeid);
|
||||
|
||||
switch e in type_info.variant {
|
||||
case: return "", false;
|
||||
case Type_Info_Enum:
|
||||
get_str :: proc(i: $T, e: Type_Info_Enum) -> (string, bool) {
|
||||
case runtime.Type_Info_Enum:
|
||||
get_str :: proc(i: $T, e: runtime.Type_Info_Enum) -> (string, bool) {
|
||||
if types.is_string(e.base) {
|
||||
for val, idx in e.values {
|
||||
if v, ok := val.(T); ok && v == i {
|
||||
@@ -655,7 +655,7 @@ enum_value_to_string :: proc(v: any) -> (string, bool) {
|
||||
return "", false;
|
||||
}
|
||||
|
||||
a := any{v.data, typeid_of(type_info_base(e.base))};
|
||||
a := any{v.data, typeid_of(runtime.type_info_base(e.base))};
|
||||
switch v in a {
|
||||
case rune: return get_str(v, e);
|
||||
case i8: return get_str(v, e);
|
||||
@@ -701,11 +701,11 @@ fmt_enum :: proc(fi: ^Fmt_Info, v: any, verb: rune) {
|
||||
type_info := type_info_of(v.typeid);
|
||||
switch e in type_info.variant {
|
||||
case: fmt_bad_verb(fi, verb);
|
||||
case Type_Info_Enum:
|
||||
case runtime.Type_Info_Enum:
|
||||
switch verb {
|
||||
case: fmt_bad_verb(fi, verb);
|
||||
case 'd', 'f':
|
||||
fmt_arg(fi, any{v.data, typeid_of(type_info_base(e.base))}, verb);
|
||||
fmt_arg(fi, any{v.data, typeid_of(runtime.type_info_base(e.base))}, verb);
|
||||
case 's', 'v':
|
||||
str, ok := enum_value_to_string(v);
|
||||
if !ok do str = "!%(BAD ENUM VALUE)";
|
||||
@@ -723,9 +723,9 @@ fmt_value :: proc(fi: ^Fmt_Info, v: any, verb: rune) {
|
||||
|
||||
type_info := type_info_of(v.typeid);
|
||||
switch info in type_info.variant {
|
||||
case Type_Info_Named:
|
||||
case runtime.Type_Info_Named:
|
||||
switch b in info.base.variant {
|
||||
case Type_Info_Struct:
|
||||
case runtime.Type_Info_Struct:
|
||||
if verb != 'v' {
|
||||
fmt_bad_verb(fi, verb);
|
||||
return;
|
||||
@@ -770,21 +770,21 @@ fmt_value :: proc(fi: ^Fmt_Info, v: any, verb: rune) {
|
||||
fmt_value(fi, any{v.data, typeid_of(info.base)}, verb);
|
||||
}
|
||||
|
||||
case Type_Info_Boolean: fmt_arg(fi, v, verb);
|
||||
case Type_Info_Integer: fmt_arg(fi, v, verb);
|
||||
case Type_Info_Rune: fmt_arg(fi, v, verb);
|
||||
case Type_Info_Float: fmt_arg(fi, v, verb);
|
||||
case Type_Info_Complex: fmt_arg(fi, v, verb);
|
||||
case Type_Info_String: fmt_arg(fi, v, verb);
|
||||
case runtime.Type_Info_Boolean: fmt_arg(fi, v, verb);
|
||||
case runtime.Type_Info_Integer: fmt_arg(fi, v, verb);
|
||||
case runtime.Type_Info_Rune: fmt_arg(fi, v, verb);
|
||||
case runtime.Type_Info_Float: fmt_arg(fi, v, verb);
|
||||
case runtime.Type_Info_Complex: fmt_arg(fi, v, verb);
|
||||
case runtime.Type_Info_String: fmt_arg(fi, v, verb);
|
||||
|
||||
case Type_Info_Pointer:
|
||||
if v.typeid == typeid_of(^Type_Info) {
|
||||
write_type(fi.buf, (^^Type_Info)(v.data)^);
|
||||
case runtime.Type_Info_Pointer:
|
||||
if v.typeid == typeid_of(^runtime.Type_Info) {
|
||||
write_type(fi.buf, (^^runtime.Type_Info)(v.data)^);
|
||||
} else {
|
||||
fmt_pointer(fi, (^rawptr)(v.data)^, verb);
|
||||
}
|
||||
|
||||
case Type_Info_Array:
|
||||
case runtime.Type_Info_Array:
|
||||
write_byte(fi.buf, '[');
|
||||
defer write_byte(fi.buf, ']');
|
||||
for i in 0..info.count {
|
||||
@@ -794,10 +794,10 @@ fmt_value :: proc(fi: ^Fmt_Info, v: any, verb: rune) {
|
||||
fmt_arg(fi, any{rawptr(data), typeid_of(info.elem)}, verb);
|
||||
}
|
||||
|
||||
case Type_Info_Dynamic_Array:
|
||||
case runtime.Type_Info_Dynamic_Array:
|
||||
write_byte(fi.buf, '[');
|
||||
defer write_byte(fi.buf, ']');
|
||||
array := cast(^raw.Dynamic_Array)v.data;
|
||||
array := cast(^mem.Raw_Dynamic_Array)v.data;
|
||||
for i in 0..array.len {
|
||||
if i > 0 do write_string(fi.buf, ", ");
|
||||
|
||||
@@ -805,10 +805,10 @@ fmt_value :: proc(fi: ^Fmt_Info, v: any, verb: rune) {
|
||||
fmt_arg(fi, any{rawptr(data), typeid_of(info.elem)}, verb);
|
||||
}
|
||||
|
||||
case Type_Info_Slice:
|
||||
case runtime.Type_Info_Slice:
|
||||
write_byte(fi.buf, '[');
|
||||
defer write_byte(fi.buf, ']');
|
||||
slice := cast(^raw.Slice)v.data;
|
||||
slice := cast(^mem.Raw_Slice)v.data;
|
||||
for i in 0..slice.len {
|
||||
if i > 0 do write_string(fi.buf, ", ");
|
||||
|
||||
@@ -816,7 +816,7 @@ fmt_value :: proc(fi: ^Fmt_Info, v: any, verb: rune) {
|
||||
fmt_arg(fi, any{rawptr(data), typeid_of(info.elem)}, verb);
|
||||
}
|
||||
|
||||
case Type_Info_Map:
|
||||
case runtime.Type_Info_Map:
|
||||
if verb != 'v' {
|
||||
fmt_bad_verb(fi, verb);
|
||||
return;
|
||||
@@ -825,20 +825,20 @@ fmt_value :: proc(fi: ^Fmt_Info, v: any, verb: rune) {
|
||||
write_string(fi.buf, "map[");
|
||||
defer write_byte(fi.buf, ']');
|
||||
|
||||
m := (^raw.Map)(v.data);
|
||||
m := (^mem.Raw_Map)(v.data);
|
||||
if m != nil {
|
||||
assert(info.generated_struct != nil);
|
||||
entries := &m.entries;
|
||||
gs := type_info_base(info.generated_struct).variant.(Type_Info_Struct);
|
||||
ed := type_info_base(gs.types[1]).variant.(Type_Info_Dynamic_Array);
|
||||
entry_type := ed.elem.variant.(Type_Info_Struct);
|
||||
gs := runtime.type_info_base(info.generated_struct).variant.(runtime.Type_Info_Struct);
|
||||
ed := runtime.type_info_base(gs.types[1]).variant.(runtime.Type_Info_Dynamic_Array);
|
||||
entry_type := ed.elem.variant.(runtime.Type_Info_Struct);
|
||||
entry_size := ed.elem_size;
|
||||
|
||||
for i in 0..entries.len {
|
||||
if i > 0 do write_string(fi.buf, ", ");
|
||||
|
||||
data := uintptr(entries.data) + uintptr(i*entry_size);
|
||||
header := cast(^__Map_Entry_Header)data;
|
||||
header := cast(^runtime.Map_Entry_Header)data;
|
||||
|
||||
if types.is_string(info.key) {
|
||||
write_string(fi.buf, header.key.str);
|
||||
@@ -854,7 +854,7 @@ fmt_value :: proc(fi: ^Fmt_Info, v: any, verb: rune) {
|
||||
}
|
||||
}
|
||||
|
||||
case Type_Info_Struct:
|
||||
case runtime.Type_Info_Struct:
|
||||
if info.is_raw_union {
|
||||
write_string(fi.buf, "(raw_union)");
|
||||
return;
|
||||
@@ -890,7 +890,7 @@ fmt_value :: proc(fi: ^Fmt_Info, v: any, verb: rune) {
|
||||
if hash do write_string(fi.buf, ",\n");
|
||||
}
|
||||
|
||||
case Type_Info_Union:
|
||||
case runtime.Type_Info_Union:
|
||||
tag_ptr := uintptr(v.data) + info.tag_offset;
|
||||
tag_any := any{rawptr(tag_ptr), typeid_of(info.tag_type)};
|
||||
|
||||
@@ -914,10 +914,10 @@ fmt_value :: proc(fi: ^Fmt_Info, v: any, verb: rune) {
|
||||
fmt_arg(fi, any{v.data, id}, verb);
|
||||
}
|
||||
|
||||
case Type_Info_Enum:
|
||||
case runtime.Type_Info_Enum:
|
||||
fmt_enum(fi, v, verb);
|
||||
|
||||
case Type_Info_Procedure:
|
||||
case runtime.Type_Info_Procedure:
|
||||
ptr := (^rawptr)(v.data)^;
|
||||
if ptr == nil {
|
||||
write_string(fi.buf, "nil");
|
||||
@@ -927,7 +927,7 @@ fmt_value :: proc(fi: ^Fmt_Info, v: any, verb: rune) {
|
||||
fmt_pointer(fi, ptr, 'p');
|
||||
}
|
||||
|
||||
case Type_Info_Type_Id:
|
||||
case runtime.Type_Info_Type_Id:
|
||||
id := (^typeid)(v.data)^;
|
||||
write_typeid(fi.buf, id);
|
||||
}
|
||||
@@ -960,14 +960,14 @@ fmt_arg :: proc(fi: ^Fmt_Info, arg: any, verb: rune) {
|
||||
if verb == 'T' {
|
||||
ti := type_info_of(arg.typeid);
|
||||
switch a in arg {
|
||||
case ^Type_Info: ti = a;
|
||||
case ^runtime.Type_Info: ti = a;
|
||||
}
|
||||
write_type(fi.buf, ti);
|
||||
return;
|
||||
}
|
||||
|
||||
base_arg := arg;
|
||||
base_arg.typeid = typeid_base(base_arg.typeid);
|
||||
base_arg.typeid = runtime.typeid_base(base_arg.typeid);
|
||||
switch a in base_arg {
|
||||
case bool: fmt_bool(fi, bool(a), verb);
|
||||
case b8: fmt_bool(fi, bool(a), verb);
|
||||
|
||||
+22
-37
@@ -1,7 +1,24 @@
|
||||
package mem
|
||||
|
||||
import "core:raw"
|
||||
import "core:os"
|
||||
DEFAULT_ALIGNMENT :: 2*align_of(rawptr);
|
||||
|
||||
Allocator_Mode :: enum byte {
|
||||
Alloc,
|
||||
Free,
|
||||
Free_All,
|
||||
Resize,
|
||||
}
|
||||
|
||||
Allocator_Proc :: #type proc(allocator_data: rawptr, mode: Allocator_Mode,
|
||||
size, alignment: int,
|
||||
old_memory: rawptr, old_size: int, flags: u64 = 0, location := #caller_location) -> rawptr;
|
||||
|
||||
|
||||
Allocator :: struct {
|
||||
procedure: Allocator_Proc,
|
||||
data: rawptr,
|
||||
}
|
||||
|
||||
|
||||
|
||||
alloc :: inline proc(size: int, alignment: int = DEFAULT_ALIGNMENT, loc := #caller_location) -> rawptr {
|
||||
@@ -30,16 +47,16 @@ resize :: inline proc(ptr: rawptr, old_size, new_size: int, alignment: int = DEF
|
||||
|
||||
|
||||
free_string :: proc(str: string, loc := #caller_location) {
|
||||
free_ptr(raw.data(str), loc);
|
||||
free_ptr(raw_data(str), loc);
|
||||
}
|
||||
free_cstring :: proc(str: cstring, loc := #caller_location) {
|
||||
free_ptr((^byte)(str), loc);
|
||||
}
|
||||
free_dynamic_array :: proc(array: $T/[dynamic]$E, loc := #caller_location) {
|
||||
free_ptr(raw.data(array), loc);
|
||||
free_ptr(raw_data(array), loc);
|
||||
}
|
||||
free_slice :: proc(array: $T/[]$E, loc := #caller_location) {
|
||||
free_ptr(raw.data(array), loc);
|
||||
free_ptr(raw_data(array), loc);
|
||||
}
|
||||
free_map :: proc(m: $T/map[$K]$V, loc := #caller_location) {
|
||||
raw := transmute(raw.Map)m;
|
||||
@@ -78,38 +95,6 @@ default_resize_align :: proc(old_memory: rawptr, old_size, new_size, alignment:
|
||||
}
|
||||
|
||||
|
||||
default_allocator_proc :: proc(allocator_data: rawptr, mode: Allocator_Mode,
|
||||
size, alignment: int,
|
||||
old_memory: rawptr, old_size: int, flags: u64 = 0, loc := #caller_location) -> rawptr {
|
||||
using Allocator_Mode;
|
||||
|
||||
switch mode {
|
||||
case Alloc:
|
||||
return os.heap_alloc(size);
|
||||
|
||||
case Free:
|
||||
os.heap_free(old_memory);
|
||||
return nil;
|
||||
|
||||
case Free_All:
|
||||
// NOTE(bill): Does nothing
|
||||
|
||||
case Resize:
|
||||
ptr := os.heap_resize(old_memory, size);
|
||||
assert(ptr != nil);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
default_allocator :: proc() -> Allocator {
|
||||
return Allocator{
|
||||
procedure = default_allocator_proc,
|
||||
data = nil,
|
||||
};
|
||||
}
|
||||
|
||||
nil_allocator_proc :: proc(allocator_data: rawptr, mode: Allocator_Mode,
|
||||
size, alignment: int,
|
||||
old_memory: rawptr, old_size: int, flags: u64 = 0, loc := #caller_location) -> rawptr {
|
||||
|
||||
+13
-13
@@ -1,6 +1,6 @@
|
||||
package mem
|
||||
|
||||
import "core:raw"
|
||||
import "core:runtime"
|
||||
|
||||
foreign _ {
|
||||
@(link_name = "llvm.bswap.i16") swap16 :: proc(b: u16) -> u16 ---;
|
||||
@@ -80,20 +80,20 @@ ptr_sub :: proc "contextless" (a, b: $P/^$T) -> int {
|
||||
|
||||
slice_ptr :: proc "contextless" (ptr: ^$T, len: int) -> []T {
|
||||
assert(len >= 0);
|
||||
slice := raw.Slice{data = ptr, len = len};
|
||||
slice := Raw_Slice{data = ptr, len = len};
|
||||
return transmute([]T)slice;
|
||||
}
|
||||
|
||||
slice_to_bytes :: proc "contextless" (slice: $E/[]$T) -> []byte {
|
||||
s := transmute(raw.Slice)slice;
|
||||
s := transmute(Raw_Slice)slice;
|
||||
s.len *= size_of(T);
|
||||
return transmute([]byte)s;
|
||||
}
|
||||
|
||||
|
||||
buffer_from_slice :: proc(backing: $T/[]$E) -> [dynamic]E {
|
||||
s := transmute(raw.Slice)backing;
|
||||
d := raw.Dynamic_Array{
|
||||
s := transmute(Raw_Slice)backing;
|
||||
d := Raw_Dynamic_Array{
|
||||
data = s.data,
|
||||
len = 0,
|
||||
cap = s.len,
|
||||
@@ -104,13 +104,13 @@ buffer_from_slice :: proc(backing: $T/[]$E) -> [dynamic]E {
|
||||
|
||||
ptr_to_bytes :: proc "contextless" (ptr: ^$T, len := 1) -> []byte {
|
||||
assert(len >= 0);
|
||||
return transmute([]byte)raw.Slice{ptr, len*size_of(T)};
|
||||
return transmute([]byte)Raw_Slice{ptr, len*size_of(T)};
|
||||
}
|
||||
|
||||
any_to_bytes :: proc "contextless" (val: any) -> []byte {
|
||||
ti := type_info_of(val.typeid);
|
||||
size := ti != nil ? ti.size : 0;
|
||||
return transmute([]byte)raw.Slice{val.data, size};
|
||||
return transmute([]byte)Raw_Slice{val.data, size};
|
||||
}
|
||||
|
||||
|
||||
@@ -158,8 +158,8 @@ allocation_header :: proc(data: rawptr) -> ^AllocationHeader {
|
||||
Fixed_Byte_Buffer :: distinct [dynamic]byte;
|
||||
|
||||
make_fixed_byte_buffer :: proc(backing: []byte) -> Fixed_Byte_Buffer {
|
||||
s := transmute(raw.Slice)backing;
|
||||
d: raw.Dynamic_Array;
|
||||
s := transmute(Raw_Slice)backing;
|
||||
d: Raw_Dynamic_Array;
|
||||
d.data = s.data;
|
||||
d.len = 0;
|
||||
d.cap = s.len;
|
||||
@@ -199,7 +199,7 @@ init_arena_from_context :: proc(using a: ^Arena, size: int) {
|
||||
}
|
||||
|
||||
|
||||
context_from_allocator :: proc(a: Allocator) -> Context {
|
||||
context_from_allocator :: proc(a: Allocator) -> runtime.Context {
|
||||
c := context;
|
||||
c.allocator = a;
|
||||
return c;
|
||||
@@ -241,7 +241,7 @@ arena_allocator_proc :: proc(allocator_data: rawptr, mode: Allocator_Mode,
|
||||
#no_bounds_check end := &arena.memory[len(arena.memory)];
|
||||
|
||||
ptr := align_forward(end, uintptr(alignment));
|
||||
(^raw.Slice)(&arena.memory).len += total_size;
|
||||
(^Raw_Slice)(&arena.memory).len += total_size;
|
||||
return zero(ptr, size);
|
||||
|
||||
case Free:
|
||||
@@ -249,7 +249,7 @@ arena_allocator_proc :: proc(allocator_data: rawptr, mode: Allocator_Mode,
|
||||
// Use ArenaTempMemory if you want to free a block
|
||||
|
||||
case Free_All:
|
||||
(^raw.Slice)(&arena.memory).len = 0;
|
||||
(^Raw_Slice)(&arena.memory).len = 0;
|
||||
|
||||
case Resize:
|
||||
return default_resize_align(old_memory, old_size, size, alignment);
|
||||
@@ -269,7 +269,7 @@ begin_arena_temp_memory :: proc(a: ^Arena) -> ArenaTempMemory {
|
||||
end_arena_temp_memory :: proc(using tmp: ArenaTempMemory) {
|
||||
assert(len(arena.memory) >= original_count);
|
||||
assert(arena.temp_count > 0);
|
||||
(^raw.Dynamic_Array)(&arena.memory).len = original_count;
|
||||
(^Raw_Dynamic_Array)(&arena.memory).len = original_count;
|
||||
arena.temp_count -= 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
package mem
|
||||
|
||||
Raw_Any :: struct {
|
||||
data: rawptr,
|
||||
typeid: typeid,
|
||||
}
|
||||
|
||||
Raw_String :: struct {
|
||||
data: ^byte,
|
||||
len: int,
|
||||
}
|
||||
|
||||
Raw_Cstring :: struct {
|
||||
data: ^byte,
|
||||
}
|
||||
|
||||
Raw_Slice :: struct {
|
||||
data: rawptr,
|
||||
len: int,
|
||||
}
|
||||
|
||||
Raw_Dynamic_Array :: struct {
|
||||
data: rawptr,
|
||||
len: int,
|
||||
cap: int,
|
||||
allocator: Allocator,
|
||||
}
|
||||
|
||||
Raw_Map :: struct {
|
||||
hashes: [dynamic]int,
|
||||
entries: Raw_Dynamic_Array,
|
||||
}
|
||||
|
||||
|
||||
make_any :: inline proc(data: rawptr, id: typeid) -> any {
|
||||
return transmute(any)Raw_Any{data, id};
|
||||
}
|
||||
|
||||
raw_string_data :: inline proc(s: $T/string) -> ^byte {
|
||||
return (^Raw_String)(&s).data;
|
||||
}
|
||||
raw_slice_data :: inline proc(a: $T/[]$E) -> ^E {
|
||||
return cast(^E)(^Raw_Slice)(&a).data;
|
||||
}
|
||||
raw_dynamic_array_data :: inline proc(a: $T/[dynamic]$E) -> ^E {
|
||||
return cast(^E)(^Raw_Dynamic_Array)(&a).data;
|
||||
}
|
||||
|
||||
raw_data :: proc[raw_string_data, raw_slice_data, raw_dynamic_array_data];
|
||||
|
||||
|
||||
+36
-3
@@ -1,6 +1,6 @@
|
||||
package os
|
||||
|
||||
import "core:raw"
|
||||
import "core:mem"
|
||||
|
||||
write_string :: proc(fd: Handle, str: string) -> (int, Errno) {
|
||||
return write(fd, cast([]byte)str);
|
||||
@@ -56,11 +56,44 @@ write_entire_file :: proc(name: string, data: []byte, truncate := true) -> (succ
|
||||
}
|
||||
|
||||
write_ptr :: proc(fd: Handle, data: rawptr, len: int) -> (int, Errno) {
|
||||
s := transmute([]byte)raw.Slice{data, len};
|
||||
s := transmute([]byte)mem.Raw_Slice{data, len};
|
||||
return write(fd, s);
|
||||
}
|
||||
|
||||
read_ptr :: proc(fd: Handle, data: rawptr, len: int) -> (int, Errno) {
|
||||
s := transmute([]byte)raw.Slice{data, len};
|
||||
s := transmute([]byte)mem.Raw_Slice{data, len};
|
||||
return read(fd, s);
|
||||
}
|
||||
|
||||
|
||||
default_allocator_proc :: proc(allocator_data: rawptr, mode: mem.Allocator_Mode,
|
||||
size, alignment: int,
|
||||
old_memory: rawptr, old_size: int, flags: u64 = 0, loc := #caller_location) -> rawptr {
|
||||
using mem.Allocator_Mode;
|
||||
|
||||
switch mode {
|
||||
case Alloc:
|
||||
return heap_alloc(size);
|
||||
|
||||
case Free:
|
||||
heap_free(old_memory);
|
||||
return nil;
|
||||
|
||||
case Free_All:
|
||||
// NOTE(bill): Does nothing
|
||||
|
||||
case Resize:
|
||||
ptr := heap_resize(old_memory, size);
|
||||
assert(ptr != nil);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
default_allocator :: proc() -> mem.Allocator {
|
||||
return mem.Allocator{
|
||||
procedure = default_allocator_proc,
|
||||
data = nil,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,51 +0,0 @@
|
||||
package raw
|
||||
|
||||
Any :: struct {
|
||||
data: rawptr,
|
||||
typeid: typeid,
|
||||
}
|
||||
|
||||
String :: struct {
|
||||
data: ^byte,
|
||||
len: int,
|
||||
}
|
||||
|
||||
Cstring :: struct {
|
||||
data: ^byte,
|
||||
}
|
||||
|
||||
Slice :: struct {
|
||||
data: rawptr,
|
||||
len: int,
|
||||
}
|
||||
|
||||
Dynamic_Array :: struct {
|
||||
data: rawptr,
|
||||
len: int,
|
||||
cap: int,
|
||||
allocator: Allocator,
|
||||
}
|
||||
|
||||
Map :: struct {
|
||||
hashes: [dynamic]int,
|
||||
entries: Dynamic_Array,
|
||||
}
|
||||
|
||||
|
||||
make_any :: inline proc(data: rawptr, id: typeid) -> any {
|
||||
return transmute(any)Any{data, id};
|
||||
}
|
||||
|
||||
string_data :: inline proc(s: $T/string) -> ^byte {
|
||||
return (^String)(&s).data;
|
||||
}
|
||||
slice_data :: inline proc(a: $T/[]$E) -> ^E {
|
||||
return cast(^E)(^Slice)(&a).data;
|
||||
}
|
||||
dynamic_array_data :: inline proc(a: $T/[dynamic]$E) -> ^E {
|
||||
return cast(^E)(^Dynamic_Array)(&a).data;
|
||||
}
|
||||
|
||||
data :: proc[string_data, slice_data, dynamic_array_data];
|
||||
|
||||
|
||||
+71
-82
@@ -4,7 +4,6 @@
|
||||
package runtime
|
||||
|
||||
import "core:os"
|
||||
import "core:raw"
|
||||
import "core:mem"
|
||||
|
||||
// Naming Conventions:
|
||||
@@ -134,9 +133,9 @@ Type_Info :: struct {
|
||||
|
||||
// NOTE(bill): only the ones that are needed (not all types)
|
||||
// This will be set by the compiler
|
||||
__type_table: []Type_Info;
|
||||
type_table: []Type_Info;
|
||||
|
||||
__args__: []cstring;
|
||||
args__: []cstring;
|
||||
|
||||
// IMPORTANT NOTE(bill): Must be in this order (as the compiler relies upon it)
|
||||
|
||||
@@ -147,27 +146,8 @@ Source_Code_Location :: struct {
|
||||
procedure: string,
|
||||
}
|
||||
|
||||
Allocator_Mode :: enum byte {
|
||||
Alloc,
|
||||
Free,
|
||||
Free_All,
|
||||
Resize,
|
||||
}
|
||||
|
||||
Allocator_Proc :: #type proc(allocator_data: rawptr, mode: Allocator_Mode,
|
||||
size, alignment: int,
|
||||
old_memory: rawptr, old_size: int, flags: u64 = 0, location := #caller_location) -> rawptr;
|
||||
|
||||
|
||||
Allocator :: struct {
|
||||
procedure: Allocator_Proc,
|
||||
data: rawptr,
|
||||
}
|
||||
|
||||
|
||||
|
||||
Context :: struct {
|
||||
allocator: Allocator,
|
||||
allocator: mem.Allocator,
|
||||
thread_id: int,
|
||||
|
||||
user_data: any,
|
||||
@@ -177,34 +157,33 @@ Context :: struct {
|
||||
derived: any, // May be used for derived data types
|
||||
}
|
||||
|
||||
DEFAULT_ALIGNMENT :: 2*align_of(rawptr);
|
||||
|
||||
|
||||
|
||||
|
||||
__INITIAL_MAP_CAP :: 16;
|
||||
INITIAL_MAP_CAP :: 16;
|
||||
|
||||
__Map_Key :: struct {
|
||||
Map_Key :: struct {
|
||||
hash: u64,
|
||||
str: string,
|
||||
}
|
||||
|
||||
__Map_Find_Result :: struct {
|
||||
Map_Find_Result :: struct {
|
||||
hash_index: int,
|
||||
entry_prev: int,
|
||||
entry_index: int,
|
||||
}
|
||||
|
||||
__Map_Entry_Header :: struct {
|
||||
key: __Map_Key,
|
||||
Map_Entry_Header :: struct {
|
||||
key: Map_Key,
|
||||
next: int,
|
||||
/*
|
||||
value: Value_Type,
|
||||
*/
|
||||
}
|
||||
|
||||
__Map_Header :: struct {
|
||||
m: ^raw.Map,
|
||||
Map_Header :: struct {
|
||||
m: ^mem.Raw_Map,
|
||||
is_key_string: bool,
|
||||
entry_size: int,
|
||||
entry_align: int,
|
||||
@@ -251,10 +230,10 @@ __typeid_of :: proc "contextless" (ti: ^Type_Info) -> typeid {
|
||||
}
|
||||
__type_info_of :: proc "contextless" (id: typeid) -> ^Type_Info {
|
||||
n := int(transmute(uintptr)id);
|
||||
if n < 0 || n >= len(__type_table) {
|
||||
if n < 0 || n >= len(type_table) {
|
||||
n = 0;
|
||||
}
|
||||
return &__type_table[n];
|
||||
return &type_table[n];
|
||||
}
|
||||
|
||||
typeid_base :: proc "contextless" (id: typeid) -> typeid {
|
||||
@@ -297,17 +276,13 @@ __init_context_from_ptr :: proc "contextless" (c: ^Context, other: ^Context) {
|
||||
__init_context :: proc "contextless" (c: ^Context) {
|
||||
if c == nil do return;
|
||||
|
||||
if c.allocator.procedure == nil {
|
||||
c.allocator = mem.default_allocator();
|
||||
}
|
||||
if c.thread_id == 0 {
|
||||
c.thread_id = os.current_thread_id();
|
||||
}
|
||||
c.allocator = os.default_allocator();
|
||||
c.thread_id = os.current_thread_id();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@(builtin)
|
||||
copy :: proc "contextless" (dst, src: $T/[]$E) -> int {
|
||||
n := max(0, min(len(dst), len(src)));
|
||||
if n > 0 do mem.copy(&dst[0], &src[0], n*size_of(E));
|
||||
@@ -316,33 +291,38 @@ copy :: proc "contextless" (dst, src: $T/[]$E) -> int {
|
||||
|
||||
|
||||
|
||||
@(builtin)
|
||||
pop :: proc "contextless" (array: ^$T/[dynamic]$E) -> E {
|
||||
if array == nil do return E{};
|
||||
assert(len(array) > 0);
|
||||
res := array[len(array)-1];
|
||||
(^raw.Dynamic_Array)(array).len -= 1;
|
||||
(^mem.Raw_Dynamic_Array)(array).len -= 1;
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@(builtin)
|
||||
clear :: proc[clear_dynamic_array, clear_map];
|
||||
|
||||
@(builtin)
|
||||
reserve :: proc[reserve_dynamic_array, reserve_map];
|
||||
|
||||
|
||||
|
||||
@(builtin)
|
||||
new :: inline proc(T: type, loc := #caller_location) -> ^T {
|
||||
ptr := (^T)(mem.alloc(size_of(T), align_of(T), loc));
|
||||
ptr^ = T{};
|
||||
return ptr;
|
||||
}
|
||||
|
||||
@(builtin)
|
||||
new_clone :: inline proc(data: $T, loc := #caller_location) -> ^T {
|
||||
ptr := (^T)(mem.alloc(size_of(T), align_of(T), loc));
|
||||
ptr^ = data;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
|
||||
@(builtin)
|
||||
free :: proc[
|
||||
mem.free_ptr,
|
||||
mem.free_string,
|
||||
@@ -355,25 +335,29 @@ free :: proc[
|
||||
|
||||
|
||||
|
||||
@(builtin)
|
||||
clear_map :: inline proc "contextless" (m: ^$T/map[$K]$V) {
|
||||
if m == nil do return;
|
||||
raw_map := (^raw.Map)(m);
|
||||
hashes := (^raw.Dynamic_Array)(&raw_map.hashes);
|
||||
entries := (^raw.Dynamic_Array)(&raw_map.entries);
|
||||
raw_map := (^mem.Raw_Map)(m);
|
||||
hashes := (^mem.Raw_Dynamic_Array)(&raw_map.hashes);
|
||||
entries := (^mem.Raw_Dynamic_Array)(&raw_map.entries);
|
||||
hashes.len = 0;
|
||||
entries.len = 0;
|
||||
}
|
||||
|
||||
@(builtin)
|
||||
reserve_map :: proc(m: ^$T/map[$K]$V, capacity: int) {
|
||||
if m != nil do __dynamic_map_reserve(__get_map_header(m), capacity);
|
||||
}
|
||||
|
||||
@(builtin)
|
||||
delete :: proc(m: ^$T/map[$K]$V, key: K) {
|
||||
if m != nil do __dynamic_map_delete(__get_map_header(m), __get_map_key(key));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@(builtin)
|
||||
append :: proc(array: ^$T/[dynamic]$E, args: ...E, loc := #caller_location) -> int {
|
||||
if array == nil do return 0;
|
||||
|
||||
@@ -387,7 +371,7 @@ append :: proc(array: ^$T/[dynamic]$E, args: ...E, loc := #caller_location) -> i
|
||||
}
|
||||
arg_len = min(cap(array)-len(array), arg_len);
|
||||
if arg_len > 0 {
|
||||
a := (^raw.Dynamic_Array)(array);
|
||||
a := (^mem.Raw_Dynamic_Array)(array);
|
||||
data := (^E)(a.data);
|
||||
assert(data != nil);
|
||||
mem.copy(mem.ptr_offset(data, uintptr(a.len)), &args[0], size_of(E) * arg_len);
|
||||
@@ -396,6 +380,7 @@ append :: proc(array: ^$T/[dynamic]$E, args: ...E, loc := #caller_location) -> i
|
||||
return len(array);
|
||||
}
|
||||
|
||||
@(builtin)
|
||||
append_string :: proc(array: ^$T/[dynamic]$E/u8, args: ...string, loc := #caller_location) -> int {
|
||||
for arg in args {
|
||||
append(array = array, args = ([]E)(arg), loc = loc);
|
||||
@@ -403,13 +388,15 @@ append_string :: proc(array: ^$T/[dynamic]$E/u8, args: ...string, loc := #caller
|
||||
return len(array);
|
||||
}
|
||||
|
||||
@(builtin)
|
||||
clear_dynamic_array :: inline proc "contextless" (array: ^$T/[dynamic]$E) {
|
||||
if array != nil do (^raw.Dynamic_Array)(array).len = 0;
|
||||
if array != nil do (^mem.Raw_Dynamic_Array)(array).len = 0;
|
||||
}
|
||||
|
||||
@(builtin)
|
||||
reserve_dynamic_array :: proc(array: ^$T/[dynamic]$E, capacity: int, loc := #caller_location) -> bool {
|
||||
if array == nil do return false;
|
||||
a := (^raw.Dynamic_Array)(array);
|
||||
a := (^mem.Raw_Dynamic_Array)(array);
|
||||
|
||||
if capacity <= a.cap do return true;
|
||||
|
||||
@@ -423,7 +410,7 @@ reserve_dynamic_array :: proc(array: ^$T/[dynamic]$E, capacity: int, loc := #cal
|
||||
allocator := a.allocator;
|
||||
|
||||
new_data := allocator.procedure(
|
||||
allocator.data, Allocator_Mode.Resize, new_size, align_of(E),
|
||||
allocator.data, mem.Allocator_Mode.Resize, new_size, align_of(E),
|
||||
a.data, old_size, 0, loc,
|
||||
);
|
||||
if new_data == nil do return false;
|
||||
@@ -438,6 +425,7 @@ reserve_dynamic_array :: proc(array: ^$T/[dynamic]$E, capacity: int, loc := #cal
|
||||
|
||||
|
||||
|
||||
@(builtin)
|
||||
assert :: proc "contextless" (condition: bool, message := "", using loc := #caller_location) -> bool {
|
||||
if !condition {
|
||||
fd := os.stderr;
|
||||
@@ -453,6 +441,7 @@ assert :: proc "contextless" (condition: bool, message := "", using loc := #call
|
||||
return condition;
|
||||
}
|
||||
|
||||
@(builtin)
|
||||
panic :: proc "contextless" (message := "", using loc := #caller_location) {
|
||||
fd := os.stderr;
|
||||
__print_caller_location(fd, loc);
|
||||
@@ -471,7 +460,7 @@ panic :: proc "contextless" (message := "", using loc := #caller_location) {
|
||||
|
||||
|
||||
__dynamic_array_make :: proc(array_: rawptr, elem_size, elem_align: int, len, cap: int, loc := #caller_location) {
|
||||
array := (^raw.Dynamic_Array)(array_);
|
||||
array := (^mem.Raw_Dynamic_Array)(array_);
|
||||
array.allocator = context.allocator;
|
||||
assert(array.allocator.procedure != nil);
|
||||
|
||||
@@ -482,7 +471,7 @@ __dynamic_array_make :: proc(array_: rawptr, elem_size, elem_align: int, len, ca
|
||||
}
|
||||
|
||||
__dynamic_array_reserve :: proc(array_: rawptr, elem_size, elem_align: int, cap: int, loc := #caller_location) -> bool {
|
||||
array := (^raw.Dynamic_Array)(array_);
|
||||
array := (^mem.Raw_Dynamic_Array)(array_);
|
||||
|
||||
if cap <= array.cap do return true;
|
||||
|
||||
@@ -495,7 +484,7 @@ __dynamic_array_reserve :: proc(array_: rawptr, elem_size, elem_align: int, cap:
|
||||
new_size := cap * elem_size;
|
||||
allocator := array.allocator;
|
||||
|
||||
new_data := allocator.procedure(allocator.data, Allocator_Mode.Resize, new_size, elem_align, array.data, old_size, 0, loc);
|
||||
new_data := allocator.procedure(allocator.data, mem.Allocator_Mode.Resize, new_size, elem_align, array.data, old_size, 0, loc);
|
||||
if new_data == nil do return false;
|
||||
|
||||
array.data = new_data;
|
||||
@@ -504,7 +493,7 @@ __dynamic_array_reserve :: proc(array_: rawptr, elem_size, elem_align: int, cap:
|
||||
}
|
||||
|
||||
__dynamic_array_resize :: proc(array_: rawptr, elem_size, elem_align: int, len: int, loc := #caller_location) -> bool {
|
||||
array := (^raw.Dynamic_Array)(array_);
|
||||
array := (^mem.Raw_Dynamic_Array)(array_);
|
||||
|
||||
ok := __dynamic_array_reserve(array_, elem_size, elem_align, len, loc);
|
||||
if ok do array.len = len;
|
||||
@@ -514,7 +503,7 @@ __dynamic_array_resize :: proc(array_: rawptr, elem_size, elem_align: int, len:
|
||||
|
||||
__dynamic_array_append :: proc(array_: rawptr, elem_size, elem_align: int,
|
||||
items: rawptr, item_count: int, loc := #caller_location) -> int {
|
||||
array := (^raw.Dynamic_Array)(array_);
|
||||
array := (^mem.Raw_Dynamic_Array)(array_);
|
||||
|
||||
if items == nil do return 0;
|
||||
if item_count <= 0 do return 0;
|
||||
@@ -537,7 +526,7 @@ __dynamic_array_append :: proc(array_: rawptr, elem_size, elem_align: int,
|
||||
}
|
||||
|
||||
__dynamic_array_append_nothing :: proc(array_: rawptr, elem_size, elem_align: int, loc := #caller_location) -> int {
|
||||
array := (^raw.Dynamic_Array)(array_);
|
||||
array := (^mem.Raw_Dynamic_Array)(array_);
|
||||
|
||||
ok := true;
|
||||
if array.cap <= array.len+1 {
|
||||
@@ -559,10 +548,10 @@ __dynamic_array_append_nothing :: proc(array_: rawptr, elem_size, elem_align: in
|
||||
|
||||
// Map
|
||||
|
||||
__get_map_header :: proc "contextless" (m: ^$T/map[$K]$V) -> __Map_Header {
|
||||
header := __Map_Header{m = (^raw.Map)(m)};
|
||||
__get_map_header :: proc "contextless" (m: ^$T/map[$K]$V) -> Map_Header {
|
||||
header := Map_Header{m = (^mem.Raw_Map)(m)};
|
||||
Entry :: struct {
|
||||
key: __Map_Key,
|
||||
key: Map_Key,
|
||||
next: int,
|
||||
value: V,
|
||||
}
|
||||
@@ -576,8 +565,8 @@ __get_map_header :: proc "contextless" (m: ^$T/map[$K]$V) -> __Map_Header {
|
||||
return header;
|
||||
}
|
||||
|
||||
__get_map_key :: proc "contextless" (key: $K) -> __Map_Key {
|
||||
map_key: __Map_Key;
|
||||
__get_map_key :: proc "contextless" (key: $K) -> Map_Key {
|
||||
map_key: Map_Key;
|
||||
ti := type_info_base_without_enum(type_info_of(K));
|
||||
switch _ in ti.variant {
|
||||
case Type_Info_Integer:
|
||||
@@ -621,17 +610,17 @@ __default_hash :: proc(data: []byte) -> u64 {
|
||||
}
|
||||
__default_hash_string :: proc(s: string) -> u64 do return __default_hash(([]byte)(s));
|
||||
|
||||
__dynamic_map_reserve :: proc(using header: __Map_Header, cap: int, loc := #caller_location) {
|
||||
__dynamic_map_reserve :: proc(using header: Map_Header, cap: int, loc := #caller_location) {
|
||||
__dynamic_array_reserve(&m.hashes, size_of(int), align_of(int), cap, loc);
|
||||
__dynamic_array_reserve(&m.entries, entry_size, entry_align, cap, loc);
|
||||
}
|
||||
__dynamic_map_rehash :: proc(using header: __Map_Header, new_count: int, loc := #caller_location) #no_bounds_check {
|
||||
new_header: __Map_Header = header;
|
||||
nm: raw.Map;
|
||||
__dynamic_map_rehash :: proc(using header: Map_Header, new_count: int, loc := #caller_location) #no_bounds_check {
|
||||
new_header: Map_Header = header;
|
||||
nm: mem.Raw_Map;
|
||||
new_header.m = &nm;
|
||||
|
||||
header_hashes := (^raw.Dynamic_Array)(&header.m.hashes);
|
||||
nm_hashes := (^raw.Dynamic_Array)(&nm.hashes);
|
||||
header_hashes := (^mem.Raw_Dynamic_Array)(&header.m.hashes);
|
||||
nm_hashes := (^mem.Raw_Dynamic_Array)(&nm.hashes);
|
||||
|
||||
__dynamic_array_resize(nm_hashes, size_of(int), align_of(int), new_count, loc);
|
||||
__dynamic_array_reserve(&nm.entries, entry_size, entry_align, m.entries.len, loc);
|
||||
@@ -664,7 +653,7 @@ __dynamic_map_rehash :: proc(using header: __Map_Header, new_count: int, loc :=
|
||||
header.m^ = nm;
|
||||
}
|
||||
|
||||
__dynamic_map_get :: proc(h: __Map_Header, key: __Map_Key) -> rawptr {
|
||||
__dynamic_map_get :: proc(h: Map_Header, key: Map_Key) -> rawptr {
|
||||
index := __dynamic_map_find(h, key).entry_index;
|
||||
if index >= 0 {
|
||||
data := uintptr(__dynamic_map_get_entry(h, index));
|
||||
@@ -673,13 +662,13 @@ __dynamic_map_get :: proc(h: __Map_Header, key: __Map_Key) -> rawptr {
|
||||
return nil;
|
||||
}
|
||||
|
||||
__dynamic_map_set :: proc(h: __Map_Header, key: __Map_Key, value: rawptr, loc := #caller_location) #no_bounds_check {
|
||||
__dynamic_map_set :: proc(h: Map_Header, key: Map_Key, value: rawptr, loc := #caller_location) #no_bounds_check {
|
||||
|
||||
index: int;
|
||||
assert(value != nil);
|
||||
|
||||
if len(h.m.hashes) == 0 {
|
||||
__dynamic_map_reserve(h, __INITIAL_MAP_CAP, loc);
|
||||
__dynamic_map_reserve(h, INITIAL_MAP_CAP, loc);
|
||||
__dynamic_map_grow(h, loc);
|
||||
}
|
||||
|
||||
@@ -708,18 +697,18 @@ __dynamic_map_set :: proc(h: __Map_Header, key: __Map_Key, value: rawptr, loc :=
|
||||
}
|
||||
|
||||
|
||||
__dynamic_map_grow :: proc(using h: __Map_Header, loc := #caller_location) {
|
||||
__dynamic_map_grow :: proc(using h: Map_Header, loc := #caller_location) {
|
||||
// TODO(bill): Determine an efficient growing rate
|
||||
new_count := max(4*m.entries.cap + 7, __INITIAL_MAP_CAP);
|
||||
new_count := max(4*m.entries.cap + 7, INITIAL_MAP_CAP);
|
||||
__dynamic_map_rehash(h, new_count, loc);
|
||||
}
|
||||
|
||||
__dynamic_map_full :: inline proc(using h: __Map_Header) -> bool {
|
||||
__dynamic_map_full :: inline proc(using h: Map_Header) -> bool {
|
||||
return int(0.75 * f64(len(m.hashes))) <= m.entries.cap;
|
||||
}
|
||||
|
||||
|
||||
__dynamic_map_hash_equal :: proc(h: __Map_Header, a, b: __Map_Key) -> bool {
|
||||
__dynamic_map_hash_equal :: proc(h: Map_Header, a, b: Map_Key) -> bool {
|
||||
if a.hash == b.hash {
|
||||
if h.is_key_string do return a.str == b.str;
|
||||
return true;
|
||||
@@ -727,8 +716,8 @@ __dynamic_map_hash_equal :: proc(h: __Map_Header, a, b: __Map_Key) -> bool {
|
||||
return false;
|
||||
}
|
||||
|
||||
__dynamic_map_find :: proc(using h: __Map_Header, key: __Map_Key) -> __Map_Find_Result #no_bounds_check {
|
||||
fr := __Map_Find_Result{-1, -1, -1};
|
||||
__dynamic_map_find :: proc(using h: Map_Header, key: Map_Key) -> Map_Find_Result #no_bounds_check {
|
||||
fr := Map_Find_Result{-1, -1, -1};
|
||||
if len(m.hashes) > 0 {
|
||||
fr.hash_index = int(key.hash % u64(len(m.hashes)));
|
||||
fr.entry_index = m.hashes[fr.hash_index];
|
||||
@@ -742,7 +731,7 @@ __dynamic_map_find :: proc(using h: __Map_Header, key: __Map_Key) -> __Map_Find_
|
||||
return fr;
|
||||
}
|
||||
|
||||
__dynamic_map_add_entry :: proc(using h: __Map_Header, key: __Map_Key, loc := #caller_location) -> int {
|
||||
__dynamic_map_add_entry :: proc(using h: Map_Header, key: Map_Key, loc := #caller_location) -> int {
|
||||
prev := m.entries.len;
|
||||
c := __dynamic_array_append_nothing(&m.entries, entry_size, entry_align, loc);
|
||||
if c != prev {
|
||||
@@ -753,19 +742,19 @@ __dynamic_map_add_entry :: proc(using h: __Map_Header, key: __Map_Key, loc := #c
|
||||
return prev;
|
||||
}
|
||||
|
||||
__dynamic_map_delete :: proc(using h: __Map_Header, key: __Map_Key) {
|
||||
__dynamic_map_delete :: proc(using h: Map_Header, key: Map_Key) {
|
||||
fr := __dynamic_map_find(h, key);
|
||||
if fr.entry_index >= 0 {
|
||||
__dynamic_map_erase(h, fr);
|
||||
}
|
||||
}
|
||||
|
||||
__dynamic_map_get_entry :: proc(using h: __Map_Header, index: int) -> ^__Map_Entry_Header {
|
||||
__dynamic_map_get_entry :: proc(using h: Map_Header, index: int) -> ^Map_Entry_Header {
|
||||
assert(0 <= index && index < m.entries.len);
|
||||
return (^__Map_Entry_Header)(uintptr(m.entries.data) + uintptr(index*entry_size));
|
||||
return (^Map_Entry_Header)(uintptr(m.entries.data) + uintptr(index*entry_size));
|
||||
}
|
||||
|
||||
__dynamic_map_erase :: proc(using h: __Map_Header, fr: __Map_Find_Result) #no_bounds_check {
|
||||
__dynamic_map_erase :: proc(using h: Map_Header, fr: Map_Find_Result) #no_bounds_check {
|
||||
if fr.entry_prev < 0 {
|
||||
m.hashes[fr.hash_index] = __dynamic_map_get_entry(h, fr.entry_index).next;
|
||||
} else {
|
||||
|
||||
+10
-10
@@ -1,6 +1,5 @@
|
||||
package runtime
|
||||
|
||||
import "core:raw"
|
||||
import "core:mem"
|
||||
import "core:os"
|
||||
import "core:unicode/utf8"
|
||||
@@ -239,7 +238,7 @@ __cstring_to_string :: proc "contextless" (s: cstring) -> string {
|
||||
if s == nil do return "";
|
||||
ptr := (^byte)(s);
|
||||
n := __cstring_len(s);
|
||||
return transmute(string)raw.String{ptr, n};
|
||||
return transmute(string)mem.Raw_String{ptr, n};
|
||||
}
|
||||
|
||||
|
||||
@@ -250,7 +249,7 @@ __complex128_eq :: inline proc "contextless" (a, b: complex128) -> bool { return
|
||||
__complex128_ne :: inline proc "contextless" (a, b: complex128) -> bool { return real(a) != real(b) || imag(a) != imag(b); }
|
||||
|
||||
|
||||
__bounds_check_error :: proc "contextless" (file: string, line, column: int, index, count: int) {
|
||||
bounds_check_error :: proc "contextless" (file: string, line, column: int, index, count: int) {
|
||||
if 0 <= index && index < count do return;
|
||||
|
||||
fd := os.stderr;
|
||||
@@ -263,7 +262,7 @@ __bounds_check_error :: proc "contextless" (file: string, line, column: int, ind
|
||||
__debug_trap();
|
||||
}
|
||||
|
||||
__slice_expr_error :: proc "contextless" (file: string, line, column: int, lo, hi: int, len: int) {
|
||||
slice_expr_error :: proc "contextless" (file: string, line, column: int, lo, hi: int, len: int) {
|
||||
if 0 <= lo && lo <= hi && hi <= len do return;
|
||||
|
||||
|
||||
@@ -279,7 +278,7 @@ __slice_expr_error :: proc "contextless" (file: string, line, column: int, lo, h
|
||||
__debug_trap();
|
||||
}
|
||||
|
||||
__dynamic_array_expr_error :: proc "contextless" (file: string, line, column: int, low, high, max: int) {
|
||||
dynamic_array_expr_error :: proc "contextless" (file: string, line, column: int, low, high, max: int) {
|
||||
if 0 <= low && low <= high && high <= max do return;
|
||||
|
||||
fd := os.stderr;
|
||||
@@ -294,7 +293,7 @@ __dynamic_array_expr_error :: proc "contextless" (file: string, line, column: in
|
||||
__debug_trap();
|
||||
}
|
||||
|
||||
__type_assertion_check :: proc "contextless" (ok: bool, file: string, line, column: int, from, to: typeid) {
|
||||
type_assertion_check :: proc "contextless" (ok: bool, file: string, line, column: int, from, to: typeid) {
|
||||
if ok do return;
|
||||
|
||||
fd := os.stderr;
|
||||
@@ -311,11 +310,12 @@ __string_decode_rune :: inline proc "contextless" (s: string) -> (rune, int) {
|
||||
return utf8.decode_rune_from_string(s);
|
||||
}
|
||||
|
||||
__bounds_check_error_loc :: inline proc "contextless" (using loc := #caller_location, index, count: int) {
|
||||
__bounds_check_error(file_path, int(line), int(column), index, count);
|
||||
bounds_check_error_loc :: inline proc "contextless" (using loc := #caller_location, index, count: int) {
|
||||
bounds_check_error(file_path, int(line), int(column), index, count);
|
||||
}
|
||||
__slice_expr_error_loc :: inline proc "contextless" (using loc := #caller_location, lo, hi: int, len: int) {
|
||||
__slice_expr_error(file_path, int(line), int(column), lo, hi, len);
|
||||
|
||||
slice_expr_error_loc :: inline proc "contextless" (using loc := #caller_location, lo, hi: int, len: int) {
|
||||
slice_expr_error(file_path, int(line), int(column), lo, hi, len);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,112 +0,0 @@
|
||||
package runtime
|
||||
|
||||
/*
|
||||
@(link_name="__multi3")
|
||||
__multi3 :: proc "c" (a, b: u128) -> u128 {
|
||||
bits_in_dword_2 :: size_of(i64) * 4;
|
||||
lower_mask :: u128(~u64(0) >> bits_in_dword_2);
|
||||
|
||||
|
||||
when ODIN_ENDIAN == "big" {
|
||||
TWords :: struct #raw_union {
|
||||
all: u128,
|
||||
using _: struct {lo, hi: u64},
|
||||
};
|
||||
} else {
|
||||
TWords :: struct #raw_union {
|
||||
all: u128,
|
||||
using _: struct {hi, lo: u64},
|
||||
};
|
||||
}
|
||||
|
||||
r: TWords;
|
||||
t: u64;
|
||||
|
||||
r.lo = u64(a & lower_mask) * u64(b & lower_mask);
|
||||
t = r.lo >> bits_in_dword_2;
|
||||
r.lo &= u64(lower_mask);
|
||||
t += u64(a >> bits_in_dword_2) * u64(b & lower_mask);
|
||||
r.lo += u64(t & u64(lower_mask)) << bits_in_dword_2;
|
||||
r.hi = t >> bits_in_dword_2;
|
||||
t = r.lo >> bits_in_dword_2;
|
||||
r.lo &= u64(lower_mask);
|
||||
t += u64(b >> bits_in_dword_2) * u64(a & lower_mask);
|
||||
r.lo += u64(t & u64(lower_mask)) << bits_in_dword_2;
|
||||
r.hi += t >> bits_in_dword_2;
|
||||
r.hi += u64(a >> bits_in_dword_2) * u64(b >> bits_in_dword_2);
|
||||
return r.all;
|
||||
}
|
||||
|
||||
@(link_name="__umodti3")
|
||||
__u128_mod :: proc "c" (a, b: u128) -> u128 {
|
||||
r: u128;
|
||||
__u128_quo_mod(a, b, &r);
|
||||
return r;
|
||||
}
|
||||
|
||||
@(link_name="__udivti3")
|
||||
__u128_quo :: proc "c" (a, b: u128) -> u128 {
|
||||
return __u128_quo_mod(a, b, nil);
|
||||
}
|
||||
|
||||
@(link_name="__modti3")
|
||||
__i128_mod :: proc "c" (a, b: i128) -> i128 {
|
||||
r: i128;
|
||||
__i128_quo_mod(a, b, &r);
|
||||
return r;
|
||||
}
|
||||
|
||||
@(link_name="__divti3")
|
||||
__i128_quo :: proc "c" (a, b: i128) -> i128 {
|
||||
return __i128_quo_mod(a, b, nil);
|
||||
}
|
||||
|
||||
@(link_name="__divmodti4")
|
||||
__i128_quo_mod :: proc "c" (a, b: i128, rem: ^i128) -> (quo: i128) {
|
||||
s: i128;
|
||||
s = b >> 127;
|
||||
b = (b~s) - s;
|
||||
s = a >> 127;
|
||||
b = (a~s) - s;
|
||||
|
||||
uquo: u128;
|
||||
urem := __u128_quo_mod(transmute(u128)a, transmute(u128)b, &uquo);
|
||||
iquo := transmute(i128)uquo;
|
||||
irem := transmute(i128)urem;
|
||||
|
||||
iquo = (iquo~s) - s;
|
||||
irem = (irem~s) - s;
|
||||
if rem != nil do rem^ = irem;
|
||||
return iquo;
|
||||
}
|
||||
|
||||
|
||||
@(link_name="__udivmodti4")
|
||||
__u128_quo_mod :: proc "c" (a, b: u128, rem: ^u128) -> (quo: u128) {
|
||||
alo := u64(a);
|
||||
blo := u64(b);
|
||||
if b == 0 {
|
||||
if rem != nil do rem^ = 0;
|
||||
return u128(alo/blo);
|
||||
}
|
||||
|
||||
r, d, x, q: u128 = a, b, 1, 0;
|
||||
|
||||
for r >= d && (d>>127)&1 == 0 {
|
||||
x <<= 1;
|
||||
d <<= 1;
|
||||
}
|
||||
|
||||
for x != 0 {
|
||||
if r >= d {
|
||||
r -= d;
|
||||
q |= x;
|
||||
}
|
||||
x >>= 1;
|
||||
d >>= 1;
|
||||
}
|
||||
|
||||
if rem != nil do rem^ = r;
|
||||
return q;
|
||||
}
|
||||
*/
|
||||
+3
-1
@@ -1,5 +1,7 @@
|
||||
package sort
|
||||
|
||||
import "core:mem"
|
||||
|
||||
bubble_sort_proc :: proc(array: $A/[]$T, f: proc(T, T) -> int) {
|
||||
assert(f != nil);
|
||||
count := len(array);
|
||||
@@ -211,5 +213,5 @@ compare_f64s :: proc(a, b: f64) -> int {
|
||||
return 0;
|
||||
}
|
||||
compare_strings :: proc(a, b: string) -> int {
|
||||
return __string_cmp(a, b);
|
||||
return mem.compare_byte_ptrs(&a[0], &b[0], min(len(a), len(b)));
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package strings
|
||||
|
||||
import "core:raw"
|
||||
import "core:mem"
|
||||
|
||||
new_string :: proc(s: string) -> string {
|
||||
c := make([]byte, len(s)+1);
|
||||
@@ -22,7 +22,7 @@ to_odin_string :: proc(str: cstring) -> string {
|
||||
}
|
||||
|
||||
string_from_ptr :: proc(ptr: ^byte, len: int) -> string {
|
||||
return transmute(string)raw.String{ptr, len};
|
||||
return transmute(string)mem.Raw_String{ptr, len};
|
||||
}
|
||||
|
||||
contains_rune :: proc(s: string, r: rune) -> int {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package thread
|
||||
|
||||
import "core:runtime"
|
||||
import "core:sys/win32"
|
||||
|
||||
Thread_Proc :: #type proc(^Thread) -> int;
|
||||
@@ -15,7 +16,7 @@ Thread :: struct {
|
||||
data: rawptr,
|
||||
user_index: int,
|
||||
|
||||
init_context: Context,
|
||||
init_context: runtime.Context,
|
||||
use_init_context: bool,
|
||||
}
|
||||
|
||||
|
||||
+80
-78
@@ -1,6 +1,8 @@
|
||||
package types
|
||||
|
||||
are_types_identical :: proc(a, b: ^Type_Info) -> bool {
|
||||
import "core:runtime"
|
||||
|
||||
are_types_identical :: proc(a, b: ^runtime.Type_Info) -> bool {
|
||||
if a == b do return true;
|
||||
|
||||
if (a == nil && b != nil) ||
|
||||
@@ -15,47 +17,47 @@ are_types_identical :: proc(a, b: ^Type_Info) -> bool {
|
||||
}
|
||||
|
||||
switch x in a.variant {
|
||||
case Type_Info_Named:
|
||||
y, ok := b.variant.(Type_Info_Named);
|
||||
case runtime.Type_Info_Named:
|
||||
y, ok := b.variant.(runtime.Type_Info_Named);
|
||||
if !ok do return false;
|
||||
return x.base == y.base;
|
||||
|
||||
case Type_Info_Integer:
|
||||
y, ok := b.variant.(Type_Info_Integer);
|
||||
case runtime.Type_Info_Integer:
|
||||
y, ok := b.variant.(runtime.Type_Info_Integer);
|
||||
if !ok do return false;
|
||||
return x.signed == y.signed;
|
||||
|
||||
case Type_Info_Rune:
|
||||
_, ok := b.variant.(Type_Info_Rune);
|
||||
case runtime.Type_Info_Rune:
|
||||
_, ok := b.variant.(runtime.Type_Info_Rune);
|
||||
return ok;
|
||||
|
||||
case Type_Info_Float:
|
||||
_, ok := b.variant.(Type_Info_Float);
|
||||
case runtime.Type_Info_Float:
|
||||
_, ok := b.variant.(runtime.Type_Info_Float);
|
||||
return ok;
|
||||
|
||||
case Type_Info_Complex:
|
||||
_, ok := b.variant.(Type_Info_Complex);
|
||||
case runtime.Type_Info_Complex:
|
||||
_, ok := b.variant.(runtime.Type_Info_Complex);
|
||||
return ok;
|
||||
|
||||
case Type_Info_String:
|
||||
_, ok := b.variant.(Type_Info_String);
|
||||
case runtime.Type_Info_String:
|
||||
_, ok := b.variant.(runtime.Type_Info_String);
|
||||
return ok;
|
||||
|
||||
case Type_Info_Boolean:
|
||||
_, ok := b.variant.(Type_Info_Boolean);
|
||||
case runtime.Type_Info_Boolean:
|
||||
_, ok := b.variant.(runtime.Type_Info_Boolean);
|
||||
return ok;
|
||||
|
||||
case Type_Info_Any:
|
||||
_, ok := b.variant.(Type_Info_Any);
|
||||
case runtime.Type_Info_Any:
|
||||
_, ok := b.variant.(runtime.Type_Info_Any);
|
||||
return ok;
|
||||
|
||||
case Type_Info_Pointer:
|
||||
y, ok := b.variant.(Type_Info_Pointer);
|
||||
case runtime.Type_Info_Pointer:
|
||||
y, ok := b.variant.(runtime.Type_Info_Pointer);
|
||||
if !ok do return false;
|
||||
return are_types_identical(x.elem, y.elem);
|
||||
|
||||
case Type_Info_Procedure:
|
||||
y, ok := b.variant.(Type_Info_Procedure);
|
||||
case runtime.Type_Info_Procedure:
|
||||
y, ok := b.variant.(runtime.Type_Info_Procedure);
|
||||
if !ok do return false;
|
||||
switch {
|
||||
case x.variadic != y.variadic,
|
||||
@@ -65,24 +67,24 @@ are_types_identical :: proc(a, b: ^Type_Info) -> bool {
|
||||
|
||||
return are_types_identical(x.params, y.params) && are_types_identical(x.results, y.results);
|
||||
|
||||
case Type_Info_Array:
|
||||
y, ok := b.variant.(Type_Info_Array);
|
||||
case runtime.Type_Info_Array:
|
||||
y, ok := b.variant.(runtime.Type_Info_Array);
|
||||
if !ok do return false;
|
||||
if x.count != y.count do return false;
|
||||
return are_types_identical(x.elem, y.elem);
|
||||
|
||||
case Type_Info_Dynamic_Array:
|
||||
y, ok := b.variant.(Type_Info_Dynamic_Array);
|
||||
case runtime.Type_Info_Dynamic_Array:
|
||||
y, ok := b.variant.(runtime.Type_Info_Dynamic_Array);
|
||||
if !ok do return false;
|
||||
return are_types_identical(x.elem, y.elem);
|
||||
|
||||
case Type_Info_Slice:
|
||||
y, ok := b.variant.(Type_Info_Slice);
|
||||
case runtime.Type_Info_Slice:
|
||||
y, ok := b.variant.(runtime.Type_Info_Slice);
|
||||
if !ok do return false;
|
||||
return are_types_identical(x.elem, y.elem);
|
||||
|
||||
case Type_Info_Tuple:
|
||||
y, ok := b.variant.(Type_Info_Tuple);
|
||||
case runtime.Type_Info_Tuple:
|
||||
y, ok := b.variant.(runtime.Type_Info_Tuple);
|
||||
if !ok do return false;
|
||||
if len(x.types) != len(y.types) do return false;
|
||||
for _, i in x.types {
|
||||
@@ -93,8 +95,8 @@ are_types_identical :: proc(a, b: ^Type_Info) -> bool {
|
||||
}
|
||||
return true;
|
||||
|
||||
case Type_Info_Struct:
|
||||
y, ok := b.variant.(Type_Info_Struct);
|
||||
case runtime.Type_Info_Struct:
|
||||
y, ok := b.variant.(runtime.Type_Info_Struct);
|
||||
if !ok do return false;
|
||||
switch {
|
||||
case len(x.types) != len(y.types),
|
||||
@@ -112,8 +114,8 @@ are_types_identical :: proc(a, b: ^Type_Info) -> bool {
|
||||
}
|
||||
return true;
|
||||
|
||||
case Type_Info_Union:
|
||||
y, ok := b.variant.(Type_Info_Union);
|
||||
case runtime.Type_Info_Union:
|
||||
y, ok := b.variant.(runtime.Type_Info_Union);
|
||||
if !ok do return false;
|
||||
if len(x.variants) != len(y.variants) do return false;
|
||||
|
||||
@@ -123,17 +125,17 @@ are_types_identical :: proc(a, b: ^Type_Info) -> bool {
|
||||
}
|
||||
return true;
|
||||
|
||||
case Type_Info_Enum:
|
||||
case runtime.Type_Info_Enum:
|
||||
// NOTE(bill): Should be handled above
|
||||
return false;
|
||||
|
||||
case Type_Info_Map:
|
||||
y, ok := b.variant.(Type_Info_Map);
|
||||
case runtime.Type_Info_Map:
|
||||
y, ok := b.variant.(runtime.Type_Info_Map);
|
||||
if !ok do return false;
|
||||
return are_types_identical(x.key, y.key) && are_types_identical(x.value, y.value);
|
||||
|
||||
case Type_Info_Bit_Field:
|
||||
y, ok := b.variant.(Type_Info_Bit_Field);
|
||||
case runtime.Type_Info_Bit_Field:
|
||||
y, ok := b.variant.(runtime.Type_Info_Bit_Field);
|
||||
if !ok do return false;
|
||||
if len(x.names) != len(y.names) do return false;
|
||||
|
||||
@@ -154,101 +156,101 @@ are_types_identical :: proc(a, b: ^Type_Info) -> bool {
|
||||
}
|
||||
|
||||
|
||||
is_signed :: proc(info: ^Type_Info) -> bool {
|
||||
is_signed :: proc(info: ^runtime.Type_Info) -> bool {
|
||||
if info == nil do return false;
|
||||
switch i in type_info_base(info).variant {
|
||||
case Type_Info_Integer: return i.signed;
|
||||
case Type_Info_Float: return true;
|
||||
switch i in runtime.type_info_base(info).variant {
|
||||
case runtime.Type_Info_Integer: return i.signed;
|
||||
case runtime.Type_Info_Float: return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
is_integer :: proc(info: ^Type_Info) -> bool {
|
||||
is_integer :: proc(info: ^runtime.Type_Info) -> bool {
|
||||
if info == nil do return false;
|
||||
_, ok := type_info_base(info).variant.(Type_Info_Integer);
|
||||
_, ok := runtime.type_info_base(info).variant.(runtime.Type_Info_Integer);
|
||||
return ok;
|
||||
}
|
||||
is_rune :: proc(info: ^Type_Info) -> bool {
|
||||
is_rune :: proc(info: ^runtime.Type_Info) -> bool {
|
||||
if info == nil do return false;
|
||||
_, ok := type_info_base(info).variant.(Type_Info_Rune);
|
||||
_, ok := runtime.type_info_base(info).variant.(runtime.Type_Info_Rune);
|
||||
return ok;
|
||||
}
|
||||
is_float :: proc(info: ^Type_Info) -> bool {
|
||||
is_float :: proc(info: ^runtime.Type_Info) -> bool {
|
||||
if info == nil do return false;
|
||||
_, ok := type_info_base(info).variant.(Type_Info_Float);
|
||||
_, ok := runtime.type_info_base(info).variant.(runtime.Type_Info_Float);
|
||||
return ok;
|
||||
}
|
||||
is_complex :: proc(info: ^Type_Info) -> bool {
|
||||
is_complex :: proc(info: ^runtime.Type_Info) -> bool {
|
||||
if info == nil do return false;
|
||||
_, ok := type_info_base(info).variant.(Type_Info_Complex);
|
||||
_, ok := runtime.type_info_base(info).variant.(runtime.Type_Info_Complex);
|
||||
return ok;
|
||||
}
|
||||
is_any :: proc(info: ^Type_Info) -> bool {
|
||||
is_any :: proc(info: ^runtime.Type_Info) -> bool {
|
||||
if info == nil do return false;
|
||||
_, ok := type_info_base(info).variant.(Type_Info_Any);
|
||||
_, ok := runtime.type_info_base(info).variant.(runtime.Type_Info_Any);
|
||||
return ok;
|
||||
}
|
||||
is_string :: proc(info: ^Type_Info) -> bool {
|
||||
is_string :: proc(info: ^runtime.Type_Info) -> bool {
|
||||
if info == nil do return false;
|
||||
_, ok := type_info_base(info).variant.(Type_Info_String);
|
||||
_, ok := runtime.type_info_base(info).variant.(runtime.Type_Info_String);
|
||||
return ok;
|
||||
}
|
||||
is_boolean :: proc(info: ^Type_Info) -> bool {
|
||||
is_boolean :: proc(info: ^runtime.Type_Info) -> bool {
|
||||
if info == nil do return false;
|
||||
_, ok := type_info_base(info).variant.(Type_Info_Boolean);
|
||||
_, ok := runtime.type_info_base(info).variant.(runtime.Type_Info_Boolean);
|
||||
return ok;
|
||||
}
|
||||
is_pointer :: proc(info: ^Type_Info) -> bool {
|
||||
is_pointer :: proc(info: ^runtime.Type_Info) -> bool {
|
||||
if info == nil do return false;
|
||||
_, ok := type_info_base(info).variant.(Type_Info_Pointer);
|
||||
_, ok := runtime.type_info_base(info).variant.(runtime.Type_Info_Pointer);
|
||||
return ok;
|
||||
}
|
||||
is_procedure :: proc(info: ^Type_Info) -> bool {
|
||||
is_procedure :: proc(info: ^runtime.Type_Info) -> bool {
|
||||
if info == nil do return false;
|
||||
_, ok := type_info_base(info).variant.(Type_Info_Procedure);
|
||||
_, ok := runtime.type_info_base(info).variant.(runtime.Type_Info_Procedure);
|
||||
return ok;
|
||||
}
|
||||
is_array :: proc(info: ^Type_Info) -> bool {
|
||||
is_array :: proc(info: ^runtime.Type_Info) -> bool {
|
||||
if info == nil do return false;
|
||||
_, ok := type_info_base(info).variant.(Type_Info_Array);
|
||||
_, ok := runtime.type_info_base(info).variant.(runtime.Type_Info_Array);
|
||||
return ok;
|
||||
}
|
||||
is_dynamic_array :: proc(info: ^Type_Info) -> bool {
|
||||
is_dynamic_array :: proc(info: ^runtime.Type_Info) -> bool {
|
||||
if info == nil do return false;
|
||||
_, ok := type_info_base(info).variant.(Type_Info_Dynamic_Array);
|
||||
_, ok := runtime.type_info_base(info).variant.(runtime.Type_Info_Dynamic_Array);
|
||||
return ok;
|
||||
}
|
||||
is_dynamic_map :: proc(info: ^Type_Info) -> bool {
|
||||
is_dynamic_map :: proc(info: ^runtime.Type_Info) -> bool {
|
||||
if info == nil do return false;
|
||||
_, ok := type_info_base(info).variant.(Type_Info_Map);
|
||||
_, ok := runtime.type_info_base(info).variant.(runtime.Type_Info_Map);
|
||||
return ok;
|
||||
}
|
||||
is_slice :: proc(info: ^Type_Info) -> bool {
|
||||
is_slice :: proc(info: ^runtime.Type_Info) -> bool {
|
||||
if info == nil do return false;
|
||||
_, ok := type_info_base(info).variant.(Type_Info_Slice);
|
||||
_, ok := runtime.type_info_base(info).variant.(runtime.Type_Info_Slice);
|
||||
return ok;
|
||||
}
|
||||
is_tuple :: proc(info: ^Type_Info) -> bool {
|
||||
is_tuple :: proc(info: ^runtime.Type_Info) -> bool {
|
||||
if info == nil do return false;
|
||||
_, ok := type_info_base(info).variant.(Type_Info_Tuple);
|
||||
_, ok := runtime.type_info_base(info).variant.(runtime.Type_Info_Tuple);
|
||||
return ok;
|
||||
}
|
||||
is_struct :: proc(info: ^Type_Info) -> bool {
|
||||
is_struct :: proc(info: ^runtime.Type_Info) -> bool {
|
||||
if info == nil do return false;
|
||||
s, ok := type_info_base(info).variant.(Type_Info_Struct);
|
||||
s, ok := runtime.type_info_base(info).variant.(runtime.Type_Info_Struct);
|
||||
return ok && !s.is_raw_union;
|
||||
}
|
||||
is_raw_union :: proc(info: ^Type_Info) -> bool {
|
||||
is_raw_union :: proc(info: ^runtime.Type_Info) -> bool {
|
||||
if info == nil do return false;
|
||||
s, ok := type_info_base(info).variant.(Type_Info_Struct);
|
||||
s, ok := runtime.type_info_base(info).variant.(runtime.Type_Info_Struct);
|
||||
return ok && s.is_raw_union;
|
||||
}
|
||||
is_union :: proc(info: ^Type_Info) -> bool {
|
||||
is_union :: proc(info: ^runtime.Type_Info) -> bool {
|
||||
if info == nil do return false;
|
||||
_, ok := type_info_base(info).variant.(Type_Info_Union);
|
||||
_, ok := runtime.type_info_base(info).variant.(runtime.Type_Info_Union);
|
||||
return ok;
|
||||
}
|
||||
is_enum :: proc(info: ^Type_Info) -> bool {
|
||||
is_enum :: proc(info: ^runtime.Type_Info) -> bool {
|
||||
if info == nil do return false;
|
||||
_, ok := type_info_base(info).variant.(Type_Info_Enum);
|
||||
_, ok := runtime.type_info_base(info).variant.(runtime.Type_Info_Enum);
|
||||
return ok;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user