mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-05 23:28:48 +00:00
Fix alignment and size bug of enums; Remove #ordered and make the default #ordered.
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
#import "fmt.odin";
|
#import "fmt.odin";
|
||||||
#import "math.odin";
|
|
||||||
|
|
||||||
main :: proc() {
|
main :: proc() {
|
||||||
immutable program := "+ + * - /";
|
immutable program := "+ + * - /";
|
||||||
|
|||||||
+7
-7
@@ -25,7 +25,7 @@ Calling_Convention :: enum {
|
|||||||
FAST = 3,
|
FAST = 3,
|
||||||
}
|
}
|
||||||
|
|
||||||
Type_Info_Record :: struct #ordered {
|
Type_Info_Record :: struct {
|
||||||
types: []^Type_Info,
|
types: []^Type_Info,
|
||||||
names: []string,
|
names: []string,
|
||||||
offsets: []int, // offsets may not be used in tuples
|
offsets: []int, // offsets may not be used in tuples
|
||||||
@@ -144,13 +144,13 @@ Allocator_Mode :: enum u8 {
|
|||||||
Allocator_Proc :: #type proc(allocator_data: rawptr, mode: Allocator_Mode,
|
Allocator_Proc :: #type 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;
|
||||||
Allocator :: struct #ordered {
|
Allocator :: struct {
|
||||||
procedure: Allocator_Proc,
|
procedure: Allocator_Proc,
|
||||||
data: rawptr,
|
data: rawptr,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Context :: struct #ordered {
|
Context :: struct {
|
||||||
thread_id: int,
|
thread_id: int,
|
||||||
|
|
||||||
allocator: Allocator,
|
allocator: Allocator,
|
||||||
@@ -559,18 +559,18 @@ __default_hash_string :: proc(s: string) -> u64 {
|
|||||||
|
|
||||||
__INITIAL_MAP_CAP :: 16;
|
__INITIAL_MAP_CAP :: 16;
|
||||||
|
|
||||||
__Map_Key :: struct #ordered {
|
__Map_Key :: struct {
|
||||||
hash: u64,
|
hash: u64,
|
||||||
str: string,
|
str: string,
|
||||||
}
|
}
|
||||||
|
|
||||||
__Map_Find_Result :: struct #ordered {
|
__Map_Find_Result :: struct {
|
||||||
hash_index: int,
|
hash_index: int,
|
||||||
entry_prev: int,
|
entry_prev: int,
|
||||||
entry_index: int,
|
entry_index: int,
|
||||||
}
|
}
|
||||||
|
|
||||||
__Map_Entry_Header :: struct #ordered {
|
__Map_Entry_Header :: struct {
|
||||||
key: __Map_Key,
|
key: __Map_Key,
|
||||||
next: int,
|
next: int,
|
||||||
/*
|
/*
|
||||||
@@ -578,7 +578,7 @@ __Map_Entry_Header :: struct #ordered {
|
|||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
__Map_Header :: struct #ordered {
|
__Map_Header :: struct {
|
||||||
m: ^raw.Dynamic_Map,
|
m: ^raw.Dynamic_Map,
|
||||||
is_key_string: bool,
|
is_key_string: bool,
|
||||||
entry_size: int,
|
entry_size: int,
|
||||||
|
|||||||
+2
-2
@@ -36,7 +36,7 @@ RTLD_GLOBAL :: 0x100;
|
|||||||
// "Argv" arguments converted to Odin strings
|
// "Argv" arguments converted to Odin strings
|
||||||
immutable args := _alloc_command_line_arguments();
|
immutable args := _alloc_command_line_arguments();
|
||||||
|
|
||||||
_File_Time :: struct #ordered {
|
_File_Time :: struct {
|
||||||
seconds: i64,
|
seconds: i64,
|
||||||
nanoseconds: i32,
|
nanoseconds: i32,
|
||||||
reserved: i32,
|
reserved: i32,
|
||||||
@@ -46,7 +46,7 @@ _File_Time :: struct #ordered {
|
|||||||
// https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.7-4.6/+/jb-dev/sysroot/usr/include/bits/stat.h
|
// https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.7-4.6/+/jb-dev/sysroot/usr/include/bits/stat.h
|
||||||
// Validity is not guaranteed.
|
// Validity is not guaranteed.
|
||||||
|
|
||||||
Stat :: struct #ordered {
|
Stat :: struct {
|
||||||
device_id: u64, // ID of device containing file
|
device_id: u64, // ID of device containing file
|
||||||
serial: u64, // File serial number
|
serial: u64, // File serial number
|
||||||
nlink: u32, // Number of hard links
|
nlink: u32, // Number of hard links
|
||||||
|
|||||||
+2
-2
@@ -41,12 +41,12 @@ RTLD_FIRST :: 0x100;
|
|||||||
|
|
||||||
args: [dynamic]string;
|
args: [dynamic]string;
|
||||||
|
|
||||||
FileTime :: struct #ordered {
|
FileTime :: struct {
|
||||||
seconds: i64,
|
seconds: i64,
|
||||||
nanoseconds: i64
|
nanoseconds: i64
|
||||||
}
|
}
|
||||||
|
|
||||||
Stat :: struct #ordered {
|
Stat :: struct {
|
||||||
device_id : i32, // ID of device containing file
|
device_id : i32, // ID of device containing file
|
||||||
mode : u16, // Mode of the file
|
mode : u16, // Mode of the file
|
||||||
nlink : u16, // Number of hard links
|
nlink : u16, // Number of hard links
|
||||||
|
|||||||
+5
-5
@@ -1,27 +1,27 @@
|
|||||||
Any :: struct #ordered {
|
Any :: struct {
|
||||||
data: rawptr,
|
data: rawptr,
|
||||||
type_info: ^Type_Info,
|
type_info: ^Type_Info,
|
||||||
}
|
}
|
||||||
|
|
||||||
String :: struct #ordered {
|
String :: struct {
|
||||||
data: ^byte,
|
data: ^byte,
|
||||||
len: int,
|
len: int,
|
||||||
};
|
};
|
||||||
|
|
||||||
Slice :: struct #ordered {
|
Slice :: struct {
|
||||||
data: rawptr,
|
data: rawptr,
|
||||||
len: int,
|
len: int,
|
||||||
cap: int,
|
cap: int,
|
||||||
};
|
};
|
||||||
|
|
||||||
Dynamic_Array :: struct #ordered {
|
Dynamic_Array :: struct {
|
||||||
data: rawptr,
|
data: rawptr,
|
||||||
len: int,
|
len: int,
|
||||||
cap: int,
|
cap: int,
|
||||||
allocator: Allocator,
|
allocator: Allocator,
|
||||||
};
|
};
|
||||||
|
|
||||||
Dynamic_Map :: struct #ordered {
|
Dynamic_Map :: struct {
|
||||||
hashes: [dynamic]int,
|
hashes: [dynamic]int,
|
||||||
entries: Dynamic_Array,
|
entries: Dynamic_Array,
|
||||||
};
|
};
|
||||||
|
|||||||
+3
-3
@@ -12,7 +12,7 @@ CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB :: 0x00000002;
|
|||||||
Hglrc :: Handle;
|
Hglrc :: Handle;
|
||||||
Color_Ref :: u32;
|
Color_Ref :: u32;
|
||||||
|
|
||||||
Layer_Plane_Descriptor :: struct #ordered {
|
Layer_Plane_Descriptor :: struct {
|
||||||
size: u16,
|
size: u16,
|
||||||
version: u16,
|
version: u16,
|
||||||
flags: u32,
|
flags: u32,
|
||||||
@@ -39,11 +39,11 @@ Layer_Plane_Descriptor :: struct #ordered {
|
|||||||
transparent: Color_Ref,
|
transparent: Color_Ref,
|
||||||
}
|
}
|
||||||
|
|
||||||
Point_Float :: struct #ordered {
|
Point_Float :: struct {
|
||||||
x, y: f32,
|
x, y: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
Glyph_Metrics_Float :: struct #ordered {
|
Glyph_Metrics_Float :: struct {
|
||||||
black_box_x: f32,
|
black_box_x: f32,
|
||||||
black_box_y: f32,
|
black_box_y: f32,
|
||||||
glyph_origin: Point_Float,
|
glyph_origin: Point_Float,
|
||||||
|
|||||||
+15
-15
@@ -65,11 +65,11 @@ SM_CYSCREEN :: 1;
|
|||||||
SW_SHOW :: 5;
|
SW_SHOW :: 5;
|
||||||
|
|
||||||
|
|
||||||
Point :: struct #ordered {
|
Point :: struct {
|
||||||
x, y: i32,
|
x, y: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
WndClassExA :: struct #ordered {
|
WndClassExA :: struct {
|
||||||
size, style: u32,
|
size, style: u32,
|
||||||
wnd_proc: Wnd_Proc,
|
wnd_proc: Wnd_Proc,
|
||||||
cls_extra, wnd_extra: i32,
|
cls_extra, wnd_extra: i32,
|
||||||
@@ -81,7 +81,7 @@ WndClassExA :: struct #ordered {
|
|||||||
sm: Hicon,
|
sm: Hicon,
|
||||||
}
|
}
|
||||||
|
|
||||||
Msg :: struct #ordered {
|
Msg :: struct {
|
||||||
hwnd: Hwnd,
|
hwnd: Hwnd,
|
||||||
message: u32,
|
message: u32,
|
||||||
wparam: Wparam,
|
wparam: Wparam,
|
||||||
@@ -90,24 +90,24 @@ Msg :: struct #ordered {
|
|||||||
pt: Point,
|
pt: Point,
|
||||||
}
|
}
|
||||||
|
|
||||||
Rect :: struct #ordered {
|
Rect :: struct {
|
||||||
left: i32,
|
left: i32,
|
||||||
top: i32,
|
top: i32,
|
||||||
right: i32,
|
right: i32,
|
||||||
bottom: i32,
|
bottom: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
Filetime :: struct #ordered {
|
Filetime :: struct {
|
||||||
lo, hi: u32,
|
lo, hi: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
Systemtime :: struct #ordered {
|
Systemtime :: struct {
|
||||||
year, month: u16,
|
year, month: u16,
|
||||||
day_of_week, day: u16,
|
day_of_week, day: u16,
|
||||||
hour, minute, second, millisecond: u16,
|
hour, minute, second, millisecond: u16,
|
||||||
}
|
}
|
||||||
|
|
||||||
By_Handle_File_Information :: struct #ordered {
|
By_Handle_File_Information :: struct {
|
||||||
file_attributes: u32,
|
file_attributes: u32,
|
||||||
creation_time,
|
creation_time,
|
||||||
last_access_time,
|
last_access_time,
|
||||||
@@ -120,7 +120,7 @@ By_Handle_File_Information :: struct #ordered {
|
|||||||
file_index_low: u32,
|
file_index_low: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
File_Attribute_Data :: struct #ordered {
|
File_Attribute_Data :: struct {
|
||||||
file_attributes: u32,
|
file_attributes: u32,
|
||||||
creation_time,
|
creation_time,
|
||||||
last_access_time,
|
last_access_time,
|
||||||
@@ -275,7 +275,7 @@ HEAP_ZERO_MEMORY :: 0x00000008;
|
|||||||
|
|
||||||
// Synchronization
|
// Synchronization
|
||||||
|
|
||||||
Security_Attributes :: struct #ordered {
|
Security_Attributes :: struct {
|
||||||
length: u32,
|
length: u32,
|
||||||
security_descriptor: rawptr,
|
security_descriptor: rawptr,
|
||||||
inherit_handle: Bool,
|
inherit_handle: Bool,
|
||||||
@@ -326,14 +326,14 @@ SWP_NOSIZE :: 0x0001;
|
|||||||
SWP_NOMOVE :: 0x0002;
|
SWP_NOMOVE :: 0x0002;
|
||||||
|
|
||||||
|
|
||||||
Monitor_Info :: struct #ordered {
|
Monitor_Info :: struct {
|
||||||
size: u32,
|
size: u32,
|
||||||
monitor: Rect,
|
monitor: Rect,
|
||||||
work: Rect,
|
work: Rect,
|
||||||
flags: u32,
|
flags: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
Window_Placement :: struct #ordered {
|
Window_Placement :: struct {
|
||||||
length: u32,
|
length: u32,
|
||||||
flags: u32,
|
flags: u32,
|
||||||
show_cmd: u32,
|
show_cmd: u32,
|
||||||
@@ -370,7 +370,7 @@ LOWORD :: proc(lParam: Lparam) -> u16 { return u16(lParam); }
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
Bitmap_Info_Header :: struct #ordered {
|
Bitmap_Info_Header :: struct {
|
||||||
size: u32,
|
size: u32,
|
||||||
width, height: i32,
|
width, height: i32,
|
||||||
planes, bit_count: i16,
|
planes, bit_count: i16,
|
||||||
@@ -381,13 +381,13 @@ Bitmap_Info_Header :: struct #ordered {
|
|||||||
clr_used: u32,
|
clr_used: u32,
|
||||||
clr_important: u32,
|
clr_important: u32,
|
||||||
}
|
}
|
||||||
Bitmap_Info :: struct #ordered {
|
Bitmap_Info :: struct {
|
||||||
using header: Bitmap_Info_Header,
|
using header: Bitmap_Info_Header,
|
||||||
colors: [1]Rgb_Quad,
|
colors: [1]Rgb_Quad,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Rgb_Quad :: struct #ordered { blue, green, red, reserved: byte }
|
Rgb_Quad :: struct { blue, green, red, reserved: byte }
|
||||||
|
|
||||||
BI_RGB :: 0;
|
BI_RGB :: 0;
|
||||||
DIB_RGB_COLORS :: 0x00;
|
DIB_RGB_COLORS :: 0x00;
|
||||||
@@ -433,7 +433,7 @@ PFD_DOUBLEBUFFER_DONTCARE :: 0x40000000;
|
|||||||
PFD_STEREO_DONTCARE :: 0x80000000;
|
PFD_STEREO_DONTCARE :: 0x80000000;
|
||||||
|
|
||||||
|
|
||||||
PIXELFORMATDESCRIPTOR :: struct #ordered {
|
PIXELFORMATDESCRIPTOR :: struct {
|
||||||
size,
|
size,
|
||||||
version,
|
version,
|
||||||
flags: u32,
|
flags: u32,
|
||||||
|
|||||||
+1
-1
@@ -534,7 +534,7 @@ void check_struct_type(Checker *c, Type *struct_type, AstNode *node) {
|
|||||||
|
|
||||||
isize field_count = 0;
|
isize field_count = 0;
|
||||||
for_array(field_index, st->fields) {
|
for_array(field_index, st->fields) {
|
||||||
AstNode *field = st->fields.e[field_index];
|
AstNode *field = st->fields.e[field_index];
|
||||||
switch (field->kind) {
|
switch (field->kind) {
|
||||||
case_ast_node(f, Field, field);
|
case_ast_node(f, Field, field);
|
||||||
field_count += f->names.count;
|
field_count += f->names.count;
|
||||||
|
|||||||
+5
-5
@@ -2745,11 +2745,11 @@ AstNode *parse_type_or_ident(AstFile *f) {
|
|||||||
syntax_error(tag, "Duplicate struct tag `#%.*s`", LIT(tag.string));
|
syntax_error(tag, "Duplicate struct tag `#%.*s`", LIT(tag.string));
|
||||||
}
|
}
|
||||||
is_packed = true;
|
is_packed = true;
|
||||||
} else if (str_eq(tag.string, str_lit("ordered"))) {
|
// } else if (str_eq(tag.string, str_lit("ordered"))) {
|
||||||
if (is_ordered) {
|
// if (is_ordered) {
|
||||||
syntax_error(tag, "Duplicate struct tag `#%.*s`", LIT(tag.string));
|
// syntax_error(tag, "Duplicate struct tag `#%.*s`", LIT(tag.string));
|
||||||
}
|
// }
|
||||||
is_ordered = true;
|
// is_ordered = true;
|
||||||
} else if (str_eq(tag.string, str_lit("align"))) {
|
} else if (str_eq(tag.string, str_lit("align"))) {
|
||||||
if (align) {
|
if (align) {
|
||||||
syntax_error(tag, "Duplicate struct tag `#%.*s`", LIT(tag.string));
|
syntax_error(tag, "Duplicate struct tag `#%.*s`", LIT(tag.string));
|
||||||
|
|||||||
@@ -1595,6 +1595,8 @@ i64 type_align_of_internal(gbAllocator allocator, Type *t, TypePath *path) {
|
|||||||
|
|
||||||
case Type_Record: {
|
case Type_Record: {
|
||||||
switch (t->Record.kind) {
|
switch (t->Record.kind) {
|
||||||
|
case TypeRecord_Enum:
|
||||||
|
return type_align_of_internal(allocator, t->Record.enum_base_type, path);
|
||||||
case TypeRecord_Struct:
|
case TypeRecord_Struct:
|
||||||
if (t->Record.custom_align > 0) {
|
if (t->Record.custom_align > 0) {
|
||||||
return gb_clamp(t->Record.custom_align, 1, build_context.max_align);
|
return gb_clamp(t->Record.custom_align, 1, build_context.max_align);
|
||||||
@@ -1844,6 +1846,9 @@ i64 type_size_of_internal(gbAllocator allocator, Type *t, TypePath *path) {
|
|||||||
|
|
||||||
case Type_Record: {
|
case Type_Record: {
|
||||||
switch (t->Record.kind) {
|
switch (t->Record.kind) {
|
||||||
|
case TypeRecord_Enum:
|
||||||
|
return type_size_of_internal(allocator, t->Record.enum_base_type, path);
|
||||||
|
|
||||||
case TypeRecord_Struct: {
|
case TypeRecord_Struct: {
|
||||||
i64 count = t->Record.field_count;
|
i64 count = t->Record.field_count;
|
||||||
if (count == 0) {
|
if (count == 0) {
|
||||||
|
|||||||
Reference in New Issue
Block a user