mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-04 06:38:47 +00:00
Begin reording of struct members by default.
This commit is contained in:
+1
-1
@@ -16,7 +16,7 @@ print_string_to_buffer :: proc(buf: ^[]byte, s: string) {
|
|||||||
if slice.len < slice.cap {
|
if slice.len < slice.cap {
|
||||||
n := min(slice.cap-slice.len, len(s))
|
n := min(slice.cap-slice.len, len(s))
|
||||||
offset := ((slice.data as int) + slice.len) as ^byte
|
offset := ((slice.data as int) + slice.len) as ^byte
|
||||||
memory_move(offset, ^s[0], n)
|
memory_copy(offset, ^s[0], n)
|
||||||
slice.len += n
|
slice.len += n
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+8
-1
@@ -1,10 +1,17 @@
|
|||||||
#load "basic.odin"
|
#load "basic.odin"
|
||||||
|
|
||||||
Vector3 :: struct { x, y, z: f32 }
|
|
||||||
main :: proc() {
|
main :: proc() {
|
||||||
|
Vector3 :: struct {
|
||||||
|
x: i8
|
||||||
|
y: i32
|
||||||
|
z: i16
|
||||||
|
}
|
||||||
|
|
||||||
v := Vector3{1, 4, 9}
|
v := Vector3{1, 4, 9}
|
||||||
|
|
||||||
|
t := type_info(v)
|
||||||
|
|
||||||
println(123, "Hello", true, 6.28)
|
println(123, "Hello", true, 6.28)
|
||||||
println([4]int{1, 2, 3, 4})
|
println([4]int{1, 2, 3, 4})
|
||||||
|
println(v)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -180,8 +180,8 @@ new_builtins :: proc() {
|
|||||||
{
|
{
|
||||||
// Compile time assert
|
// Compile time assert
|
||||||
COND :: true
|
COND :: true
|
||||||
assert(COND)
|
compile_assert(COND)
|
||||||
// assert(!COND)
|
// compile_assert(!COND)
|
||||||
|
|
||||||
// Runtime assert
|
// Runtime assert
|
||||||
x := true
|
x := true
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ memory_copy :: proc(dst, src: rawptr, n: int) #inline {
|
|||||||
}
|
}
|
||||||
|
|
||||||
v128b :: type {4}u32
|
v128b :: type {4}u32
|
||||||
assert(align_of(v128b) == 16)
|
compile_assert(align_of(v128b) == 16)
|
||||||
|
|
||||||
d, s: ^byte = dst, src
|
d, s: ^byte = dst, src
|
||||||
|
|
||||||
|
|||||||
+25
-25
@@ -3,43 +3,47 @@
|
|||||||
// IMPORTANT NOTE(bill): Do not change the order of any of this data
|
// IMPORTANT NOTE(bill): Do not change the order of any of this data
|
||||||
// The compiler relies upon this _exact_ order
|
// The compiler relies upon this _exact_ order
|
||||||
Type_Info :: union {
|
Type_Info :: union {
|
||||||
Member :: struct {
|
Member :: struct #ordered {
|
||||||
name: string
|
name: string // can be empty if tuple
|
||||||
type_info: ^Type_Info
|
type_info: ^Type_Info
|
||||||
offset: int
|
offset: int // offsets are not used in tuples
|
||||||
}
|
}
|
||||||
Record :: struct {
|
Record :: struct #ordered {
|
||||||
fields: []Member // NOTE(bill): This will need to be allocated on the heap
|
fields: []Member // IMPORTANT: This will need to be allocated on the heap
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Named: struct {
|
Named: struct #ordered {
|
||||||
name: string
|
name: string
|
||||||
base: ^Type_Info
|
base: ^Type_Info
|
||||||
}
|
}
|
||||||
Integer: struct {
|
Integer: struct #ordered {
|
||||||
size: int // in bytes
|
size: int // in bytes
|
||||||
signed: bool
|
signed: bool
|
||||||
}
|
}
|
||||||
Float: struct {
|
Float: struct #ordered {
|
||||||
size: int // in bytes
|
size: int // in bytes
|
||||||
}
|
}
|
||||||
String: struct {}
|
String: struct #ordered {}
|
||||||
Boolean: struct {}
|
Boolean: struct #ordered {}
|
||||||
Pointer: struct {
|
Pointer: struct #ordered {
|
||||||
elem: ^Type_Info
|
elem: ^Type_Info
|
||||||
}
|
}
|
||||||
Procedure: struct{}
|
Procedure: struct #ordered {
|
||||||
Array: struct {
|
params: ^Type_Info // Type_Info.Tuple
|
||||||
|
results: ^Type_Info // Type_Info.Tuple
|
||||||
|
variadic: bool
|
||||||
|
}
|
||||||
|
Array: struct #ordered {
|
||||||
elem: ^Type_Info
|
elem: ^Type_Info
|
||||||
elem_size: int
|
elem_size: int
|
||||||
len: int
|
len: int
|
||||||
}
|
}
|
||||||
Slice: struct {
|
Slice: struct #ordered {
|
||||||
elem: ^Type_Info
|
elem: ^Type_Info
|
||||||
elem_size: int
|
elem_size: int
|
||||||
}
|
}
|
||||||
Vector: struct {
|
Vector: struct #ordered {
|
||||||
elem: ^Type_Info
|
elem: ^Type_Info
|
||||||
elem_size: int
|
elem_size: int
|
||||||
len: int
|
len: int
|
||||||
@@ -48,7 +52,7 @@ Type_Info :: union {
|
|||||||
Struct: Record
|
Struct: Record
|
||||||
Union: Record
|
Union: Record
|
||||||
Raw_Union: Record
|
Raw_Union: Record
|
||||||
Enum: struct {
|
Enum: struct #ordered {
|
||||||
base: ^Type_Info
|
base: ^Type_Info
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -57,9 +61,9 @@ Type_Info :: union {
|
|||||||
|
|
||||||
assume :: proc(cond: bool) #foreign "llvm.assume"
|
assume :: proc(cond: bool) #foreign "llvm.assume"
|
||||||
|
|
||||||
__debug_trap :: proc() #foreign "llvm.debugtrap"
|
__debug_trap :: proc() #foreign "llvm.debugtrap"
|
||||||
__trap :: proc() #foreign "llvm.trap"
|
__trap :: proc() #foreign "llvm.trap"
|
||||||
read_cycle_counter :: proc() -> u64 #foreign "llvm.readcyclecounter"
|
read_cycle_counter :: proc() -> u64 #foreign "llvm.readcyclecounter"
|
||||||
|
|
||||||
bit_reverse16 :: proc(b: u16) -> u16 #foreign "llvm.bitreverse.i16"
|
bit_reverse16 :: proc(b: u16) -> u16 #foreign "llvm.bitreverse.i16"
|
||||||
bit_reverse32 :: proc(b: u32) -> u32 #foreign "llvm.bitreverse.i32"
|
bit_reverse32 :: proc(b: u32) -> u32 #foreign "llvm.bitreverse.i32"
|
||||||
@@ -87,7 +91,8 @@ memory_zero :: proc(data: rawptr, len: int) {
|
|||||||
|
|
||||||
memory_compare :: proc(dst, src: rawptr, len: int) -> int {
|
memory_compare :: proc(dst, src: rawptr, len: int) -> int {
|
||||||
// TODO(bill): make a faster `memory_compare`
|
// TODO(bill): make a faster `memory_compare`
|
||||||
a, b := slice_ptr(dst as ^byte, len), slice_ptr(src as ^byte, len)
|
a := slice_ptr(dst as ^byte, len)
|
||||||
|
b := slice_ptr(src as ^byte, len)
|
||||||
for i := 0; i < len; i++ {
|
for i := 0; i < len; i++ {
|
||||||
if a[i] != b[i] {
|
if a[i] != b[i] {
|
||||||
return (a[i] - b[i]) as int
|
return (a[i] - b[i]) as int
|
||||||
@@ -97,11 +102,6 @@ memory_compare :: proc(dst, src: rawptr, len: int) -> int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
memory_copy :: proc(dst, src: rawptr, len: int) #inline {
|
memory_copy :: proc(dst, src: rawptr, len: int) #inline {
|
||||||
llvm_memcpy_64bit :: proc(dst, src: rawptr, len: int, align: i32, is_volatile: bool) #foreign "llvm.memcpy.p0i8.p0i8.i64"
|
|
||||||
llvm_memcpy_64bit(dst, src, len, 1, false)
|
|
||||||
}
|
|
||||||
|
|
||||||
memory_move :: proc(dst, src: rawptr, len: int) #inline {
|
|
||||||
llvm_memmove_64bit :: proc(dst, src: rawptr, len: int, align: i32, is_volatile: bool) #foreign "llvm.memmove.p0i8.p0i8.i64"
|
llvm_memmove_64bit :: proc(dst, src: rawptr, len: int, align: i32, is_volatile: bool) #foreign "llvm.memmove.p0i8.p0i8.i64"
|
||||||
llvm_memmove_64bit(dst, src, len, 1, false)
|
llvm_memmove_64bit(dst, src, len, 1, false)
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -42,7 +42,7 @@ INVALID_HANDLE_VALUE :: (-1 as int) as HANDLE
|
|||||||
|
|
||||||
WNDPROC :: type proc(hwnd: HWND, msg: u32, wparam: WPARAM, lparam: LPARAM) -> LRESULT
|
WNDPROC :: type proc(hwnd: HWND, msg: u32, wparam: WPARAM, lparam: LPARAM) -> LRESULT
|
||||||
|
|
||||||
WNDCLASSEXA :: struct {
|
WNDCLASSEXA :: struct #ordered {
|
||||||
size, style: u32
|
size, style: u32
|
||||||
wnd_proc: WNDPROC
|
wnd_proc: WNDPROC
|
||||||
cls_extra, wnd_extra: i32
|
cls_extra, wnd_extra: i32
|
||||||
@@ -54,7 +54,7 @@ WNDCLASSEXA :: struct {
|
|||||||
sm: HICON
|
sm: HICON
|
||||||
}
|
}
|
||||||
|
|
||||||
MSG :: struct {
|
MSG :: struct #ordered {
|
||||||
hwnd: HWND
|
hwnd: HWND
|
||||||
message: u32
|
message: u32
|
||||||
wparam: WPARAM
|
wparam: WPARAM
|
||||||
@@ -191,7 +191,7 @@ PROC :: type proc()
|
|||||||
wglCreateContextAttribsARBType :: type proc(hdc: HDC, hshareContext: rawptr, attribList: ^i32) -> HGLRC
|
wglCreateContextAttribsARBType :: type proc(hdc: HDC, hshareContext: rawptr, attribList: ^i32) -> HGLRC
|
||||||
|
|
||||||
|
|
||||||
PIXELFORMATDESCRIPTOR :: struct {
|
PIXELFORMATDESCRIPTOR :: struct #ordered {
|
||||||
size,
|
size,
|
||||||
version,
|
version,
|
||||||
flags: u32
|
flags: u32
|
||||||
|
|||||||
+40
-14
@@ -133,6 +133,10 @@ enum BuiltinProcId {
|
|||||||
BuiltinProc_offset_of,
|
BuiltinProc_offset_of,
|
||||||
BuiltinProc_offset_of_val,
|
BuiltinProc_offset_of_val,
|
||||||
BuiltinProc_type_of_val,
|
BuiltinProc_type_of_val,
|
||||||
|
|
||||||
|
BuiltinProc_type_info,
|
||||||
|
|
||||||
|
BuiltinProc_compile_assert,
|
||||||
BuiltinProc_assert,
|
BuiltinProc_assert,
|
||||||
|
|
||||||
BuiltinProc_len,
|
BuiltinProc_len,
|
||||||
@@ -150,7 +154,6 @@ enum BuiltinProcId {
|
|||||||
BuiltinProc_max,
|
BuiltinProc_max,
|
||||||
BuiltinProc_abs,
|
BuiltinProc_abs,
|
||||||
|
|
||||||
BuiltinProc_type_info,
|
|
||||||
|
|
||||||
BuiltinProc_Count,
|
BuiltinProc_Count,
|
||||||
};
|
};
|
||||||
@@ -174,6 +177,10 @@ gb_global BuiltinProc builtin_procs[BuiltinProc_Count] = {
|
|||||||
{STR_LIT("offset_of"), 2, false, Expr_Expr},
|
{STR_LIT("offset_of"), 2, false, Expr_Expr},
|
||||||
{STR_LIT("offset_of_val"), 1, false, Expr_Expr},
|
{STR_LIT("offset_of_val"), 1, false, Expr_Expr},
|
||||||
{STR_LIT("type_of_val"), 1, false, Expr_Expr},
|
{STR_LIT("type_of_val"), 1, false, Expr_Expr},
|
||||||
|
|
||||||
|
{STR_LIT("type_info"), 1, false, Expr_Expr},
|
||||||
|
|
||||||
|
{STR_LIT("compile_assert"), 1, false, Expr_Stmt},
|
||||||
{STR_LIT("assert"), 1, false, Expr_Stmt},
|
{STR_LIT("assert"), 1, false, Expr_Stmt},
|
||||||
|
|
||||||
{STR_LIT("len"), 1, false, Expr_Expr},
|
{STR_LIT("len"), 1, false, Expr_Expr},
|
||||||
@@ -191,7 +198,6 @@ gb_global BuiltinProc builtin_procs[BuiltinProc_Count] = {
|
|||||||
{STR_LIT("max"), 2, false, Expr_Expr},
|
{STR_LIT("max"), 2, false, Expr_Expr},
|
||||||
{STR_LIT("abs"), 1, false, Expr_Expr},
|
{STR_LIT("abs"), 1, false, Expr_Expr},
|
||||||
|
|
||||||
{STR_LIT("type_info"), 1, false, Expr_Expr},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct CheckerContext {
|
struct CheckerContext {
|
||||||
@@ -682,26 +688,27 @@ void add_type_info_type(Checker *c, Type *t) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
isize found = -1;
|
isize ti_index = -1;
|
||||||
gb_for_array(i, c->info.type_info_map.entries) {
|
gb_for_array(i, c->info.type_info_map.entries) {
|
||||||
auto *e = &c->info.type_info_map.entries[i];
|
auto *e = &c->info.type_info_map.entries[i];
|
||||||
Type *prev_type = cast(Type *)cast(uintptr)e->key.key;
|
Type *prev_type = cast(Type *)cast(uintptr)e->key.key;
|
||||||
if (are_types_identical(t, prev_type)) {
|
if (are_types_identical(t, prev_type)) {
|
||||||
found = i;
|
// Duplicate entry
|
||||||
|
ti_index = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (found >= 0) {
|
if (ti_index < 0) {
|
||||||
// Duplicate entry
|
|
||||||
map_set(&c->info.type_info_map, hash_pointer(t), found);
|
|
||||||
} else {
|
|
||||||
// Unique entry
|
// Unique entry
|
||||||
isize index = c->info.type_info_index;
|
// NOTE(bill): map entries grow linearly and in order
|
||||||
|
ti_index = c->info.type_info_index;
|
||||||
c->info.type_info_index++;
|
c->info.type_info_index++;
|
||||||
map_set(&c->info.type_info_map, hash_pointer(t), index);
|
|
||||||
}
|
}
|
||||||
|
map_set(&c->info.type_info_map, hash_pointer(t), ti_index);
|
||||||
|
|
||||||
|
|
||||||
|
// Add nested types
|
||||||
|
|
||||||
if (t->kind == Type_Named) {
|
if (t->kind == Type_Named) {
|
||||||
// NOTE(bill): Just in case
|
// NOTE(bill): Just in case
|
||||||
add_type_info_type(c, t->Named.base);
|
add_type_info_type(c, t->Named.base);
|
||||||
@@ -716,6 +723,11 @@ void add_type_info_type(Checker *c, Type *t) {
|
|||||||
add_type_info_type(c, t_int);
|
add_type_info_type(c, t_int);
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
|
case Type_Pointer:
|
||||||
|
add_type_info_type(c, bt->Pointer.elem);
|
||||||
|
break;
|
||||||
|
|
||||||
case Type_Array:
|
case Type_Array:
|
||||||
add_type_info_type(c, bt->Array.elem);
|
add_type_info_type(c, bt->Array.elem);
|
||||||
add_type_info_type(c, make_type_pointer(c->allocator, bt->Array.elem));
|
add_type_info_type(c, make_type_pointer(c->allocator, bt->Array.elem));
|
||||||
@@ -726,8 +738,11 @@ void add_type_info_type(Checker *c, Type *t) {
|
|||||||
add_type_info_type(c, make_type_pointer(c->allocator, bt->Slice.elem));
|
add_type_info_type(c, make_type_pointer(c->allocator, bt->Slice.elem));
|
||||||
add_type_info_type(c, t_int);
|
add_type_info_type(c, t_int);
|
||||||
break;
|
break;
|
||||||
case Type_Vector: add_type_info_type(c, bt->Vector.elem); break;
|
case Type_Vector:
|
||||||
case Type_Pointer: add_type_info_type(c, bt->Pointer.elem); break;
|
add_type_info_type(c, bt->Vector.elem);
|
||||||
|
add_type_info_type(c, t_int);
|
||||||
|
break;
|
||||||
|
|
||||||
case Type_Record: {
|
case Type_Record: {
|
||||||
switch (bt->Record.kind) {
|
switch (bt->Record.kind) {
|
||||||
case TypeRecord_Enum:
|
case TypeRecord_Enum:
|
||||||
@@ -741,9 +756,20 @@ void add_type_info_type(Checker *c, Type *t) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
|
case Type_Tuple:
|
||||||
|
for (isize i = 0; i < bt->Tuple.variable_count; i++) {
|
||||||
|
Entity *var = bt->Tuple.variables[i];
|
||||||
|
add_type_info_type(c, var->type);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Type_Proc:
|
||||||
|
add_type_info_type(c, bt->Proc.params);
|
||||||
|
add_type_info_type(c, bt->Proc.results);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
// TODO(bill): Type info for procedures and tuples
|
|
||||||
// TODO(bill): Remove duplicate identical types efficiently
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+60
-16
@@ -386,6 +386,22 @@ void check_fields(Checker *c, AstNode *node, AstNodeArray decls,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// TODO(bill): Cleanup struct field reordering
|
||||||
|
gb_global BaseTypeSizes __checker_sizes = {};
|
||||||
|
gb_global gbAllocator __checker_allocator = {};
|
||||||
|
|
||||||
|
GB_COMPARE_PROC(cmp_struct_entity_size) {
|
||||||
|
// NOTE(bill): Biggest to smallest
|
||||||
|
Entity *x = *(Entity **)a;
|
||||||
|
Entity *y = *(Entity **)b;
|
||||||
|
i64 xs = type_size_of(__checker_sizes, __checker_allocator, x->type);
|
||||||
|
i64 ys = type_size_of(__checker_sizes, __checker_allocator, y->type);
|
||||||
|
if (xs == ys) {
|
||||||
|
return string_cmp(&x->token.string, &y->token.string);
|
||||||
|
}
|
||||||
|
return xs > ys ? -1 : xs < ys;
|
||||||
|
}
|
||||||
|
|
||||||
void check_struct_type(Checker *c, Type *struct_type, AstNode *node, CycleChecker *cycle_checker) {
|
void check_struct_type(Checker *c, Type *struct_type, AstNode *node, CycleChecker *cycle_checker) {
|
||||||
GB_ASSERT(is_type_struct(struct_type));
|
GB_ASSERT(is_type_struct(struct_type));
|
||||||
ast_node(st, StructType, node);
|
ast_node(st, StructType, node);
|
||||||
@@ -414,7 +430,20 @@ void check_struct_type(Checker *c, Type *struct_type, AstNode *node, CycleChecke
|
|||||||
|
|
||||||
check_fields(c, node, st->decls, fields, field_count, other_fields, other_field_count, cycle_checker, make_string("struct"));
|
check_fields(c, node, st->decls, fields, field_count, other_fields, other_field_count, cycle_checker, make_string("struct"));
|
||||||
|
|
||||||
|
if (!st->is_packed && !st->is_ordered) {
|
||||||
|
// NOTE(bill): Reorder fields for reduced size/performance
|
||||||
|
// NOTE(bill): Hacky thing
|
||||||
|
__checker_sizes = c->sizes;
|
||||||
|
__checker_allocator = c->allocator;
|
||||||
|
|
||||||
|
// TODO(bill): Figure out rules more
|
||||||
|
// sorting rules
|
||||||
|
// compound literal order must match source not layout
|
||||||
|
// gb_sort_array(fields, field_count, cmp_struct_entity_size);
|
||||||
|
}
|
||||||
|
|
||||||
struct_type->Record.struct_is_packed = st->is_packed;
|
struct_type->Record.struct_is_packed = st->is_packed;
|
||||||
|
struct_type->Record.struct_is_ordered = st->is_ordered;
|
||||||
struct_type->Record.fields = fields;
|
struct_type->Record.fields = fields;
|
||||||
struct_type->Record.field_count = field_count;
|
struct_type->Record.field_count = field_count;
|
||||||
struct_type->Record.other_fields = other_fields;
|
struct_type->Record.other_fields = other_fields;
|
||||||
@@ -1959,7 +1988,8 @@ b32 check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id)
|
|||||||
case BuiltinProc_size_of:
|
case BuiltinProc_size_of:
|
||||||
case BuiltinProc_align_of:
|
case BuiltinProc_align_of:
|
||||||
case BuiltinProc_offset_of:
|
case BuiltinProc_offset_of:
|
||||||
// NOTE(bill): The first arg is a Type, this will be checked case by case
|
case BuiltinProc_type_info:
|
||||||
|
// NOTE(bill): The first arg may be a Type, this will be checked case by case
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
check_multi_expr(c, operand, ce->args[0]);
|
check_multi_expr(c, operand, ce->args[0]);
|
||||||
@@ -2178,6 +2208,34 @@ b32 check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id)
|
|||||||
operand->mode = Addressing_Type;
|
operand->mode = Addressing_Type;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
||||||
|
case BuiltinProc_type_info: {
|
||||||
|
// type_info :: proc(val_or_type) -> ^Type_Info
|
||||||
|
Operand op = {};
|
||||||
|
check_expr_or_type(c, &op, ce->args[0]);
|
||||||
|
add_type_info_type(c, op.type);
|
||||||
|
operand->mode = Addressing_Value;
|
||||||
|
operand->type = t_type_info_ptr;
|
||||||
|
} break;
|
||||||
|
|
||||||
|
case BuiltinProc_compile_assert:
|
||||||
|
// compile_assert :: proc(cond: bool)
|
||||||
|
|
||||||
|
if (!is_type_boolean(operand->type) && operand->mode != Addressing_Constant) {
|
||||||
|
gbString str = expr_to_string(ce->args[0]);
|
||||||
|
defer (gb_string_free(str));
|
||||||
|
error(&c->error_collector, ast_node_token(call),
|
||||||
|
"`%s` is not a constant boolean", str);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!operand->value.value_bool) {
|
||||||
|
gbString str = expr_to_string(ce->args[0]);
|
||||||
|
defer (gb_string_free(str));
|
||||||
|
error(&c->error_collector, ast_node_token(call),
|
||||||
|
"Compile time assertion: `%s`", str);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case BuiltinProc_assert:
|
case BuiltinProc_assert:
|
||||||
// assert :: proc(cond: bool)
|
// assert :: proc(cond: bool)
|
||||||
|
|
||||||
@@ -2188,14 +2246,7 @@ b32 check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id)
|
|||||||
"`%s` is not a boolean", str);
|
"`%s` is not a boolean", str);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (operand->mode == Addressing_Constant &&
|
|
||||||
!operand->value.value_bool) {
|
|
||||||
gbString str = expr_to_string(ce->args[0]);
|
|
||||||
defer (gb_string_free(str));
|
|
||||||
error(&c->error_collector, ast_node_token(call),
|
|
||||||
"Compile time assertion: `%s`", str);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (operand->mode != Addressing_Constant) {
|
if (operand->mode != Addressing_Constant) {
|
||||||
operand->mode = Addressing_NoValue;
|
operand->mode = Addressing_NoValue;
|
||||||
}
|
}
|
||||||
@@ -2693,13 +2744,6 @@ b32 check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id)
|
|||||||
|
|
||||||
operand->type = type;
|
operand->type = type;
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
|
|
||||||
case BuiltinProc_type_info: {
|
|
||||||
add_type_info_type(c, operand->type);
|
|
||||||
operand->mode = Addressing_Value;
|
|
||||||
operand->type = t_type_info_ptr;
|
|
||||||
} break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -132,6 +132,7 @@ struct Type {
|
|||||||
i64 * struct_offsets;
|
i64 * struct_offsets;
|
||||||
b32 struct_are_offsets_set;
|
b32 struct_are_offsets_set;
|
||||||
b32 struct_is_packed;
|
b32 struct_is_packed;
|
||||||
|
b32 struct_is_ordered;
|
||||||
|
|
||||||
// Entity_Constant or Entity_TypeName
|
// Entity_Constant or Entity_TypeName
|
||||||
Entity **other_fields;
|
Entity **other_fields;
|
||||||
|
|||||||
+85
-30
@@ -179,16 +179,25 @@ void ssa_gen_tree(ssaGen *s) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
{ // NOTE(bill): Setup type_info data
|
{ // NOTE(bill): Setup type_info data
|
||||||
ssaValue **found = map_get(&proc->module->members, hash_string(make_string("__type_info_data")));
|
ssaValue *type_info_data = NULL;
|
||||||
|
ssaValue *type_info_member_data = NULL;
|
||||||
|
|
||||||
|
ssaValue **found = NULL;
|
||||||
|
found = map_get(&proc->module->members, hash_string(make_string("__type_info_data")));
|
||||||
GB_ASSERT(found != NULL);
|
GB_ASSERT(found != NULL);
|
||||||
ssaValue *type_info_data = *found;
|
type_info_data = *found;
|
||||||
|
|
||||||
|
found = map_get(&proc->module->members, hash_string(make_string("__type_info_member_data")));
|
||||||
|
GB_ASSERT(found != NULL);
|
||||||
|
type_info_member_data = *found;
|
||||||
|
|
||||||
CheckerInfo *info = proc->module->info;
|
CheckerInfo *info = proc->module->info;
|
||||||
|
|
||||||
|
// Useful types
|
||||||
Type *t_int_ptr = make_type_pointer(a, t_int);
|
Type *t_int_ptr = make_type_pointer(a, t_int);
|
||||||
Type *t_bool_ptr = make_type_pointer(a, t_bool);
|
Type *t_bool_ptr = make_type_pointer(a, t_bool);
|
||||||
Type *t_string_ptr = make_type_pointer(a, t_string);
|
Type *t_string_ptr = make_type_pointer(a, t_string);
|
||||||
Type *t_type_info_ptr_ptr = make_type_pointer(a, t_type_info_ptr);
|
Type *t_type_info_ptr_ptr = make_type_pointer(a, t_type_info_ptr);
|
||||||
|
|
||||||
|
|
||||||
auto get_type_info_ptr = [](ssaProcedure *proc, ssaValue *type_info_data, Type *type) -> ssaValue * {
|
auto get_type_info_ptr = [](ssaProcedure *proc, ssaValue *type_info_data, Type *type) -> ssaValue * {
|
||||||
@@ -197,6 +206,15 @@ void ssa_gen_tree(ssaGen *s) {
|
|||||||
t_type_info_ptr);
|
t_type_info_ptr);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
isize type_info_member_index = 0;
|
||||||
|
|
||||||
|
auto type_info_member_offset = [](ssaProcedure *proc, ssaValue *data, isize count, isize *index) -> ssaValue * {
|
||||||
|
ssaValue *offset = ssa_emit_struct_gep(proc, data, *index, t_type_info_member_ptr);
|
||||||
|
*index += count;
|
||||||
|
return offset;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
gb_for_array(entry_index, info->type_info_map.entries) {
|
gb_for_array(entry_index, info->type_info_map.entries) {
|
||||||
auto *entry = &info->type_info_map.entries[entry_index];
|
auto *entry = &info->type_info_map.entries[entry_index];
|
||||||
Type *t = cast(Type *)cast(uintptr)entry->key.key;
|
Type *t = cast(Type *)cast(uintptr)entry->key.key;
|
||||||
@@ -207,7 +225,9 @@ void ssa_gen_tree(ssaGen *s) {
|
|||||||
case Type_Named: {
|
case Type_Named: {
|
||||||
tag = ssa_add_local_generated(proc, t_type_info_named);
|
tag = ssa_add_local_generated(proc, t_type_info_named);
|
||||||
|
|
||||||
ssaValue *gsa = ssa_add_global_string_array(proc, make_exact_value_string(t->Named.name));
|
// TODO(bill): Which is better? The mangled name or actual name?
|
||||||
|
// ssaValue *gsa = ssa_add_global_string_array(proc, make_exact_value_string(t->Named.name));
|
||||||
|
ssaValue *gsa = ssa_add_global_string_array(proc, make_exact_value_string(t->Named.type_name->token.string));
|
||||||
ssaValue *elem = ssa_array_elem(proc, gsa);
|
ssaValue *elem = ssa_array_elem(proc, gsa);
|
||||||
ssaValue *len = ssa_array_len(proc, ssa_emit_load(proc, gsa));
|
ssaValue *len = ssa_array_len(proc, ssa_emit_load(proc, gsa));
|
||||||
ssaValue *name = ssa_emit_string(proc, elem, len);
|
ssaValue *name = ssa_emit_string(proc, elem, len);
|
||||||
@@ -303,16 +323,10 @@ void ssa_gen_tree(ssaGen *s) {
|
|||||||
} break;
|
} break;
|
||||||
case Type_Record: {
|
case Type_Record: {
|
||||||
switch (t->Record.kind) {
|
switch (t->Record.kind) {
|
||||||
// TODO(bill): Record members for `Type_Info`
|
|
||||||
case TypeRecord_Struct: {
|
case TypeRecord_Struct: {
|
||||||
tag = ssa_add_local_generated(proc, t_type_info_struct);
|
tag = ssa_add_local_generated(proc, t_type_info_struct);
|
||||||
ssaValue **args = gb_alloc_array(a, ssaValue *, 1);
|
|
||||||
isize element_size = type_size_of(m->sizes, a, t_type_info_member);
|
ssaValue *memory = type_info_member_offset(proc, type_info_member_data, t->Record.field_count, &type_info_member_index);
|
||||||
isize allocation_size = t->Record.field_count * element_size;
|
|
||||||
ssaValue *size = ssa_make_value_constant(a, t_int, make_exact_value_integer(allocation_size));
|
|
||||||
args[0] = size;
|
|
||||||
ssaValue *memory = ssa_emit_global_call(proc, "alloc", args, 1);
|
|
||||||
memory = ssa_emit_conv(proc, memory, t_type_info_member_ptr);
|
|
||||||
|
|
||||||
type_set_offsets(m->sizes, a, t); // NOTE(bill): Just incase the offsets have not been set yet
|
type_set_offsets(m->sizes, a, t); // NOTE(bill): Just incase the offsets have not been set yet
|
||||||
for (isize i = 0; i < t->Record.field_count; i++) {
|
for (isize i = 0; i < t->Record.field_count; i++) {
|
||||||
@@ -325,7 +339,9 @@ void ssa_gen_tree(ssaGen *s) {
|
|||||||
ssaValue *tip = get_type_info_ptr(proc, type_info_data, f->type);
|
ssaValue *tip = get_type_info_ptr(proc, type_info_data, f->type);
|
||||||
i64 foffset = t->Record.struct_offsets[i];
|
i64 foffset = t->Record.struct_offsets[i];
|
||||||
|
|
||||||
ssa_emit_store(proc, name, ssa_emit_global_string(proc, make_exact_value_string(f->token.string)));
|
if (f->token.string.len > 0) {
|
||||||
|
ssa_emit_store(proc, name, ssa_emit_global_string(proc, make_exact_value_string(f->token.string)));
|
||||||
|
}
|
||||||
ssa_emit_store(proc, type_info, tip);
|
ssa_emit_store(proc, type_info, tip);
|
||||||
ssa_emit_store(proc, offset, ssa_make_value_constant(a, t_int, make_exact_value_integer(foffset)));
|
ssa_emit_store(proc, offset, ssa_make_value_constant(a, t_int, make_exact_value_integer(foffset)));
|
||||||
}
|
}
|
||||||
@@ -348,13 +364,8 @@ void ssa_gen_tree(ssaGen *s) {
|
|||||||
break;
|
break;
|
||||||
case TypeRecord_RawUnion: {
|
case TypeRecord_RawUnion: {
|
||||||
tag = ssa_add_local_generated(proc, t_type_info_raw_union);
|
tag = ssa_add_local_generated(proc, t_type_info_raw_union);
|
||||||
ssaValue **args = gb_alloc_array(a, ssaValue *, 1);
|
|
||||||
isize element_size = type_size_of(m->sizes, a, t_type_info_member);
|
ssaValue *memory = type_info_member_offset(proc, type_info_member_data, t->Record.field_count, &type_info_member_index);
|
||||||
isize allocation_size = t->Record.field_count * element_size;
|
|
||||||
ssaValue *size = ssa_make_value_constant(a, t_int, make_exact_value_integer(allocation_size));
|
|
||||||
args[0] = size;
|
|
||||||
ssaValue *memory = ssa_emit_global_call(proc, "alloc", args, 1);
|
|
||||||
memory = ssa_emit_conv(proc, memory, t_type_info_member_ptr);
|
|
||||||
|
|
||||||
for (isize i = 0; i < t->Record.field_count; i++) {
|
for (isize i = 0; i < t->Record.field_count; i++) {
|
||||||
ssaValue *field = ssa_emit_ptr_offset(proc, memory, ssa_make_value_constant(a, t_int, make_exact_value_integer(i)));
|
ssaValue *field = ssa_emit_ptr_offset(proc, memory, ssa_make_value_constant(a, t_int, make_exact_value_integer(i)));
|
||||||
@@ -365,7 +376,9 @@ void ssa_gen_tree(ssaGen *s) {
|
|||||||
Entity *f = t->Record.fields[i];
|
Entity *f = t->Record.fields[i];
|
||||||
ssaValue *tip = get_type_info_ptr(proc, type_info_data, f->type);
|
ssaValue *tip = get_type_info_ptr(proc, type_info_data, f->type);
|
||||||
|
|
||||||
ssa_emit_store(proc, name, ssa_emit_global_string(proc, make_exact_value_string(f->token.string)));
|
if (f->token.string.len > 0) {
|
||||||
|
ssa_emit_store(proc, name, ssa_emit_global_string(proc, make_exact_value_string(f->token.string)));
|
||||||
|
}
|
||||||
ssa_emit_store(proc, type_info, tip);
|
ssa_emit_store(proc, type_info, tip);
|
||||||
ssa_emit_store(proc, offset, ssa_make_value_constant(a, t_int, make_exact_value_integer(0)));
|
ssa_emit_store(proc, offset, ssa_make_value_constant(a, t_int, make_exact_value_integer(0)));
|
||||||
}
|
}
|
||||||
@@ -395,12 +408,54 @@ void ssa_gen_tree(ssaGen *s) {
|
|||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case Type_Tuple:
|
case Type_Tuple: {
|
||||||
// TODO(bill): Type_Info for tuples
|
tag = ssa_add_local_generated(proc, t_type_info_tuple);
|
||||||
break;
|
|
||||||
case Type_Proc:
|
ssaValue *memory = type_info_member_offset(proc, type_info_member_data, t->Tuple.variable_count, &type_info_member_index);
|
||||||
|
|
||||||
|
for (isize i = 0; i < t->Tuple.variable_count; i++) {
|
||||||
|
ssaValue *field = ssa_emit_ptr_offset(proc, memory, ssa_make_value_constant(a, t_int, make_exact_value_integer(i)));
|
||||||
|
ssaValue *name = ssa_emit_struct_gep(proc, field, v_zero32, t_string_ptr);
|
||||||
|
ssaValue *type_info = ssa_emit_struct_gep(proc, field, v_one32, t_type_info_ptr_ptr);
|
||||||
|
// NOTE(bill): offset is not used for tuples
|
||||||
|
|
||||||
|
Entity *f = t->Tuple.variables[i];
|
||||||
|
ssaValue *tip = get_type_info_ptr(proc, type_info_data, f->type);
|
||||||
|
|
||||||
|
if (f->token.string.len > 0) {
|
||||||
|
ssa_emit_store(proc, name, ssa_emit_global_string(proc, make_exact_value_string(f->token.string)));
|
||||||
|
}
|
||||||
|
ssa_emit_store(proc, type_info, tip);
|
||||||
|
}
|
||||||
|
|
||||||
|
Type *slice_type = make_type_slice(a, t_type_info_member);
|
||||||
|
Type *slice_type_ptr = make_type_pointer(a, slice_type);
|
||||||
|
ssaValue *slice = ssa_emit_struct_gep(proc, tag, v_zero32, slice_type_ptr);
|
||||||
|
ssaValue *variable_count = ssa_make_value_constant(a, t_int, make_exact_value_integer(t->Tuple.variable_count));
|
||||||
|
|
||||||
|
ssaValue *elem = ssa_emit_struct_gep(proc, slice, v_zero32, make_type_pointer(a, t_type_info_member_ptr));
|
||||||
|
ssaValue *len = ssa_emit_struct_gep(proc, slice, v_one32, make_type_pointer(a, t_int_ptr));
|
||||||
|
ssaValue *cap = ssa_emit_struct_gep(proc, slice, v_two32, make_type_pointer(a, t_int_ptr));
|
||||||
|
|
||||||
|
ssa_emit_store(proc, elem, memory);
|
||||||
|
ssa_emit_store(proc, len, variable_count);
|
||||||
|
ssa_emit_store(proc, cap, variable_count);
|
||||||
|
} break;
|
||||||
|
|
||||||
|
case Type_Proc: {
|
||||||
|
tag = ssa_add_local_generated(proc, t_type_info_procedure);
|
||||||
|
|
||||||
|
ssaValue *params = ssa_emit_struct_gep(proc, tag, v_zero32, t_type_info_ptr_ptr);
|
||||||
|
ssaValue *results = ssa_emit_struct_gep(proc, tag, v_one32, t_type_info_ptr_ptr);
|
||||||
|
ssaValue *variadic = ssa_emit_struct_gep(proc, tag, v_two32, t_bool_ptr);
|
||||||
|
|
||||||
|
|
||||||
|
ssa_emit_store(proc, params, get_type_info_ptr(proc, type_info_data, t->Proc.params));
|
||||||
|
ssa_emit_store(proc, results, get_type_info_ptr(proc, type_info_data, t->Proc.results));
|
||||||
|
ssa_emit_store(proc, variadic, ssa_make_value_constant(a, t_bool, make_exact_value_bool(t->Proc.variadic)));
|
||||||
|
|
||||||
// TODO(bill): Type_Info for procedures
|
// TODO(bill): Type_Info for procedures
|
||||||
break;
|
} break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tag != NULL) {
|
if (tag != NULL) {
|
||||||
|
|||||||
+46
-13
@@ -294,6 +294,7 @@ ssaAddr ssa_make_addr_vector(ssaValue *addr, ssaValue *index, AstNode *expr) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ssaValue *ssa_make_value_global(gbAllocator a, Entity *e, ssaValue *value);
|
||||||
|
|
||||||
|
|
||||||
void ssa_module_init(ssaModule *m, Checker *c) {
|
void ssa_module_init(ssaModule *m, Checker *c) {
|
||||||
@@ -310,21 +311,53 @@ void ssa_module_init(ssaModule *m, Checker *c) {
|
|||||||
|
|
||||||
{
|
{
|
||||||
// Add type info data
|
// Add type info data
|
||||||
ssaValue *ssa_make_value_global(gbAllocator a, Entity *e, ssaValue *value);
|
{
|
||||||
|
String name = make_string("__type_info_data");
|
||||||
|
Token token = {Token_Identifier};
|
||||||
|
token.string = name;
|
||||||
|
|
||||||
|
|
||||||
String name = make_string("__type_info_data");
|
isize count = gb_array_count(c->info.type_info_map.entries);
|
||||||
Token token = {};
|
Entity *e = make_entity_variable(m->allocator, NULL, token, make_type_array(m->allocator, t_type_info, count));
|
||||||
token.kind = Token_Identifier;
|
ssaValue *g = ssa_make_value_global(m->allocator, e, NULL);
|
||||||
token.string = name;
|
g->Global.is_private = true;
|
||||||
|
map_set(&m->values, hash_pointer(e), g);
|
||||||
|
map_set(&m->members, hash_string(name), g);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Type info member buffer
|
||||||
|
{
|
||||||
|
// NOTE(bill): Removes need for heap allocation by making it global memory
|
||||||
|
isize count = 0;
|
||||||
|
|
||||||
isize count = gb_array_count(c->info.type_info_map.entries);
|
gb_for_array(entry_index, m->info->type_info_map.entries) {
|
||||||
Entity *e = make_entity_variable(m->allocator, NULL, token, make_type_array(m->allocator, t_type_info, count));
|
auto *entry = &m->info->type_info_map.entries[entry_index];
|
||||||
ssaValue *g = ssa_make_value_global(m->allocator, e, NULL);
|
Type *t = cast(Type *)cast(uintptr)entry->key.key;
|
||||||
g->Global.is_private = true;
|
|
||||||
map_set(&m->values, hash_pointer(e), g);
|
switch (t->kind) {
|
||||||
map_set(&m->members, hash_string(name), g);
|
case Type_Record:
|
||||||
|
switch (t->Record.kind) {
|
||||||
|
case TypeRecord_Struct:
|
||||||
|
case TypeRecord_RawUnion:
|
||||||
|
count += t->Record.field_count;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case Type_Tuple:
|
||||||
|
count += t->Tuple.variable_count;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String name = make_string("__type_info_member_data");
|
||||||
|
Token token = {Token_Identifier};
|
||||||
|
token.string = name;
|
||||||
|
|
||||||
|
Entity *e = make_entity_variable(m->allocator, NULL, token,
|
||||||
|
make_type_array(m->allocator, t_type_info_member, count));
|
||||||
|
ssaValue *g = ssa_make_value_global(m->allocator, e, NULL);
|
||||||
|
map_set(&m->values, hash_pointer(e), g);
|
||||||
|
map_set(&m->members, hash_string(name), g);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2087,7 +2120,7 @@ ssaValue *ssa_build_single_expr(ssaProcedure *proc, AstNode *expr, TypeAndValue
|
|||||||
args[1] = src;
|
args[1] = src;
|
||||||
args[2] = byte_count;
|
args[2] = byte_count;
|
||||||
|
|
||||||
ssa_emit_global_call(proc, "memory_move", args, 3);
|
ssa_emit_global_call(proc, "memory_copy", args, 3);
|
||||||
|
|
||||||
return len;
|
return len;
|
||||||
} break;
|
} break;
|
||||||
@@ -2137,7 +2170,7 @@ ssaValue *ssa_build_single_expr(ssaProcedure *proc, AstNode *expr, TypeAndValue
|
|||||||
args[1] = item;
|
args[1] = item;
|
||||||
args[2] = byte_count;
|
args[2] = byte_count;
|
||||||
|
|
||||||
ssa_emit_global_call(proc, "memory_move", args, 3);
|
ssa_emit_global_call(proc, "memory_copy", args, 3);
|
||||||
|
|
||||||
// Increment slice length
|
// Increment slice length
|
||||||
Token add = {Token_Add};
|
Token add = {Token_Add};
|
||||||
|
|||||||
+10
-5
@@ -245,6 +245,7 @@ AST_NODE_KIND(_TypeBegin, "", struct{}) \
|
|||||||
AstNodeArray decls; \
|
AstNodeArray decls; \
|
||||||
isize decl_count; \
|
isize decl_count; \
|
||||||
b32 is_packed; \
|
b32 is_packed; \
|
||||||
|
b32 is_ordered; \
|
||||||
}) \
|
}) \
|
||||||
AST_NODE_KIND(UnionType, "union type", struct { \
|
AST_NODE_KIND(UnionType, "union type", struct { \
|
||||||
Token token; \
|
Token token; \
|
||||||
@@ -815,12 +816,13 @@ gb_inline AstNode *make_vector_type(AstFile *f, Token token, AstNode *count, Ast
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
gb_inline AstNode *make_struct_type(AstFile *f, Token token, AstNodeArray decls, isize decl_count, b32 is_packed) {
|
gb_inline AstNode *make_struct_type(AstFile *f, Token token, AstNodeArray decls, isize decl_count, b32 is_packed, b32 is_ordered) {
|
||||||
AstNode *result = make_node(f, AstNode_StructType);
|
AstNode *result = make_node(f, AstNode_StructType);
|
||||||
result->StructType.token = token;
|
result->StructType.token = token;
|
||||||
result->StructType.decls = decls;
|
result->StructType.decls = decls;
|
||||||
result->StructType.decl_count = decl_count;
|
result->StructType.decl_count = decl_count;
|
||||||
result->StructType.is_packed = is_packed;
|
result->StructType.is_packed = is_packed;
|
||||||
|
result->StructType.is_ordered = is_ordered;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1826,12 +1828,15 @@ AstNode *parse_identifier_or_type(AstFile *f) {
|
|||||||
case Token_struct: {
|
case Token_struct: {
|
||||||
Token token = expect_token(f, Token_struct);
|
Token token = expect_token(f, Token_struct);
|
||||||
b32 is_packed = false;
|
b32 is_packed = false;
|
||||||
if (allow_token(f, Token_Hash)) {
|
b32 is_ordered = false;
|
||||||
|
while (allow_token(f, Token_Hash)) {
|
||||||
Token tag = expect_token(f, Token_Identifier);
|
Token tag = expect_token(f, Token_Identifier);
|
||||||
if (are_strings_equal(tag.string, make_string("packed"))) {
|
if (are_strings_equal(tag.string, make_string("packed"))) {
|
||||||
is_packed = true;
|
is_packed = true;
|
||||||
} else {
|
} else if (are_strings_equal(tag.string, make_string("ordered"))) {
|
||||||
ast_file_err(f, tag, "Expected a `#packed` tag");
|
is_ordered = true;
|
||||||
|
} else {
|
||||||
|
ast_file_err(f, tag, "Expected a `#packed` or `#ordered` tag");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1840,7 +1845,7 @@ AstNode *parse_identifier_or_type(AstFile *f) {
|
|||||||
AstNodeArray decls = parse_struct_params(f, &decl_count, true);
|
AstNodeArray decls = parse_struct_params(f, &decl_count, true);
|
||||||
Token close = expect_token(f, Token_CloseBrace);
|
Token close = expect_token(f, Token_CloseBrace);
|
||||||
|
|
||||||
return make_struct_type(f, token, decls, decl_count, is_packed);
|
return make_struct_type(f, token, decls, decl_count, is_packed, is_ordered);
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case Token_union: {
|
case Token_union: {
|
||||||
|
|||||||
@@ -43,6 +43,46 @@ gb_inline b32 are_strings_equal_ignore_case(String a, String b) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GB_COMPARE_PROC(string_cmp) {
|
||||||
|
String x = *cast(String *)a;
|
||||||
|
String y = *cast(String *)b;
|
||||||
|
|
||||||
|
if (x.len == y.len &&
|
||||||
|
x.text == y.text) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
isize n = gb_min(x.len, y.len);
|
||||||
|
|
||||||
|
isize fast = n/gb_size_of(isize) + 1;
|
||||||
|
isize offset = (fast-1)*gb_size_of(isize);
|
||||||
|
isize curr_block = 0;
|
||||||
|
if (n <= gb_size_of(isize)) {
|
||||||
|
fast = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
isize *la = cast(isize *)x.text;
|
||||||
|
isize *lb = cast(isize *)y.text;
|
||||||
|
|
||||||
|
for (; curr_block < fast; curr_block++) {
|
||||||
|
if ((la[curr_block] ^ lb[curr_block]) != 0) {
|
||||||
|
for (isize pos = curr_block*gb_size_of(isize); pos < n; pos++) {
|
||||||
|
if ((x.text[pos] ^ y.text[pos]) != 0) {
|
||||||
|
return cast(int)x.text[pos] - cast(int)y.text[pos];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (; offset < n; offset++) {
|
||||||
|
if ((x.text[offset] ^ y.text[offset]) != 0) {
|
||||||
|
return cast(int)x.text[offset] - cast(int)y.text[offset];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
gb_inline isize string_extension_position(String str) {
|
gb_inline isize string_extension_position(String str) {
|
||||||
isize dot_pos = -1;
|
isize dot_pos = -1;
|
||||||
|
|||||||
Reference in New Issue
Block a user