mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-04 14:48:47 +00:00
Change precedence order for types e.g. ^T(x) == ^(T(x))
This commit is contained in:
+4
-3
@@ -219,7 +219,7 @@ call_location :: proc() {
|
|||||||
|
|
||||||
explicit_parametric_polymorphic_procedures :: proc() {
|
explicit_parametric_polymorphic_procedures :: proc() {
|
||||||
// This is how `new` is actually implemented, see _preload.odin
|
// This is how `new` is actually implemented, see _preload.odin
|
||||||
alloc_type :: proc(T: type) -> ^T do return ^T(alloc(size_of(T), align_of(T)));
|
alloc_type :: proc(T: type) -> ^T do return cast(^T)alloc(size_of(T), align_of(T));
|
||||||
|
|
||||||
int_ptr := alloc_type(int);
|
int_ptr := alloc_type(int);
|
||||||
defer free(int_ptr);
|
defer free(int_ptr);
|
||||||
@@ -340,7 +340,7 @@ explicit_parametric_polymorphic_procedures :: proc() {
|
|||||||
result.x = x;
|
result.x = x;
|
||||||
result.y = y;
|
result.y = y;
|
||||||
|
|
||||||
return ^T(&result.variant);
|
return cast(^T)&result.variant;
|
||||||
}
|
}
|
||||||
|
|
||||||
entities: [dynamic]^Entity;
|
entities: [dynamic]^Entity;
|
||||||
@@ -386,6 +386,7 @@ implicit_polymorphic_assignment :: proc() {
|
|||||||
|
|
||||||
|
|
||||||
main :: proc() {
|
main :: proc() {
|
||||||
|
/*
|
||||||
foo :: proc(x: i64, y: f32) do fmt.println("#1", x, y);
|
foo :: proc(x: i64, y: f32) do fmt.println("#1", x, y);
|
||||||
foo :: proc(x: type, y: f32) do fmt.println("#2", type_info(x), y);
|
foo :: proc(x: type, y: f32) do fmt.println("#2", type_info(x), y);
|
||||||
foo :: proc(x: type) do fmt.println("#3", type_info(x));
|
foo :: proc(x: type) do fmt.println("#3", type_info(x));
|
||||||
@@ -408,7 +409,7 @@ main :: proc() {
|
|||||||
|
|
||||||
// Command line argument(s)!
|
// Command line argument(s)!
|
||||||
// -opt=0,1,2,3
|
// -opt=0,1,2,3
|
||||||
|
*/
|
||||||
/*
|
/*
|
||||||
program := "+ + * - /";
|
program := "+ + * - /";
|
||||||
accumulator := 0;
|
accumulator := 0;
|
||||||
|
|||||||
+44
-44
@@ -319,8 +319,8 @@ append :: proc(array: ^[]$T, args: ...T) -> int #cc_contextless {
|
|||||||
|
|
||||||
arg_len = min(cap(array)-len(array), arg_len);
|
arg_len = min(cap(array)-len(array), arg_len);
|
||||||
if arg_len > 0 {
|
if arg_len > 0 {
|
||||||
s := ^raw.Slice(array);
|
s := cast(^raw.Slice)array;
|
||||||
data := ^T(s.data);
|
data := cast(^T)s.data;
|
||||||
assert(data != nil);
|
assert(data != nil);
|
||||||
sz :: size_of(T);
|
sz :: size_of(T);
|
||||||
__mem_copy(data + s.len, &args[0], sz*arg_len);
|
__mem_copy(data + s.len, &args[0], sz*arg_len);
|
||||||
@@ -344,8 +344,8 @@ append :: proc(array: ^[dynamic]$T, args: ...T) -> int {
|
|||||||
// TODO(bill): Better error handling for failed reservation
|
// TODO(bill): Better error handling for failed reservation
|
||||||
if !ok do return len(array);
|
if !ok do return len(array);
|
||||||
|
|
||||||
a := ^raw.DynamicArray(array);
|
a := cast(^raw.DynamicArray)array;
|
||||||
data := ^T(a.data);
|
data := cast(^T)a.data;
|
||||||
assert(data != nil);
|
assert(data != nil);
|
||||||
__mem_copy(data + a.len, &args[0], size_of(T) * arg_len);
|
__mem_copy(data + a.len, &args[0], size_of(T) * arg_len);
|
||||||
a.len += arg_len;
|
a.len += arg_len;
|
||||||
@@ -357,7 +357,7 @@ pop :: proc(array: ^[]$T) -> T #cc_contextless {
|
|||||||
if array != nil do return res;
|
if array != nil do return res;
|
||||||
assert(len(array) > 0);
|
assert(len(array) > 0);
|
||||||
res = array[len(array)-1];
|
res = array[len(array)-1];
|
||||||
^raw.Slice(array).len -= 1;
|
(cast(^raw.Slice)array).len -= 1;
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -366,28 +366,28 @@ pop :: proc(array: ^[dynamic]$T) -> T #cc_contextless {
|
|||||||
if array != nil do return res;
|
if array != nil do return res;
|
||||||
assert(len(array) > 0);
|
assert(len(array) > 0);
|
||||||
res = array[len(array)-1];
|
res = array[len(array)-1];
|
||||||
^raw.DynamicArray(array).len -= 1;
|
(cast(^raw.DynamicArray)array).len -= 1;
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
clear :: proc(slice: ^[]$T) #cc_contextless #inline {
|
clear :: proc(slice: ^[]$T) #cc_contextless #inline {
|
||||||
if slice != nil do ^raw.Slice(slice).len = 0;
|
if slice != nil do (cast(^raw.Slice)slice).len = 0;
|
||||||
}
|
}
|
||||||
clear :: proc(array: ^[dynamic]$T) #cc_contextless #inline {
|
clear :: proc(array: ^[dynamic]$T) #cc_contextless #inline {
|
||||||
if array != nil do ^raw.DynamicArray(array).len = 0;
|
if array != nil do (cast(^raw.DynamicArray)array).len = 0;
|
||||||
}
|
}
|
||||||
clear :: proc(m: ^map[$K]$V) #cc_contextless #inline {
|
clear :: proc(m: ^map[$K]$V) #cc_contextless #inline {
|
||||||
if m == nil do return;
|
if m == nil do return;
|
||||||
raw_map := ^raw.DynamicMap(m);
|
raw_map := cast(^raw.DynamicMap)m;
|
||||||
hashes := ^raw.DynamicArray(&raw_map.hashes);
|
hashes := cast(^raw.DynamicArray)&raw_map.hashes;
|
||||||
entries := ^raw.DynamicArray(&raw_map.entries);
|
entries := cast(^raw.DynamicArray)&raw_map.entries;
|
||||||
hashes.len = 0;
|
hashes.len = 0;
|
||||||
entries.len = 0;
|
entries.len = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
reserve :: proc(array: ^[dynamic]$T, capacity: int) -> bool {
|
reserve :: proc(array: ^[dynamic]$T, capacity: int) -> bool {
|
||||||
if array == nil do return false;
|
if array == nil do return false;
|
||||||
a := ^raw.DynamicArray(array);
|
a := cast(^raw.DynamicArray)array;
|
||||||
|
|
||||||
if capacity <= a.cap do return true;
|
if capacity <= a.cap do return true;
|
||||||
|
|
||||||
@@ -410,7 +410,7 @@ reserve :: proc(array: ^[dynamic]$T, capacity: int) -> bool {
|
|||||||
|
|
||||||
|
|
||||||
__get_map_header :: proc(m: ^map[$K]$V) -> __MapHeader #cc_contextless {
|
__get_map_header :: proc(m: ^map[$K]$V) -> __MapHeader #cc_contextless {
|
||||||
header := __MapHeader{m = ^raw.DynamicMap(m)};
|
header := __MapHeader{m = cast(^raw.DynamicMap)m};
|
||||||
Entry :: struct {
|
Entry :: struct {
|
||||||
key: __MapKey;
|
key: __MapKey;
|
||||||
next: int;
|
next: int;
|
||||||
@@ -432,24 +432,24 @@ __get_map_key :: proc(key: $K) -> __MapKey #cc_contextless {
|
|||||||
match _ in ti {
|
match _ in ti {
|
||||||
case TypeInfo.Integer:
|
case TypeInfo.Integer:
|
||||||
match 8*size_of(key) {
|
match 8*size_of(key) {
|
||||||
case 8: map_key.hash = u128( ^u8(&key)^);
|
case 8: map_key.hash = u128((cast( ^u8)&key)^);
|
||||||
case 16: map_key.hash = u128( ^u16(&key)^);
|
case 16: map_key.hash = u128((cast( ^u16)&key)^);
|
||||||
case 32: map_key.hash = u128( ^u32(&key)^);
|
case 32: map_key.hash = u128((cast( ^u32)&key)^);
|
||||||
case 64: map_key.hash = u128( ^u64(&key)^);
|
case 64: map_key.hash = u128((cast( ^u64)&key)^);
|
||||||
case 128: map_key.hash = u128(^u128(&key)^);
|
case 128: map_key.hash = u128((cast(^u128)&key)^);
|
||||||
}
|
}
|
||||||
case TypeInfo.Rune:
|
case TypeInfo.Rune:
|
||||||
map_key.hash = u128(^rune(&key)^);
|
map_key.hash = u128((cast(^rune)&key)^);
|
||||||
case TypeInfo.Pointer:
|
case TypeInfo.Pointer:
|
||||||
map_key.hash = u128(uint(^rawptr(&key)^));
|
map_key.hash = u128(uint((cast(^rawptr)&key)^));
|
||||||
case TypeInfo.Float:
|
case TypeInfo.Float:
|
||||||
match 8*size_of(key) {
|
match 8*size_of(key) {
|
||||||
case 32: map_key.hash = u128(^u32(&key)^);
|
case 32: map_key.hash = u128((cast(^u32)&key)^);
|
||||||
case 64: map_key.hash = u128(^u64(&key)^);
|
case 64: map_key.hash = u128((cast(^u64)&key)^);
|
||||||
case: panic("Unhandled float size");
|
case: panic("Unhandled float size");
|
||||||
}
|
}
|
||||||
case TypeInfo.String:
|
case TypeInfo.String:
|
||||||
str := ^string(&key)^;
|
str := (cast(^string)&key)^;
|
||||||
map_key.hash = __default_hash_string(str);
|
map_key.hash = __default_hash_string(str);
|
||||||
map_key.str = str;
|
map_key.str = str;
|
||||||
case:
|
case:
|
||||||
@@ -468,12 +468,12 @@ delete :: proc(m: ^map[$K]$V, key: K) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
new :: proc(T: type) -> ^T #inline do return ^T(alloc(size_of(T), align_of(T)));
|
new :: proc(T: type) -> ^T #inline do return cast(^T)alloc(size_of(T), align_of(T));
|
||||||
|
|
||||||
free :: proc(ptr: rawptr) do free_ptr(ptr);
|
free :: proc(ptr: rawptr) do free_ptr(ptr);
|
||||||
free :: proc(str: string) do free_ptr(^raw.String(&str).data);
|
free :: proc(str: string) do free_ptr((cast(^raw.String)&str).data);
|
||||||
free :: proc(array: [dynamic]$T) do free_ptr(^raw.DynamicArray(&array).data);
|
free :: proc(array: [dynamic]$T) do free_ptr((cast(^raw.DynamicArray)&array).data);
|
||||||
free :: proc(slice: []$T) do free_ptr(^raw.Slice(&slice).data);
|
free :: proc(slice: []$T) do free_ptr((cast(^raw.Slice)&slice).data);
|
||||||
free :: proc(m: map[$K]$V) {
|
free :: proc(m: map[$K]$V) {
|
||||||
raw := ^raw.DynamicMap(&m);
|
raw := ^raw.DynamicMap(&m);
|
||||||
free(raw.hashes);
|
free(raw.hashes);
|
||||||
@@ -688,7 +688,7 @@ __abs_complex128 :: proc(x: complex128) -> f64 #inline #cc_contextless {
|
|||||||
|
|
||||||
|
|
||||||
__dynamic_array_make :: proc(array_: rawptr, elem_size, elem_align: int, len, cap: int) {
|
__dynamic_array_make :: proc(array_: rawptr, elem_size, elem_align: int, len, cap: int) {
|
||||||
array := ^raw.DynamicArray(array_);
|
array := cast(^raw.DynamicArray)array_;
|
||||||
array.allocator = context.allocator;
|
array.allocator = context.allocator;
|
||||||
assert(array.allocator.procedure != nil);
|
assert(array.allocator.procedure != nil);
|
||||||
|
|
||||||
@@ -699,7 +699,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) -> bool {
|
__dynamic_array_reserve :: proc(array_: rawptr, elem_size, elem_align: int, cap: int) -> bool {
|
||||||
array := ^raw.DynamicArray(array_);
|
array := cast(^raw.DynamicArray)array_;
|
||||||
|
|
||||||
if cap <= array.cap do return true;
|
if cap <= array.cap do return true;
|
||||||
|
|
||||||
@@ -721,7 +721,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) -> bool {
|
__dynamic_array_resize :: proc(array_: rawptr, elem_size, elem_align: int, len: int) -> bool {
|
||||||
array := ^raw.DynamicArray(array_);
|
array := cast(^raw.DynamicArray)array_;
|
||||||
|
|
||||||
ok := __dynamic_array_reserve(array_, elem_size, elem_align, len);
|
ok := __dynamic_array_reserve(array_, elem_size, elem_align, len);
|
||||||
if ok do array.len = len;
|
if ok do array.len = len;
|
||||||
@@ -731,7 +731,7 @@ __dynamic_array_resize :: proc(array_: rawptr, elem_size, elem_align: int, len:
|
|||||||
|
|
||||||
__dynamic_array_append :: proc(array_: rawptr, elem_size, elem_align: int,
|
__dynamic_array_append :: proc(array_: rawptr, elem_size, elem_align: int,
|
||||||
items: rawptr, item_count: int) -> int {
|
items: rawptr, item_count: int) -> int {
|
||||||
array := ^raw.DynamicArray(array_);
|
array := cast(^raw.DynamicArray)array_;
|
||||||
|
|
||||||
if items == nil do return 0;
|
if items == nil do return 0;
|
||||||
if item_count <= 0 do return 0;
|
if item_count <= 0 do return 0;
|
||||||
@@ -745,7 +745,7 @@ __dynamic_array_append :: proc(array_: rawptr, elem_size, elem_align: int,
|
|||||||
// TODO(bill): Better error handling for failed reservation
|
// TODO(bill): Better error handling for failed reservation
|
||||||
if !ok do return array.len;
|
if !ok do return array.len;
|
||||||
|
|
||||||
data := ^u8(array.data);
|
data := cast(^u8)array.data;
|
||||||
assert(data != nil);
|
assert(data != nil);
|
||||||
__mem_copy(data + (elem_size*array.len), items, elem_size * item_count);
|
__mem_copy(data + (elem_size*array.len), items, elem_size * item_count);
|
||||||
array.len += item_count;
|
array.len += item_count;
|
||||||
@@ -753,7 +753,7 @@ __dynamic_array_append :: proc(array_: rawptr, elem_size, elem_align: int,
|
|||||||
}
|
}
|
||||||
|
|
||||||
__dynamic_array_append_nothing :: proc(array_: rawptr, elem_size, elem_align: int) -> int {
|
__dynamic_array_append_nothing :: proc(array_: rawptr, elem_size, elem_align: int) -> int {
|
||||||
array := ^raw.DynamicArray(array_);
|
array := cast(^raw.DynamicArray)array_;
|
||||||
|
|
||||||
ok := true;
|
ok := true;
|
||||||
if array.cap <= array.len+1 {
|
if array.cap <= array.len+1 {
|
||||||
@@ -763,7 +763,7 @@ __dynamic_array_append_nothing :: proc(array_: rawptr, elem_size, elem_align: in
|
|||||||
// TODO(bill): Better error handling for failed reservation
|
// TODO(bill): Better error handling for failed reservation
|
||||||
if !ok do return array.len;
|
if !ok do return array.len;
|
||||||
|
|
||||||
data := ^u8(array.data);
|
data := cast(^u8)array.data;
|
||||||
assert(data != nil);
|
assert(data != nil);
|
||||||
__mem_zero(data + (elem_size*array.len), elem_size);
|
__mem_zero(data + (elem_size*array.len), elem_size);
|
||||||
array.len++;
|
array.len++;
|
||||||
@@ -772,7 +772,7 @@ __dynamic_array_append_nothing :: proc(array_: rawptr, elem_size, elem_align: in
|
|||||||
|
|
||||||
__slice_append :: proc(slice_: rawptr, elem_size, elem_align: int,
|
__slice_append :: proc(slice_: rawptr, elem_size, elem_align: int,
|
||||||
items: rawptr, item_count: int) -> int {
|
items: rawptr, item_count: int) -> int {
|
||||||
slice := ^raw.Slice(slice_);
|
slice := cast(^raw.Slice)slice_;
|
||||||
|
|
||||||
if item_count <= 0 || items == nil {
|
if item_count <= 0 || items == nil {
|
||||||
return slice.len;
|
return slice.len;
|
||||||
@@ -780,7 +780,7 @@ __slice_append :: proc(slice_: rawptr, elem_size, elem_align: int,
|
|||||||
|
|
||||||
item_count = min(slice.cap-slice.len, item_count);
|
item_count = min(slice.cap-slice.len, item_count);
|
||||||
if item_count > 0 {
|
if item_count > 0 {
|
||||||
data := ^u8(slice.data);
|
data := cast(^u8)slice.data;
|
||||||
assert(data != nil);
|
assert(data != nil);
|
||||||
__mem_copy(data + (elem_size*slice.len), items, elem_size * item_count);
|
__mem_copy(data + (elem_size*slice.len), items, elem_size * item_count);
|
||||||
slice.len += item_count;
|
slice.len += item_count;
|
||||||
@@ -800,7 +800,7 @@ __default_hash :: proc(data: []u8) -> u128 {
|
|||||||
}
|
}
|
||||||
return fnv128a(data);
|
return fnv128a(data);
|
||||||
}
|
}
|
||||||
__default_hash_string :: proc(s: string) -> u128 do return __default_hash([]u8(s));
|
__default_hash_string :: proc(s: string) -> u128 do return __default_hash(cast([]u8)s);
|
||||||
|
|
||||||
__dynamic_map_reserve :: proc(using header: __MapHeader, cap: int) {
|
__dynamic_map_reserve :: proc(using header: __MapHeader, cap: int) {
|
||||||
__dynamic_array_reserve(&m.hashes, size_of(int), align_of(int), cap);
|
__dynamic_array_reserve(&m.hashes, size_of(int), align_of(int), cap);
|
||||||
@@ -812,8 +812,8 @@ __dynamic_map_rehash :: proc(using header: __MapHeader, new_count: int) {
|
|||||||
nm: raw.DynamicMap;
|
nm: raw.DynamicMap;
|
||||||
new_header.m = &nm;
|
new_header.m = &nm;
|
||||||
|
|
||||||
header_hashes := ^raw.DynamicArray(&header.m.hashes);
|
header_hashes := cast(^raw.DynamicArray)&header.m.hashes;
|
||||||
nm_hashes := ^raw.DynamicArray(&nm.hashes);
|
nm_hashes := cast(^raw.DynamicArray)&nm.hashes;
|
||||||
|
|
||||||
__dynamic_array_resize(nm_hashes, size_of(int), align_of(int), new_count);
|
__dynamic_array_resize(nm_hashes, size_of(int), align_of(int), new_count);
|
||||||
__dynamic_array_reserve(&nm.entries, entry_size, entry_align, m.entries.len);
|
__dynamic_array_reserve(&nm.entries, entry_size, entry_align, m.entries.len);
|
||||||
@@ -823,7 +823,7 @@ __dynamic_map_rehash :: proc(using header: __MapHeader, new_count: int) {
|
|||||||
if len(nm.hashes) == 0 do __dynamic_map_grow(new_header);
|
if len(nm.hashes) == 0 do __dynamic_map_grow(new_header);
|
||||||
|
|
||||||
entry_header := __dynamic_map_get_entry(header, i);
|
entry_header := __dynamic_map_get_entry(header, i);
|
||||||
data := ^u8(entry_header);
|
data := cast(^u8)entry_header;
|
||||||
|
|
||||||
fr := __dynamic_map_find(new_header, entry_header.key);
|
fr := __dynamic_map_find(new_header, entry_header.key);
|
||||||
j := __dynamic_map_add_entry(new_header, entry_header.key);
|
j := __dynamic_map_add_entry(new_header, entry_header.key);
|
||||||
@@ -836,7 +836,7 @@ __dynamic_map_rehash :: proc(using header: __MapHeader, new_count: int) {
|
|||||||
|
|
||||||
e := __dynamic_map_get_entry(new_header, j);
|
e := __dynamic_map_get_entry(new_header, j);
|
||||||
e.next = fr.entry_index;
|
e.next = fr.entry_index;
|
||||||
ndata := ^u8(e);
|
ndata := cast(^u8)e;
|
||||||
__mem_copy(ndata+value_offset, data+value_offset, value_size);
|
__mem_copy(ndata+value_offset, data+value_offset, value_size);
|
||||||
|
|
||||||
if __dynamic_map_full(new_header) do __dynamic_map_grow(new_header);
|
if __dynamic_map_full(new_header) do __dynamic_map_grow(new_header);
|
||||||
@@ -849,7 +849,7 @@ __dynamic_map_rehash :: proc(using header: __MapHeader, new_count: int) {
|
|||||||
__dynamic_map_get :: proc(h: __MapHeader, key: __MapKey) -> rawptr {
|
__dynamic_map_get :: proc(h: __MapHeader, key: __MapKey) -> rawptr {
|
||||||
index := __dynamic_map_find(h, key).entry_index;
|
index := __dynamic_map_find(h, key).entry_index;
|
||||||
if index >= 0 {
|
if index >= 0 {
|
||||||
data := ^u8(__dynamic_map_get_entry(h, index));
|
data := cast(^u8)__dynamic_map_get_entry(h, index);
|
||||||
return data + h.value_offset;
|
return data + h.value_offset;
|
||||||
}
|
}
|
||||||
return nil;
|
return nil;
|
||||||
@@ -880,7 +880,7 @@ __dynamic_map_set :: proc(using h: __MapHeader, key: __MapKey, value: rawptr) {
|
|||||||
{
|
{
|
||||||
e := __dynamic_map_get_entry(h, index);
|
e := __dynamic_map_get_entry(h, index);
|
||||||
e.key = key;
|
e.key = key;
|
||||||
val := ^u8(e) + value_offset;
|
val := cast(^u8)e + value_offset;
|
||||||
__mem_copy(val, value, value_size);
|
__mem_copy(val, value, value_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -942,7 +942,7 @@ __dynamic_map_delete :: proc(using h: __MapHeader, key: __MapKey) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
__dynamic_map_get_entry :: proc(using h: __MapHeader, index: int) -> ^__MapEntryHeader {
|
__dynamic_map_get_entry :: proc(using h: __MapHeader, index: int) -> ^__MapEntryHeader {
|
||||||
return ^__MapEntryHeader(^u8(m.entries.data) + index*entry_size);
|
return cast(^__MapEntryHeader)(cast(^u8)m.entries.data + index*entry_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
__dynamic_map_erase :: proc(using h: __MapHeader, fr: __MapFindResult) {
|
__dynamic_map_erase :: proc(using h: __MapHeader, fr: __MapFindResult) {
|
||||||
|
|||||||
+14
-14
@@ -55,7 +55,7 @@ to_string :: proc(buf: StringBuffer) -> string {
|
|||||||
|
|
||||||
|
|
||||||
write_string :: proc(buf: ^StringBuffer, s: string) {
|
write_string :: proc(buf: ^StringBuffer, s: string) {
|
||||||
write_bytes(buf, []u8(s));
|
write_bytes(buf, cast([]u8)s);
|
||||||
}
|
}
|
||||||
write_bytes :: proc(buf: ^StringBuffer, data: []u8) {
|
write_bytes :: proc(buf: ^StringBuffer, data: []u8) {
|
||||||
match b in buf {
|
match b in buf {
|
||||||
@@ -747,7 +747,7 @@ fmt_value :: proc(fi: ^FmtInfo, v: any, verb: rune) {
|
|||||||
if t := b.types[i]; types.is_any(t) {
|
if t := b.types[i]; types.is_any(t) {
|
||||||
write_string(fi.buf, "any{}");
|
write_string(fi.buf, "any{}");
|
||||||
} else {
|
} else {
|
||||||
data := ^u8(v.data) + b.offsets[i];
|
data := cast(^u8)v.data + b.offsets[i];
|
||||||
fmt_arg(fi, any{rawptr(data), t}, 'v');
|
fmt_arg(fi, any{rawptr(data), t}, 'v');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -766,9 +766,9 @@ fmt_value :: proc(fi: ^FmtInfo, v: any, verb: rune) {
|
|||||||
|
|
||||||
case Pointer:
|
case Pointer:
|
||||||
if v.type_info == type_info(^TypeInfo) {
|
if v.type_info == type_info(^TypeInfo) {
|
||||||
write_type(fi.buf, ^^TypeInfo(v.data)^);
|
write_type(fi.buf, (cast(^^TypeInfo)v.data)^);
|
||||||
} else {
|
} else {
|
||||||
fmt_pointer(fi, ^rawptr(v.data)^, verb);
|
fmt_pointer(fi, (cast(^rawptr)v.data)^, verb);
|
||||||
}
|
}
|
||||||
|
|
||||||
case Atomic:
|
case Atomic:
|
||||||
@@ -780,25 +780,25 @@ fmt_value :: proc(fi: ^FmtInfo, v: any, verb: rune) {
|
|||||||
for i in 0..info.count {
|
for i in 0..info.count {
|
||||||
if i > 0 do write_string(fi.buf, ", ");
|
if i > 0 do write_string(fi.buf, ", ");
|
||||||
|
|
||||||
data := ^u8(v.data) + i*info.elem_size;
|
data := cast(^u8)v.data + i*info.elem_size;
|
||||||
fmt_arg(fi, any{rawptr(data), info.elem}, verb);
|
fmt_arg(fi, any{rawptr(data), info.elem}, verb);
|
||||||
}
|
}
|
||||||
|
|
||||||
case DynamicArray:
|
case DynamicArray:
|
||||||
write_byte(fi.buf, '[');
|
write_byte(fi.buf, '[');
|
||||||
defer write_byte(fi.buf, ']');
|
defer write_byte(fi.buf, ']');
|
||||||
array := ^raw.DynamicArray(v.data);
|
array := cast(^raw.DynamicArray)v.data;
|
||||||
for i in 0..array.len {
|
for i in 0..array.len {
|
||||||
if i > 0 do write_string(fi.buf, ", ");
|
if i > 0 do write_string(fi.buf, ", ");
|
||||||
|
|
||||||
data := ^u8(array.data) + i*info.elem_size;
|
data := cast(^u8)array.data + i*info.elem_size;
|
||||||
fmt_arg(fi, any{rawptr(data), info.elem}, verb);
|
fmt_arg(fi, any{rawptr(data), info.elem}, verb);
|
||||||
}
|
}
|
||||||
|
|
||||||
case Slice:
|
case Slice:
|
||||||
write_byte(fi.buf, '[');
|
write_byte(fi.buf, '[');
|
||||||
defer write_byte(fi.buf, ']');
|
defer write_byte(fi.buf, ']');
|
||||||
slice := ^[]u8(v.data);
|
slice := cast(^[]u8)v.data;
|
||||||
for _, i in slice {
|
for _, i in slice {
|
||||||
if i > 0 do write_string(fi.buf, ", ");
|
if i > 0 do write_string(fi.buf, ", ");
|
||||||
|
|
||||||
@@ -813,7 +813,7 @@ fmt_value :: proc(fi: ^FmtInfo, v: any, verb: rune) {
|
|||||||
for i in 0..info.count {
|
for i in 0..info.count {
|
||||||
if i > 0 do write_string(fi.buf, ", ");
|
if i > 0 do write_string(fi.buf, ", ");
|
||||||
|
|
||||||
data := ^u8(v.data) + i*info.elem_size;
|
data := cast(^u8)v.data + i*info.elem_size;
|
||||||
fmt_value(fi, any{rawptr(data), info.elem}, verb);
|
fmt_value(fi, any{rawptr(data), info.elem}, verb);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -826,7 +826,7 @@ fmt_value :: proc(fi: ^FmtInfo, v: any, verb: rune) {
|
|||||||
write_string(fi.buf, "map[");
|
write_string(fi.buf, "map[");
|
||||||
defer write_byte(fi.buf, ']');
|
defer write_byte(fi.buf, ']');
|
||||||
|
|
||||||
entries := &(^raw.DynamicMap(v.data).entries);
|
entries := &((cast(^raw.DynamicMap)v.data).entries);
|
||||||
gs := type_info_base(info.generated_struct).variant.(Struct);
|
gs := type_info_base(info.generated_struct).variant.(Struct);
|
||||||
ed := type_info_base(gs.types[1]).variant.(DynamicArray);
|
ed := type_info_base(gs.types[1]).variant.(DynamicArray);
|
||||||
entry_type := ed.elem.variant.(Struct);
|
entry_type := ed.elem.variant.(Struct);
|
||||||
@@ -835,8 +835,8 @@ fmt_value :: proc(fi: ^FmtInfo, v: any, verb: rune) {
|
|||||||
for i in 0..entries.len {
|
for i in 0..entries.len {
|
||||||
if i > 0 do write_string(fi.buf, ", ");
|
if i > 0 do write_string(fi.buf, ", ");
|
||||||
|
|
||||||
data := ^u8(entries.data) + i*entry_size;
|
data := cast(^u8)entries.data + i*entry_size;
|
||||||
header := ^__MapEntryHeader(data);
|
header := cast(^__MapEntryHeader)data;
|
||||||
|
|
||||||
if types.is_string(info.key) {
|
if types.is_string(info.key) {
|
||||||
write_string(fi.buf, header.key.str);
|
write_string(fi.buf, header.key.str);
|
||||||
@@ -866,7 +866,7 @@ fmt_value :: proc(fi: ^FmtInfo, v: any, verb: rune) {
|
|||||||
if t := info.types[i]; types.is_any(t) {
|
if t := info.types[i]; types.is_any(t) {
|
||||||
write_string(fi.buf, "any{}");
|
write_string(fi.buf, "any{}");
|
||||||
} else {
|
} else {
|
||||||
data := ^u8(v.data) + info.offsets[i];
|
data := cast(^u8)v.data + info.offsets[i];
|
||||||
fmt_arg(fi, any{rawptr(data), t}, 'v');
|
fmt_arg(fi, any{rawptr(data), t}, 'v');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -883,7 +883,7 @@ fmt_value :: proc(fi: ^FmtInfo, v: any, verb: rune) {
|
|||||||
case Procedure:
|
case Procedure:
|
||||||
write_type(fi.buf, v.type_info);
|
write_type(fi.buf, v.type_info);
|
||||||
write_string(fi.buf, " @ ");
|
write_string(fi.buf, " @ ");
|
||||||
fmt_pointer(fi, ^rawptr(v.data)^, 'p');
|
fmt_pointer(fi, (cast(^rawptr)v.data)^, 'p');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
-3
@@ -57,7 +57,7 @@ murmur32 :: proc(data: []u8) -> u32 {
|
|||||||
p1 := p + 4*nblocks;
|
p1 := p + 4*nblocks;
|
||||||
|
|
||||||
for ; p < p1; p += 4 {
|
for ; p < p1; p += 4 {
|
||||||
k1 := ^u32(p)^;
|
k1 := (cast(^u32)p)^;
|
||||||
|
|
||||||
k1 *= c1_32;
|
k1 *= c1_32;
|
||||||
k1 = (k1 << 15) | (k1 >> 17);
|
k1 = (k1 << 15) | (k1 >> 17);
|
||||||
@@ -104,7 +104,7 @@ murmur64 :: proc(data: []u8) -> u64 {
|
|||||||
r :: 47;
|
r :: 47;
|
||||||
|
|
||||||
h: u64 = SEED ~ (u64(len(data)) * m);
|
h: u64 = SEED ~ (u64(len(data)) * m);
|
||||||
data64 := mem.slice_ptr(^u64(&data[0]), len(data)/size_of(u64));
|
data64 := mem.slice_ptr(cast(^u64)&data[0], len(data)/size_of(u64));
|
||||||
|
|
||||||
for _, i in data64 {
|
for _, i in data64 {
|
||||||
k := data64[i];
|
k := data64[i];
|
||||||
@@ -140,7 +140,7 @@ murmur64 :: proc(data: []u8) -> u64 {
|
|||||||
|
|
||||||
h1 := u32(SEED) ~ u32(len(data));
|
h1 := u32(SEED) ~ u32(len(data));
|
||||||
h2 := u32(SEED) >> 32;
|
h2 := u32(SEED) >> 32;
|
||||||
data32 := mem.slice_ptr(^u32(&data[0]), len(data)/size_of(u32));
|
data32 := mem.slice_ptr(cast(^u32)&data[0], len(data)/size_of(u32));
|
||||||
len := len(data);
|
len := len(data);
|
||||||
i := 0;
|
i := 0;
|
||||||
|
|
||||||
|
|||||||
+8
-8
@@ -29,19 +29,19 @@ compare :: proc(a, b: []u8) -> int #cc_contextless {
|
|||||||
slice_ptr :: proc(ptr: ^$T, len: int) -> []T #cc_contextless {
|
slice_ptr :: proc(ptr: ^$T, len: int) -> []T #cc_contextless {
|
||||||
assert(len >= 0);
|
assert(len >= 0);
|
||||||
slice := raw.Slice{data = ptr, len = len, cap = len};
|
slice := raw.Slice{data = ptr, len = len, cap = len};
|
||||||
return ^[]T(&slice)^;
|
return (cast(^[]T)&slice)^;
|
||||||
}
|
}
|
||||||
slice_ptr :: proc(ptr: ^$T, len, cap: int) -> []T #cc_contextless {
|
slice_ptr :: proc(ptr: ^$T, len, cap: int) -> []T #cc_contextless {
|
||||||
assert(0 <= len && len <= cap);
|
assert(0 <= len && len <= cap);
|
||||||
slice := raw.Slice{data = ptr, len = len, cap = cap};
|
slice := raw.Slice{data = ptr, len = len, cap = cap};
|
||||||
return ^[]T(&slice)^;
|
return (cast(^[]T)&slice)^;
|
||||||
}
|
}
|
||||||
|
|
||||||
slice_to_bytes :: proc(slice: []$T) -> []u8 #cc_contextless {
|
slice_to_bytes :: proc(slice: []$T) -> []u8 #cc_contextless {
|
||||||
s := ^raw.Slice(&slice);
|
s := cast(^raw.Slice)&slice;
|
||||||
s.len *= size_of(T);
|
s.len *= size_of(T);
|
||||||
s.cap *= size_of(T);
|
s.cap *= size_of(T);
|
||||||
return ^[]u8(s)^;
|
return (cast(^[]u8)s)^;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -73,7 +73,7 @@ AllocationHeader :: struct {
|
|||||||
|
|
||||||
allocation_header_fill :: proc(header: ^AllocationHeader, data: rawptr, size: int) {
|
allocation_header_fill :: proc(header: ^AllocationHeader, data: rawptr, size: int) {
|
||||||
header.size = size;
|
header.size = size;
|
||||||
ptr := ^int(header+1);
|
ptr := cast(^int)(header+1);
|
||||||
|
|
||||||
for i := 0; rawptr(ptr) < data; i++ {
|
for i := 0; rawptr(ptr) < data; i++ {
|
||||||
(ptr+i)^ = -1;
|
(ptr+i)^ = -1;
|
||||||
@@ -81,9 +81,9 @@ allocation_header_fill :: proc(header: ^AllocationHeader, data: rawptr, size: in
|
|||||||
}
|
}
|
||||||
allocation_header :: proc(data: rawptr) -> ^AllocationHeader {
|
allocation_header :: proc(data: rawptr) -> ^AllocationHeader {
|
||||||
if data == nil do return nil;
|
if data == nil do return nil;
|
||||||
p := ^int(data);
|
p := cast(^int)data;
|
||||||
for (p-1)^ == -1 do p = (p-1);
|
for (p-1)^ == -1 do p = (p-1);
|
||||||
return ^AllocationHeader(p-1);
|
return cast(^AllocationHeader)(p-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -141,7 +141,7 @@ arena_allocator_proc :: proc(allocator_data: rawptr, mode: Allocator.Mode,
|
|||||||
size, alignment: int,
|
size, alignment: int,
|
||||||
old_memory: rawptr, old_size: int, flags: u64) -> rawptr {
|
old_memory: rawptr, old_size: int, flags: u64) -> rawptr {
|
||||||
using Allocator.Mode;
|
using Allocator.Mode;
|
||||||
arena := ^Arena(allocator_data);
|
arena := cast(^Arena)allocator_data;
|
||||||
|
|
||||||
match mode {
|
match mode {
|
||||||
case Alloc:
|
case Alloc:
|
||||||
|
|||||||
+1
-1
@@ -120,7 +120,7 @@ get_proc_address :: proc(name: string) -> rawptr {
|
|||||||
|
|
||||||
init :: proc() {
|
init :: proc() {
|
||||||
set_proc_address :: proc(p: rawptr, name: string) #inline {
|
set_proc_address :: proc(p: rawptr, name: string) #inline {
|
||||||
x := ^rawptr(p);
|
x := cast(^rawptr)p;
|
||||||
x^ = get_proc_address(name);
|
x^ = get_proc_address(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -5,7 +5,7 @@ import_load (
|
|||||||
)
|
)
|
||||||
|
|
||||||
write_string :: proc(fd: Handle, str: string) -> (int, Errno) {
|
write_string :: proc(fd: Handle, str: string) -> (int, Errno) {
|
||||||
return write(fd, []u8(str));
|
return write(fd, cast([]u8)str);
|
||||||
}
|
}
|
||||||
|
|
||||||
read_entire_file :: proc(name: string) -> ([]u8, bool) {
|
read_entire_file :: proc(name: string) -> ([]u8, bool) {
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ open :: proc(path: string, mode: int = O_RDONLY, perm: u32 = 0) -> (Handle, Errn
|
|||||||
}
|
}
|
||||||
|
|
||||||
buf: [300]u8;
|
buf: [300]u8;
|
||||||
copy(buf[..], []u8(path));
|
copy(buf[..], cast([]u8)path);
|
||||||
|
|
||||||
handle := Handle(win32.create_file_a(&buf[0], access, share_mode, sa, create_mode, win32.FILE_ATTRIBUTE_NORMAL, nil));
|
handle := Handle(win32.create_file_a(&buf[0], access, share_mode, sa, create_mode, win32.FILE_ATTRIBUTE_NORMAL, nil));
|
||||||
if handle != INVALID_HANDLE do return handle, ERROR_NONE;
|
if handle != INVALID_HANDLE do return handle, ERROR_NONE;
|
||||||
@@ -217,7 +217,7 @@ last_write_time_by_name :: proc(name: string) -> FileTime {
|
|||||||
|
|
||||||
assert(len(buf) > len(name));
|
assert(len(buf) > len(name));
|
||||||
|
|
||||||
copy(buf[..], []u8(name));
|
copy(buf[..], cast([]u8)name);
|
||||||
|
|
||||||
if win32.get_file_attributes_ex_a(&buf[0], win32.GetFileExInfoStandard, &data) != 0 {
|
if win32.get_file_attributes_ex_a(&buf[0], win32.GetFileExInfoStandard, &data) != 0 {
|
||||||
last_write_time = data.last_write_time;
|
last_write_time = data.last_write_time;
|
||||||
|
|||||||
+2
-2
@@ -191,7 +191,7 @@ parse_f64 :: proc(s: string) -> f64 {
|
|||||||
|
|
||||||
append_bool :: proc(buf: []u8, b: bool) -> string {
|
append_bool :: proc(buf: []u8, b: bool) -> string {
|
||||||
s := b ? "true" : "false";
|
s := b ? "true" : "false";
|
||||||
append(&buf, ...[]u8(s));
|
append(&buf, ...cast([]u8)s);
|
||||||
return string(buf);
|
return string(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -257,7 +257,7 @@ generic_ftoa :: proc(buf: []u8, val: f64, fmt: u8, prec, bit_size: int) -> []u8
|
|||||||
} else {
|
} else {
|
||||||
s = "+Inf";
|
s = "+Inf";
|
||||||
}
|
}
|
||||||
append(&buf, ...[]u8(s));
|
append(&buf, ...cast([]u8)s);
|
||||||
return buf;
|
return buf;
|
||||||
|
|
||||||
case 0: // denormalized
|
case 0: // denormalized
|
||||||
|
|||||||
+2
-2
@@ -2,14 +2,14 @@ import "mem.odin";
|
|||||||
|
|
||||||
new_string :: proc(s: string) -> string {
|
new_string :: proc(s: string) -> string {
|
||||||
c := make([]u8, len(s)+1);
|
c := make([]u8, len(s)+1);
|
||||||
copy(c, []u8(s));
|
copy(c, cast([]u8)s);
|
||||||
c[len(s)] = 0;
|
c[len(s)] = 0;
|
||||||
return string(c[..len(s)]);
|
return string(c[..len(s)]);
|
||||||
}
|
}
|
||||||
|
|
||||||
new_c_string :: proc(s: string) -> ^u8 {
|
new_c_string :: proc(s: string) -> ^u8 {
|
||||||
c := make([]u8, len(s)+1);
|
c := make([]u8, len(s)+1);
|
||||||
copy(c, []u8(s));
|
copy(c, cast([]u8)s);
|
||||||
c[len(s)] = 0;
|
c[len(s)] = 0;
|
||||||
return &c[0];
|
return &c[0];
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -92,7 +92,7 @@ encode_rune :: proc(r: rune) -> ([4]u8, int) {
|
|||||||
return buf, 4;
|
return buf, 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
decode_rune :: proc(s: string) -> (rune, int) #inline { return decode_rune([]u8(s)); }
|
decode_rune :: proc(s: string) -> (rune, int) #inline { return decode_rune(cast([]u8)s); }
|
||||||
decode_rune :: proc(s: []u8) -> (rune, int) {
|
decode_rune :: proc(s: []u8) -> (rune, int) {
|
||||||
n := len(s);
|
n := len(s);
|
||||||
if n < 1 {
|
if n < 1 {
|
||||||
@@ -132,7 +132,7 @@ decode_rune :: proc(s: []u8) -> (rune, int) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
decode_last_rune :: proc(s: string) -> (rune, int) #inline { return decode_last_rune([]u8(s)); }
|
decode_last_rune :: proc(s: string) -> (rune, int) #inline { return decode_last_rune(cast([]u8)s); }
|
||||||
decode_last_rune :: proc(s: []u8) -> (rune, int) {
|
decode_last_rune :: proc(s: []u8) -> (rune, int) {
|
||||||
r: rune;
|
r: rune;
|
||||||
size: int;
|
size: int;
|
||||||
@@ -217,7 +217,7 @@ valid_string :: proc(s: string) -> bool {
|
|||||||
|
|
||||||
rune_start :: proc(b: u8) -> bool #inline { return b&0xc0 != 0x80; }
|
rune_start :: proc(b: u8) -> bool #inline { return b&0xc0 != 0x80; }
|
||||||
|
|
||||||
rune_count :: proc(s: string) -> int #inline { return rune_count([]u8(s)); }
|
rune_count :: proc(s: string) -> int #inline { return rune_count(cast([]u8)s); }
|
||||||
rune_count :: proc(s: []u8) -> int {
|
rune_count :: proc(s: []u8) -> int {
|
||||||
count := 0;
|
count := 0;
|
||||||
n := len(s);
|
n := len(s);
|
||||||
|
|||||||
+1
-1
@@ -365,7 +365,7 @@ void init_entity_foreign_library(Checker *c, Entity *e) {
|
|||||||
String name = ident->Ident.token.string;
|
String name = ident->Ident.token.string;
|
||||||
Entity *found = scope_lookup_entity(c->context.scope, name);
|
Entity *found = scope_lookup_entity(c->context.scope, name);
|
||||||
if (found == nullptr) {
|
if (found == nullptr) {
|
||||||
if (name == "_") {
|
if (is_blank_ident(name)) {
|
||||||
error(ident, "`_` cannot be used as a value type");
|
error(ident, "`_` cannot be used as a value type");
|
||||||
} else {
|
} else {
|
||||||
error(ident, "Undeclared name: %.*s", LIT(name));
|
error(ident, "Undeclared name: %.*s", LIT(name));
|
||||||
|
|||||||
+13
-15
@@ -823,7 +823,7 @@ void check_record_field_decl(Checker *c, AstNode *decl, Array<Entity *> *fields,
|
|||||||
|
|
||||||
Entity *e = make_entity_field(c->allocator, c->context.scope, name_token, type, is_using, cast(i32)fields->count);
|
Entity *e = make_entity_field(c->allocator, c->context.scope, name_token, type, is_using, cast(i32)fields->count);
|
||||||
e->identifier = name;
|
e->identifier = name;
|
||||||
if (name_token.string == "_") {
|
if (is_blank_ident(name_token)) {
|
||||||
array_add(fields, e);
|
array_add(fields, e);
|
||||||
} else if (name_token.string == "__tag") {
|
} else if (name_token.string == "__tag") {
|
||||||
error(name, "`__tag` is a reserved identifier for fields");
|
error(name, "`__tag` is a reserved identifier for fields");
|
||||||
@@ -1223,7 +1223,7 @@ void check_enum_type(Checker *c, Type *enum_type, Type *named_type, AstNode *nod
|
|||||||
|
|
||||||
|
|
||||||
// NOTE(bill): Skip blank identifiers
|
// NOTE(bill): Skip blank identifiers
|
||||||
if (name == "_") {
|
if (is_blank_ident(name)) {
|
||||||
continue;
|
continue;
|
||||||
} else if (name == "count") {
|
} else if (name == "count") {
|
||||||
error(field, "`count` is a reserved identifier for enumerations");
|
error(field, "`count` is a reserved identifier for enumerations");
|
||||||
@@ -1331,7 +1331,7 @@ void check_bit_field_type(Checker *c, Type *bit_field_type, Type *named_type, As
|
|||||||
e->flags |= EntityFlag_BitFieldValue;
|
e->flags |= EntityFlag_BitFieldValue;
|
||||||
|
|
||||||
HashKey key = hash_string(name);
|
HashKey key = hash_string(name);
|
||||||
if (name != "_" &&
|
if (!is_blank_ident(name) &&
|
||||||
map_get(&entity_map, key) != nullptr) {
|
map_get(&entity_map, key) != nullptr) {
|
||||||
error(ident, "`%.*s` is already declared in this bit field", LIT(name));
|
error(ident, "`%.*s` is already declared in this bit field", LIT(name));
|
||||||
} else {
|
} else {
|
||||||
@@ -1879,12 +1879,12 @@ Type *check_get_results(Checker *c, Scope *scope, AstNode *_results) {
|
|||||||
|
|
||||||
for (isize i = 0; i < variable_index; i++) {
|
for (isize i = 0; i < variable_index; i++) {
|
||||||
String x = variables[i]->token.string;
|
String x = variables[i]->token.string;
|
||||||
if (x.len == 0 || x == "_") {
|
if (x.len == 0 || is_blank_ident(x)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
for (isize j = i+1; j < variable_index; j++) {
|
for (isize j = i+1; j < variable_index; j++) {
|
||||||
String y = variables[j]->token.string;
|
String y = variables[j]->token.string;
|
||||||
if (y.len == 0 || y == "_") {
|
if (y.len == 0 || is_blank_ident(y)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (x == y) {
|
if (x == y) {
|
||||||
@@ -2162,7 +2162,7 @@ Entity *check_ident(Checker *c, Operand *o, AstNode *n, Type *named_type, Type *
|
|||||||
|
|
||||||
Entity *e = scope_lookup_entity(c->context.scope, name);
|
Entity *e = scope_lookup_entity(c->context.scope, name);
|
||||||
if (e == nullptr) {
|
if (e == nullptr) {
|
||||||
if (name == "_") {
|
if (is_blank_ident(name)) {
|
||||||
error(n, "`_` cannot be used as a value type");
|
error(n, "`_` cannot be used as a value type");
|
||||||
} else {
|
} else {
|
||||||
error(n, "Undeclared name: %.*s", LIT(name));
|
error(n, "Undeclared name: %.*s", LIT(name));
|
||||||
@@ -2603,7 +2603,7 @@ bool check_type_internal(Checker *c, AstNode *e, Type **type, Type *named_type)
|
|||||||
Type *elem = check_type(c, at->elem, nullptr);
|
Type *elem = check_type(c, at->elem, nullptr);
|
||||||
i64 count = check_array_or_map_count(c, at->count, false);
|
i64 count = check_array_or_map_count(c, at->count, false);
|
||||||
if (count < 0) {
|
if (count < 0) {
|
||||||
error(at->count, ".. can only be used in conjuction with compound literals");
|
error(at->count, "... can only be used in conjuction with compound literals");
|
||||||
count = 0;
|
count = 0;
|
||||||
}
|
}
|
||||||
#if 0
|
#if 0
|
||||||
@@ -5735,7 +5735,7 @@ isize lookup_procedure_parameter(TypeProc *pt, String parameter_name) {
|
|||||||
for (isize i = 0; i < param_count; i++) {
|
for (isize i = 0; i < param_count; i++) {
|
||||||
Entity *e = pt->params->Tuple.variables[i];
|
Entity *e = pt->params->Tuple.variables[i];
|
||||||
String name = e->token.string;
|
String name = e->token.string;
|
||||||
if (name == "_") {
|
if (is_blank_ident(name)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (name == parameter_name) {
|
if (name == parameter_name) {
|
||||||
@@ -5749,7 +5749,7 @@ isize lookup_procedure_result(TypeProc *pt, String result_name) {
|
|||||||
for (isize i = 0; i < result_count; i++) {
|
for (isize i = 0; i < result_count; i++) {
|
||||||
Entity *e = pt->results->Tuple.variables[i];
|
Entity *e = pt->results->Tuple.variables[i];
|
||||||
String name = e->token.string;
|
String name = e->token.string;
|
||||||
if (name == "_") {
|
if (is_blank_ident(name)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (name == result_name) {
|
if (name == result_name) {
|
||||||
@@ -5818,7 +5818,7 @@ CALL_ARGUMENT_CHECKER(check_named_call_arguments) {
|
|||||||
for (isize i = 0; i < param_count_to_check; i++) {
|
for (isize i = 0; i < param_count_to_check; i++) {
|
||||||
if (!visited[i]) {
|
if (!visited[i]) {
|
||||||
Entity *e = pt->params->Tuple.variables[i];
|
Entity *e = pt->params->Tuple.variables[i];
|
||||||
if (e->token.string == "_") {
|
if (is_blank_ident(e->token)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (e->kind == Entity_Variable) {
|
if (e->kind == Entity_Variable) {
|
||||||
@@ -6664,7 +6664,7 @@ ExprKind check_expr_base_internal(Checker *c, Operand *o, AstNode *node, Type *t
|
|||||||
bool all_fields_are_blank = true;
|
bool all_fields_are_blank = true;
|
||||||
for (isize i = 0; i < t->Record.field_count; i++) {
|
for (isize i = 0; i < t->Record.field_count; i++) {
|
||||||
Entity *field = t->Record.fields_in_src_order[i];
|
Entity *field = t->Record.fields_in_src_order[i];
|
||||||
if (field->token.string != "_") {
|
if (!is_blank_ident(field->token)) {
|
||||||
all_fields_are_blank = false;
|
all_fields_are_blank = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -6682,7 +6682,7 @@ ExprKind check_expr_base_internal(Checker *c, Operand *o, AstNode *node, Type *t
|
|||||||
}
|
}
|
||||||
|
|
||||||
Entity *field = t->Record.fields_in_src_order[index];
|
Entity *field = t->Record.fields_in_src_order[index];
|
||||||
if (!all_fields_are_blank && field->token.string == "_") {
|
if (!all_fields_are_blank && is_blank_ident(field->token)) {
|
||||||
// NOTE(bill): Ignore blank identifiers
|
// NOTE(bill): Ignore blank identifiers
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -7599,9 +7599,7 @@ gbString write_expr_to_string(gbString str, AstNode *node) {
|
|||||||
if (field->names.count == 0) {
|
if (field->names.count == 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
AstNode *name = field->names[0];
|
if (!is_blank_ident(field->names[0])) {
|
||||||
ast_node(n, Ident, name);
|
|
||||||
if (n->token.string != "_") {
|
|
||||||
has_name = true;
|
has_name = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-6
@@ -186,8 +186,7 @@ Type *check_assignment_variable(Checker *c, Operand *rhs, AstNode *lhs_node) {
|
|||||||
AstNode *node = unparen_expr(lhs_node);
|
AstNode *node = unparen_expr(lhs_node);
|
||||||
|
|
||||||
// NOTE(bill): Ignore assignments to `_`
|
// NOTE(bill): Ignore assignments to `_`
|
||||||
if (node->kind == AstNode_Ident &&
|
if (is_blank_ident(node)) {
|
||||||
node->Ident.token.string == "_") {
|
|
||||||
add_entity_definition(&c->info, node, nullptr);
|
add_entity_definition(&c->info, node, nullptr);
|
||||||
check_assignment(c, rhs, nullptr, str_lit("assignment to `_` identifier"));
|
check_assignment(c, rhs, nullptr, str_lit("assignment to `_` identifier"));
|
||||||
if (rhs->mode == Addressing_Invalid) {
|
if (rhs->mode == Addressing_Invalid) {
|
||||||
@@ -429,7 +428,7 @@ void check_label(Checker *c, AstNode *label) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String name = l->name->Ident.token.string;
|
String name = l->name->Ident.token.string;
|
||||||
if (name == "_") {
|
if (is_blank_ident(name)) {
|
||||||
error(l->name, "A label's name cannot be a blank identifier");
|
error(l->name, "A label's name cannot be a blank identifier");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -884,7 +883,7 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) {
|
|||||||
for (isize i = 0; i < result_count; i++) {
|
for (isize i = 0; i < result_count; i++) {
|
||||||
if (!visited[i]) {
|
if (!visited[i]) {
|
||||||
Entity *e = pt->results->Tuple.variables[i];
|
Entity *e = pt->results->Tuple.variables[i];
|
||||||
if (e->token.string == "_") {
|
if (is_blank_ident(e->token)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
GB_ASSERT(e->kind == Entity_Variable);
|
GB_ASSERT(e->kind == Entity_Variable);
|
||||||
@@ -1133,7 +1132,7 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) {
|
|||||||
String str = token.string;
|
String str = token.string;
|
||||||
Entity *found = nullptr;
|
Entity *found = nullptr;
|
||||||
|
|
||||||
if (str != "_") {
|
if (!is_blank_ident(str)) {
|
||||||
found = current_scope_lookup_entity(c->context.scope, str);
|
found = current_scope_lookup_entity(c->context.scope, str);
|
||||||
}
|
}
|
||||||
if (found == nullptr) {
|
if (found == nullptr) {
|
||||||
@@ -1686,7 +1685,7 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) {
|
|||||||
String str = token.string;
|
String str = token.string;
|
||||||
Entity *found = nullptr;
|
Entity *found = nullptr;
|
||||||
// NOTE(bill): Ignore assignments to `_`
|
// NOTE(bill): Ignore assignments to `_`
|
||||||
if (str != "_") {
|
if (!is_blank_ident(str)) {
|
||||||
found = current_scope_lookup_entity(c->context.scope, str);
|
found = current_scope_lookup_entity(c->context.scope, str);
|
||||||
}
|
}
|
||||||
if (found == nullptr) {
|
if (found == nullptr) {
|
||||||
|
|||||||
+4
-4
@@ -979,7 +979,7 @@ void add_type_and_value(CheckerInfo *i, AstNode *expression, AddressingMode mode
|
|||||||
void add_entity_definition(CheckerInfo *i, AstNode *identifier, Entity *entity) {
|
void add_entity_definition(CheckerInfo *i, AstNode *identifier, Entity *entity) {
|
||||||
GB_ASSERT(identifier != nullptr);
|
GB_ASSERT(identifier != nullptr);
|
||||||
if (identifier->kind == AstNode_Ident) {
|
if (identifier->kind == AstNode_Ident) {
|
||||||
if (identifier->Ident.token.string == "_") {
|
if (is_blank_ident(identifier)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
HashKey key = hash_node(identifier);
|
HashKey key = hash_node(identifier);
|
||||||
@@ -994,7 +994,7 @@ bool add_entity(Checker *c, Scope *scope, AstNode *identifier, Entity *entity) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
String name = entity->token.string;
|
String name = entity->token.string;
|
||||||
if (name != "_") {
|
if (!is_blank_ident(name)) {
|
||||||
Entity *ie = scope_insert_entity(scope, entity);
|
Entity *ie = scope_insert_entity(scope, entity);
|
||||||
if (ie) {
|
if (ie) {
|
||||||
TokenPos pos = ie->token.pos;
|
TokenPos pos = ie->token.pos;
|
||||||
@@ -2202,7 +2202,7 @@ void check_import_entities(Checker *c, Map<Scope *> *file_scopes) {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
String import_name = path_to_entity_name(id->import_name.string, id->fullpath);
|
String import_name = path_to_entity_name(id->import_name.string, id->fullpath);
|
||||||
if (import_name == "_") {
|
if (is_blank_ident(import_name)) {
|
||||||
error(token, "File name, %.*s, cannot be as an import name as it is not a valid identifier", LIT(id->import_name.string));
|
error(token, "File name, %.*s, cannot be as an import name as it is not a valid identifier", LIT(id->import_name.string));
|
||||||
} else {
|
} else {
|
||||||
GB_ASSERT(id->import_name.pos.line != 0);
|
GB_ASSERT(id->import_name.pos.line != 0);
|
||||||
@@ -2254,7 +2254,7 @@ void check_import_entities(Checker *c, Map<Scope *> *file_scopes) {
|
|||||||
|
|
||||||
|
|
||||||
String library_name = path_to_entity_name(fl->library_name.string, file_str);
|
String library_name = path_to_entity_name(fl->library_name.string, file_str);
|
||||||
if (library_name == "_") {
|
if (is_blank_ident(library_name)) {
|
||||||
error(spec, "File name, %.*s, cannot be as a library name as it is not a valid identifier", LIT(fl->library_name.string));
|
error(spec, "File name, %.*s, cannot be as a library name as it is not a valid identifier", LIT(fl->library_name.string));
|
||||||
} else {
|
} else {
|
||||||
GB_ASSERT(fl->library_name.pos.line != 0);
|
GB_ASSERT(fl->library_name.pos.line != 0);
|
||||||
|
|||||||
+16
-15
@@ -653,13 +653,6 @@ Type *ir_type(irValue *value) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool ir_is_blank_ident(AstNode *node) {
|
|
||||||
if (node->kind == AstNode_Ident) {
|
|
||||||
ast_node(i, Ident, node);
|
|
||||||
return is_blank_ident(i->token.string);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
irInstr *ir_get_last_instr(irBlock *block) {
|
irInstr *ir_get_last_instr(irBlock *block) {
|
||||||
@@ -5001,7 +4994,7 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) {
|
|||||||
case_end;
|
case_end;
|
||||||
|
|
||||||
case_ast_node(i, Ident, expr);
|
case_ast_node(i, Ident, expr);
|
||||||
if (ir_is_blank_ident(expr)) {
|
if (is_blank_ident(expr)) {
|
||||||
irAddr val = {};
|
irAddr val = {};
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
@@ -5614,6 +5607,15 @@ irAddr ir_build_addr(irProcedure *proc, AstNode *expr) {
|
|||||||
|
|
||||||
return ir_addr(v);
|
return ir_addr(v);
|
||||||
case_end;
|
case_end;
|
||||||
|
|
||||||
|
case_ast_node(tc, TypeCast, expr);
|
||||||
|
Type *type = type_of_expr(proc->module->info, expr);
|
||||||
|
irValue *x = ir_build_expr(proc, tc->expr);
|
||||||
|
irValue *e = ir_emit_conv(proc, x, type);
|
||||||
|
irValue *v = ir_add_local_generated(proc, type);
|
||||||
|
ir_emit_store(proc, v, e);
|
||||||
|
return ir_addr(v);
|
||||||
|
case_end;
|
||||||
}
|
}
|
||||||
|
|
||||||
TokenPos token_pos = ast_node_token(expr).pos;
|
TokenPos token_pos = ast_node_token(expr).pos;
|
||||||
@@ -6143,7 +6145,7 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) {
|
|||||||
if (vd->values.count == 0) { // declared and zero-initialized
|
if (vd->values.count == 0) { // declared and zero-initialized
|
||||||
for_array(i, vd->names) {
|
for_array(i, vd->names) {
|
||||||
AstNode *name = vd->names[i];
|
AstNode *name = vd->names[i];
|
||||||
if (!ir_is_blank_ident(name)) {
|
if (!is_blank_ident(name)) {
|
||||||
ir_add_local_for_identifier(proc, name, true);
|
ir_add_local_for_identifier(proc, name, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -6156,7 +6158,7 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) {
|
|||||||
for_array(i, vd->names) {
|
for_array(i, vd->names) {
|
||||||
AstNode *name = vd->names[i];
|
AstNode *name = vd->names[i];
|
||||||
irAddr lval = ir_addr(nullptr);
|
irAddr lval = ir_addr(nullptr);
|
||||||
if (!ir_is_blank_ident(name)) {
|
if (!is_blank_ident(name)) {
|
||||||
ir_add_local_for_identifier(proc, name, false);
|
ir_add_local_for_identifier(proc, name, false);
|
||||||
lval = ir_build_addr(proc, name);
|
lval = ir_build_addr(proc, name);
|
||||||
}
|
}
|
||||||
@@ -6200,7 +6202,7 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) {
|
|||||||
for_array(i, as->lhs) {
|
for_array(i, as->lhs) {
|
||||||
AstNode *lhs = as->lhs[i];
|
AstNode *lhs = as->lhs[i];
|
||||||
irAddr lval = {};
|
irAddr lval = {};
|
||||||
if (!ir_is_blank_ident(lhs)) {
|
if (!is_blank_ident(lhs)) {
|
||||||
lval = ir_build_addr(proc, lhs);
|
lval = ir_build_addr(proc, lhs);
|
||||||
}
|
}
|
||||||
array_add(&lvals, lval);
|
array_add(&lvals, lval);
|
||||||
@@ -6498,10 +6500,10 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) {
|
|||||||
|
|
||||||
Type *val_type = nullptr;
|
Type *val_type = nullptr;
|
||||||
Type *idx_type = nullptr;
|
Type *idx_type = nullptr;
|
||||||
if (rs->value != nullptr && !ir_is_blank_ident(rs->value)) {
|
if (rs->value != nullptr && !is_blank_ident(rs->value)) {
|
||||||
val_type = type_of_expr(proc->module->info, rs->value);
|
val_type = type_of_expr(proc->module->info, rs->value);
|
||||||
}
|
}
|
||||||
if (rs->index != nullptr && !ir_is_blank_ident(rs->index)) {
|
if (rs->index != nullptr && !is_blank_ident(rs->index)) {
|
||||||
idx_type = type_of_expr(proc->module->info, rs->index);
|
idx_type = type_of_expr(proc->module->info, rs->index);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -7073,8 +7075,7 @@ void ir_begin_procedure_body(irProcedure *proc) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Type *abi_type = proc->type->Proc.abi_compat_params[i];
|
Type *abi_type = proc->type->Proc.abi_compat_params[i];
|
||||||
if (e->token.string != "" &&
|
if (e->token.string != "" && !is_blank_ident(e->token)) {
|
||||||
e->token.string != "_") {
|
|
||||||
irValue *param = ir_add_param(proc, e, name, abi_type);
|
irValue *param = ir_add_param(proc, e, name, abi_type);
|
||||||
array_add(&proc->params, param);
|
array_add(&proc->params, param);
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-2
@@ -1580,8 +1580,7 @@ void ir_print_proc(irFileBuffer *f, irModule *m, irProcedure *proc) {
|
|||||||
ir_fprintf(f, " noalias");
|
ir_fprintf(f, " noalias");
|
||||||
}
|
}
|
||||||
if (proc->body != nullptr) {
|
if (proc->body != nullptr) {
|
||||||
if (e->token.string != "" &&
|
if (e->token.string != "" && !is_blank_ident(e->token)) {
|
||||||
e->token.string != "_") {
|
|
||||||
ir_fprintf(f, " ");
|
ir_fprintf(f, " ");
|
||||||
ir_print_encoded_local(f, e->token.string);
|
ir_print_encoded_local(f, e->token.string);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
+1558
-1315
File diff suppressed because it is too large
Load Diff
+1
-1
@@ -1476,7 +1476,7 @@ Entity *current_scope_lookup_entity(Scope *s, String name);
|
|||||||
Selection lookup_field_with_selection(gbAllocator a, Type *type_, String field_name, bool is_type, Selection sel) {
|
Selection lookup_field_with_selection(gbAllocator a, Type *type_, String field_name, bool is_type, Selection sel) {
|
||||||
GB_ASSERT(type_ != nullptr);
|
GB_ASSERT(type_ != nullptr);
|
||||||
|
|
||||||
if (field_name == "_") {
|
if (is_blank_ident(field_name)) {
|
||||||
return empty_selection;
|
return empty_selection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user