mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-02 20:58:15 +00:00
Disable polymorphic overloading in the global scope
TODO: Figure out why it does not work in the global scope
This commit is contained in:
+68
-21
@@ -122,8 +122,7 @@ type_info_base :: proc(info: ^TypeInfo) -> ^TypeInfo {
|
||||
|
||||
base := info;
|
||||
match i in base {
|
||||
case TypeInfo.Named:
|
||||
base = i.base;
|
||||
case TypeInfo.Named: base = i.base;
|
||||
}
|
||||
return base;
|
||||
}
|
||||
@@ -134,10 +133,8 @@ type_info_base_without_enum :: proc(info: ^TypeInfo) -> ^TypeInfo {
|
||||
|
||||
base := info;
|
||||
match i in base {
|
||||
case TypeInfo.Named:
|
||||
base = i.base;
|
||||
case TypeInfo.Enum:
|
||||
base = i.base;
|
||||
case TypeInfo.Named: base = i.base;
|
||||
case TypeInfo.Enum: base = i.base;
|
||||
}
|
||||
return base;
|
||||
}
|
||||
@@ -258,8 +255,67 @@ resize :: proc(ptr: rawptr, old_size, new_size: int, alignment: int = DEFAULT_AL
|
||||
return a.procedure(a.data, AllocatorMode.Resize, new_size, alignment, ptr, old_size, 0);
|
||||
}
|
||||
|
||||
// append :: proc(s: ^[]$T, args: ..T) -> int {
|
||||
// if s == nil {
|
||||
// return 0;
|
||||
// }
|
||||
// slice := ^raw.Slice(s);
|
||||
// arg_len := len(args);
|
||||
// if arg_len <= 0 {
|
||||
// return slice.len;
|
||||
// }
|
||||
|
||||
// arg_len = min(slice.cap-slice.len, arg_len);
|
||||
// if arg_len > 0 {
|
||||
// data := ^T(slice.data);
|
||||
// assert(data != nil);
|
||||
// sz :: size_of(T);
|
||||
// __mem_copy(data + slice.len, &args[0], sz*arg_len);
|
||||
// slice.len += arg_len;
|
||||
// }
|
||||
// return slice.len;
|
||||
// }
|
||||
|
||||
// append :: proc(a: ^[dynamic]$T, args: ..T) -> int {
|
||||
// array := ^raw.DynamicArray(a);
|
||||
|
||||
// arg_len := len(args);
|
||||
// if arg_len <= 0 || items == nil {
|
||||
// return array.len;
|
||||
// }
|
||||
|
||||
|
||||
// ok := true;
|
||||
// if array.cap <= array.len+arg_len {
|
||||
// cap := 2 * array.cap + max(8, arg_len);
|
||||
// ok = __dynamic_array_reserve(array, size_of(T), align_of(T), cap);
|
||||
// }
|
||||
// // TODO(bill): Better error handling for failed reservation
|
||||
// if !ok do return array.len;
|
||||
|
||||
// data := ^T(array.data);
|
||||
// assert(data != nil);
|
||||
// __mem_copy(data + array.len, items, size_of(T) * arg_len);
|
||||
// array.len += arg_len;
|
||||
// return array.len;
|
||||
// }
|
||||
|
||||
copy :: proc(dst, src: []$T) -> int #cc_contextless {
|
||||
n := max(0, min(len(dst), len(src)));
|
||||
if n > 0 do __mem_copy(&dst[0], &src[0], n*size_of(T));
|
||||
return n;
|
||||
}
|
||||
|
||||
|
||||
new :: proc(T: type) -> ^T #inline do return ^T(alloc(size_of(T), align_of(T)));
|
||||
|
||||
/*
|
||||
free :: proc(array: [dynamic]$T) do free_ptr(^raw.DynamicArray(&array).data);
|
||||
free :: proc(slice: []$T) do free_ptr(^raw.Slice(&slice).data);
|
||||
free :: proc(str: string) do free_ptr(^raw.String(&str).data);
|
||||
free :: proc(ptr: rawptr) do free_ptr(ptr);
|
||||
*/
|
||||
|
||||
new :: proc(T: type) -> ^T #inline do return ^T(alloc(size_of(T), align_of(T)));
|
||||
|
||||
|
||||
|
||||
@@ -440,10 +496,8 @@ __mem_copy_non_overlapping :: proc(dst, src: rawptr, len: int) -> rawptr #cc_con
|
||||
__mem_compare :: proc(a, b: ^u8, n: int) -> int #cc_contextless {
|
||||
for i in 0..<n {
|
||||
match {
|
||||
case (a+i)^ < (b+i)^:
|
||||
return -1;
|
||||
case (a+i)^ > (b+i)^:
|
||||
return +1;
|
||||
case (a+i)^ < (b+i)^: return -1;
|
||||
case (a+i)^ > (b+i)^: return +1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
@@ -569,7 +623,6 @@ __slice_append :: proc(slice_: rawptr, elem_size, elem_align: int,
|
||||
return slice.len;
|
||||
}
|
||||
|
||||
|
||||
// Map stuff
|
||||
|
||||
__default_hash :: proc(data: []u8) -> u128 {
|
||||
@@ -582,9 +635,7 @@ __default_hash :: proc(data: []u8) -> u128 {
|
||||
}
|
||||
return fnv128a(data);
|
||||
}
|
||||
__default_hash_string :: proc(s: string) -> u128 {
|
||||
return __default_hash([]u8(s));
|
||||
}
|
||||
__default_hash_string :: proc(s: string) -> u128 do return __default_hash([]u8(s));
|
||||
|
||||
__INITIAL_MAP_CAP :: 16;
|
||||
|
||||
@@ -634,9 +685,7 @@ __dynamic_map_rehash :: proc(using header: __MapHeader, new_count: int) {
|
||||
for i in 0..<new_count do nm.hashes[i] = -1;
|
||||
|
||||
for i := 0; i < m.entries.len; i++ {
|
||||
if len(nm.hashes) == 0 {
|
||||
__dynamic_map_grow(new_header);
|
||||
}
|
||||
if len(nm.hashes) == 0 do __dynamic_map_grow(new_header);
|
||||
|
||||
entry_header := __dynamic_map_get_entry(header, i);
|
||||
data := ^u8(entry_header);
|
||||
@@ -655,9 +704,7 @@ __dynamic_map_rehash :: proc(using header: __MapHeader, new_count: int) {
|
||||
ndata := ^u8(e);
|
||||
__mem_copy(ndata+value_offset, data+value_offset, value_size);
|
||||
|
||||
if __dynamic_map_full(new_header) {
|
||||
__dynamic_map_grow(new_header);
|
||||
}
|
||||
if __dynamic_map_full(new_header) do __dynamic_map_grow(new_header);
|
||||
}
|
||||
free_ptr_with_allocator(header_hashes.allocator, header_hashes.data);
|
||||
free_ptr_with_allocator(header.m.entries.allocator, header.m.entries.data);
|
||||
|
||||
+36
-30
@@ -1,6 +1,7 @@
|
||||
import (
|
||||
"fmt.odin";
|
||||
"os.odin";
|
||||
"raw.odin";
|
||||
)
|
||||
foreign __llvm_core {
|
||||
swap :: proc(b: u16) -> u16 #link_name "llvm.bswap.i16" ---;
|
||||
@@ -8,33 +9,50 @@ foreign __llvm_core {
|
||||
swap :: proc(b: u64) -> u64 #link_name "llvm.bswap.i64" ---;
|
||||
}
|
||||
|
||||
set :: proc(data: rawptr, value: i32, len: int) -> rawptr {
|
||||
set :: proc(data: rawptr, value: i32, len: int) -> rawptr #cc_contextless {
|
||||
return __mem_set(data, value, len);
|
||||
}
|
||||
zero :: proc(data: rawptr, len: int) -> rawptr {
|
||||
zero :: proc(data: rawptr, len: int) -> rawptr #cc_contextless {
|
||||
return __mem_zero(data, len);
|
||||
}
|
||||
copy :: proc(dst, src: rawptr, len: int) -> rawptr {
|
||||
copy :: proc(dst, src: rawptr, len: int) -> rawptr #cc_contextless {
|
||||
return __mem_copy(dst, src, len);
|
||||
}
|
||||
copy_non_overlapping :: proc(dst, src: rawptr, len: int) -> rawptr {
|
||||
copy_non_overlapping :: proc(dst, src: rawptr, len: int) -> rawptr #cc_contextless {
|
||||
return __mem_copy_non_overlapping(dst, src, len);
|
||||
}
|
||||
compare :: proc(a, b: []u8) -> int {
|
||||
compare :: proc(a, b: []u8) -> int #cc_contextless {
|
||||
return __mem_compare(&a[0], &b[0], min(len(a), len(b)));
|
||||
}
|
||||
|
||||
/*
|
||||
slice_ptr :: proc(ptr: ^$T, len: int) -> []T #cc_contextless {
|
||||
assert(len >= 0);
|
||||
slice := raw.Slice{data = ptr, len = len, cap = len};
|
||||
return ^[]T(&slice)^;
|
||||
}
|
||||
slice_ptr :: proc(ptr: ^$T, len, cap: int) -> []T #cc_contextless {
|
||||
assert(0 <= len && len <= cap);
|
||||
slice := raw.Slice{data = ptr, len = len, cap = cap};
|
||||
return ^[]T(&slice)^;
|
||||
}
|
||||
|
||||
slice_to_bytes :: proc(slice: []$T) -> []u8 #cc_contextless {
|
||||
s := ^raw.Slice(&slice);
|
||||
s.len *= size_of(T);
|
||||
s.cap *= size_of(T);
|
||||
return ^[]u8(s)^;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
kilobytes :: proc(x: int) -> int #inline { return (x) * 1024; }
|
||||
megabytes :: proc(x: int) -> int #inline { return kilobytes(x) * 1024; }
|
||||
gigabytes :: proc(x: int) -> int #inline { return megabytes(x) * 1024; }
|
||||
terabytes :: proc(x: int) -> int #inline { return gigabytes(x) * 1024; }
|
||||
kilobytes :: proc(x: int) -> int #inline #cc_contextless { return (x) * 1024; }
|
||||
megabytes :: proc(x: int) -> int #inline #cc_contextless { return kilobytes(x) * 1024; }
|
||||
gigabytes :: proc(x: int) -> int #inline #cc_contextless { return megabytes(x) * 1024; }
|
||||
terabytes :: proc(x: int) -> int #inline #cc_contextless { return gigabytes(x) * 1024; }
|
||||
|
||||
is_power_of_two :: proc(x: int) -> bool {
|
||||
if x <= 0 {
|
||||
return false;
|
||||
}
|
||||
if x <= 0 do return false;
|
||||
return (x & (x-1)) == 0;
|
||||
}
|
||||
|
||||
@@ -44,9 +62,7 @@ align_forward :: proc(ptr: rawptr, align: int) -> rawptr {
|
||||
a := uint(align);
|
||||
p := uint(ptr);
|
||||
modulo := p & (a-1);
|
||||
if modulo != 0 {
|
||||
p += a - modulo;
|
||||
}
|
||||
if modulo != 0 do p += a - modulo;
|
||||
return rawptr(p);
|
||||
}
|
||||
|
||||
@@ -65,13 +81,9 @@ allocation_header_fill :: proc(header: ^AllocationHeader, data: rawptr, size: in
|
||||
}
|
||||
}
|
||||
allocation_header :: proc(data: rawptr) -> ^AllocationHeader {
|
||||
if data == nil {
|
||||
return nil;
|
||||
}
|
||||
if data == nil do return nil;
|
||||
p := ^int(data);
|
||||
for (p-1)^ == -1 {
|
||||
p = (p-1);
|
||||
}
|
||||
for (p-1)^ == -1 do p = (p-1);
|
||||
return ^AllocationHeader(p-1);
|
||||
}
|
||||
|
||||
@@ -184,9 +196,7 @@ end_arena_temp_memory :: proc(using tmp: ArenaTempMemory) {
|
||||
|
||||
align_of_type_info :: proc(type_info: ^TypeInfo) -> int {
|
||||
prev_pow2 :: proc(n: i64) -> i64 {
|
||||
if n <= 0 {
|
||||
return 0;
|
||||
}
|
||||
if n <= 0 do return 0;
|
||||
n |= n >> 1;
|
||||
n |= n >> 2;
|
||||
n |= n >> 4;
|
||||
@@ -271,9 +281,7 @@ size_of_type_info :: proc(type_info: ^TypeInfo) -> int {
|
||||
return WORD_SIZE;
|
||||
case Array:
|
||||
count := info.count;
|
||||
if count == 0 {
|
||||
return 0;
|
||||
}
|
||||
if count == 0 do return 0;
|
||||
size := size_of_type_info(info.elem);
|
||||
align := align_of_type_info(info.elem);
|
||||
alignment := align_formula(size, align);
|
||||
@@ -284,9 +292,7 @@ size_of_type_info :: proc(type_info: ^TypeInfo) -> int {
|
||||
return 2*WORD_SIZE;
|
||||
case Vector:
|
||||
count := info.count;
|
||||
if count == 0 {
|
||||
return 0;
|
||||
}
|
||||
if count == 0 do return 0;
|
||||
size := size_of_type_info(info.elem);
|
||||
align := align_of_type_info(info.elem);
|
||||
alignment := align_formula(size, align);
|
||||
|
||||
+21
-46
@@ -1,4 +1,5 @@
|
||||
import win32 "sys/windows.odin";
|
||||
import "mem.odin";
|
||||
|
||||
Handle :: int;
|
||||
FileTime :: u64;
|
||||
@@ -100,9 +101,8 @@ open :: proc(path: string, mode: int = O_RDONLY, perm: u32 = 0) -> (Handle, Errn
|
||||
copy(buf[..], []u8(path));
|
||||
|
||||
handle := Handle(win32.create_file_a(&buf[0], access, share_mode, sa, create_mode, win32.FILE_ATTRIBUTE_NORMAL, nil));
|
||||
if handle != INVALID_HANDLE {
|
||||
return handle, ERROR_NONE;
|
||||
}
|
||||
if handle != INVALID_HANDLE do return handle, ERROR_NONE;
|
||||
|
||||
err := win32.get_last_error();
|
||||
return INVALID_HANDLE, Errno(err);
|
||||
}
|
||||
@@ -113,23 +113,18 @@ close :: proc(fd: Handle) {
|
||||
|
||||
|
||||
write :: proc(fd: Handle, data: []u8) -> (int, Errno) {
|
||||
if len(data) == 0 {
|
||||
return 0, ERROR_NONE;
|
||||
}
|
||||
if len(data) == 0 do return 0, ERROR_NONE;
|
||||
|
||||
single_write_length: i32;
|
||||
total_write: i64;
|
||||
length := i64(len(data));
|
||||
|
||||
for total_write < length {
|
||||
remaining := length - total_write;
|
||||
to_read: i32;
|
||||
MAX :: 1<<31-1;
|
||||
if remaining <= MAX {
|
||||
to_read = i32(remaining);
|
||||
} else {
|
||||
to_read = MAX;
|
||||
}
|
||||
e := win32.write_file(win32.Handle(fd), &data[total_write], to_read, &single_write_length, nil);
|
||||
to_write: i32 = min(i32(remaining), MAX);
|
||||
|
||||
e := win32.write_file(win32.Handle(fd), &data[total_write], to_write, &single_write_length, nil);
|
||||
if single_write_length <= 0 || e == win32.FALSE {
|
||||
err := win32.get_last_error();
|
||||
return int(total_write), Errno(e);
|
||||
@@ -140,9 +135,7 @@ write :: proc(fd: Handle, data: []u8) -> (int, Errno) {
|
||||
}
|
||||
|
||||
read :: proc(fd: Handle, data: []u8) -> (int, Errno) {
|
||||
if len(data) == 0 {
|
||||
return 0, ERROR_NONE;
|
||||
}
|
||||
if len(data) == 0 do return 0, ERROR_NONE;
|
||||
|
||||
single_read_length: i32;
|
||||
total_read: i64;
|
||||
@@ -150,13 +143,8 @@ read :: proc(fd: Handle, data: []u8) -> (int, Errno) {
|
||||
|
||||
for total_read < length {
|
||||
remaining := length - total_read;
|
||||
to_read: u32;
|
||||
MAX :: 1<<32-1;
|
||||
if remaining <= MAX {
|
||||
to_read = u32(remaining);
|
||||
} else {
|
||||
to_read = MAX;
|
||||
}
|
||||
to_read: u32 = min(u32(remaining), MAX);
|
||||
|
||||
e := win32.read_file(win32.Handle(fd), &data[total_read], to_read, &single_read_length, nil);
|
||||
if single_read_length <= 0 || e == win32.FALSE {
|
||||
@@ -178,9 +166,8 @@ seek :: proc(fd: Handle, offset: i64, whence: int) -> (i64, Errno) {
|
||||
hi := i32(offset>>32);
|
||||
lo := i32(offset);
|
||||
ft := win32.get_file_type(win32.Handle(fd));
|
||||
if ft == win32.FILE_TYPE_PIPE {
|
||||
return 0, ERROR_FILE_IS_PIPE;
|
||||
}
|
||||
if ft == win32.FILE_TYPE_PIPE do return 0, ERROR_FILE_IS_PIPE;
|
||||
|
||||
dw_ptr := win32.set_file_pointer(win32.Handle(fd), lo, &hi, w);
|
||||
if dw_ptr == win32.INVALID_SET_FILE_POINTER {
|
||||
err := win32.get_last_error();
|
||||
@@ -253,9 +240,8 @@ heap_resize :: proc(ptr: rawptr, new_size: int) -> rawptr {
|
||||
heap_free(ptr);
|
||||
return nil;
|
||||
}
|
||||
if ptr == nil {
|
||||
return heap_alloc(new_size);
|
||||
}
|
||||
if ptr == nil do return heap_alloc(new_size);
|
||||
|
||||
return win32.heap_realloc(win32.get_process_heap(), win32.HEAP_ZERO_MEMORY, ptr, new_size);
|
||||
}
|
||||
heap_free :: proc(ptr: rawptr) {
|
||||
@@ -282,9 +268,8 @@ current_thread_id :: proc() -> int {
|
||||
_alloc_command_line_arguments :: proc() -> []string {
|
||||
alloc_ucs2_to_utf8 :: proc(wstr: ^u16) -> string {
|
||||
wstr_len := 0;
|
||||
for (wstr+wstr_len)^ != 0 {
|
||||
wstr_len++;
|
||||
}
|
||||
for (wstr+wstr_len)^ != 0 do wstr_len++;
|
||||
|
||||
len := 2*wstr_len-1;
|
||||
buf := make([]u8, len+1);
|
||||
str := slice_ptr(wstr, wstr_len+1);
|
||||
@@ -293,22 +278,16 @@ _alloc_command_line_arguments :: proc() -> []string {
|
||||
for str[j] != 0 {
|
||||
match {
|
||||
case str[j] < 0x80:
|
||||
if i+1 > len {
|
||||
return "";
|
||||
}
|
||||
if i+1 > len do return "";
|
||||
buf[i] = u8(str[j]); i++;
|
||||
j++;
|
||||
case str[j] < 0x800:
|
||||
if i+2 > len {
|
||||
return "";
|
||||
}
|
||||
if i+2 > len do return "";
|
||||
buf[i] = u8(0xc0 + (str[j]>>6)); i++;
|
||||
buf[i] = u8(0x80 + (str[j]&0x3f)); i++;
|
||||
j++;
|
||||
case 0xd800 <= str[j] && str[j] < 0xdc00:
|
||||
if i+4 > len {
|
||||
return "";
|
||||
}
|
||||
if i+4 > len do return "";
|
||||
c := rune((str[j] - 0xd800) << 10) + rune((str[j+1]) - 0xdc00) + 0x10000;
|
||||
buf[i] = u8(0xf0 + (c >> 18)); i++;
|
||||
buf[i] = u8(0x80 + ((c >> 12) & 0x3f)); i++;
|
||||
@@ -318,9 +297,7 @@ _alloc_command_line_arguments :: proc() -> []string {
|
||||
case 0xdc00 <= str[j] && str[j] < 0xe000:
|
||||
return "";
|
||||
case:
|
||||
if i+3 > len {
|
||||
return "";
|
||||
}
|
||||
if i+3 > len do return "";
|
||||
buf[i] = 0xe0 + u8 (str[j] >> 12); i++;
|
||||
buf[i] = 0x80 + u8((str[j] >> 6) & 0x3f); i++;
|
||||
buf[i] = 0x80 + u8((str[j] ) & 0x3f); i++;
|
||||
@@ -334,9 +311,7 @@ _alloc_command_line_arguments :: proc() -> []string {
|
||||
arg_count: i32;
|
||||
arg_list_ptr := win32.command_line_to_argv_w(win32.get_command_line_w(), &arg_count);
|
||||
arg_list := make([]string, arg_count);
|
||||
for _, i in arg_list {
|
||||
arg_list[i] = alloc_ucs2_to_utf8((arg_list_ptr+i)^);
|
||||
}
|
||||
for _, i in arg_list do arg_list[i] = alloc_ucs2_to_utf8((arg_list_ptr+i)^);
|
||||
return arg_list;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -68,7 +68,7 @@ GetExtensionsStringARBType :: proc(Hdc) -> ^u8 #cc_c;
|
||||
foreign opengl32 {
|
||||
create_context :: proc(hdc: Hdc) -> Hglrc #link_name "wglCreateContext" ---;
|
||||
make_current :: proc(hdc: Hdc, hglrc: Hglrc) -> Bool #link_name "wglMakeCurrent" ---;
|
||||
get_proc_address :: proc(c_str: ^u8) -> Proc #link_name "wglGetProcAddress" ---;
|
||||
get_proc_address :: proc(c_str: ^u8) -> rawptr #link_name "wglGetProcAddress" ---;
|
||||
delete_context :: proc(hglrc: Hglrc) -> Bool #link_name "wglDeleteContext" ---;
|
||||
copy_context :: proc(src, dst: Hglrc, mask: u32) -> Bool #link_name "wglCopyContext" ---;
|
||||
create_layer_context :: proc(hdc: Hdc, layer_plane: i32) -> Hglrc #link_name "wglCreateLayerContext" ---;
|
||||
|
||||
@@ -144,9 +144,6 @@ PixelFormatDescriptor :: struct #ordered {
|
||||
|
||||
|
||||
|
||||
|
||||
Proc :: proc() #cc_c;
|
||||
|
||||
MAPVK_VK_TO_VSC :: 0;
|
||||
MAPVK_VSC_TO_VK :: 1;
|
||||
MAPVK_VK_TO_CHAR :: 2;
|
||||
@@ -344,7 +341,7 @@ foreign kernel32 {
|
||||
|
||||
load_library_a :: proc(c_str: ^u8) -> Hmodule #cc_std #link_name "LoadLibraryA" ---;
|
||||
free_library :: proc(h: Hmodule) #cc_std #link_name "FreeLibrary" ---;
|
||||
get_proc_address :: proc(h: Hmodule, c_str: ^u8) -> Proc #cc_std #link_name "GetProcAddress" ---;
|
||||
get_proc_address :: proc(h: Hmodule, c_str: ^u8) -> rawptr #cc_std #link_name "GetProcAddress" ---;
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user