浏览代码

Reimplement #ordered again

Ginger Bill 8 年之前
父节点
当前提交
45eecc0905
共有 6 个文件被更改,包括 40 次插入37 次删除
  1. 7 7
      core/_preload.odin
  2. 2 2
      core/os_linux.odin
  3. 2 2
      core/os_x.odin
  4. 16 16
      core/sys/windows.odin
  5. 8 5
      src/check_expr.c
  6. 5 5
      src/parser.c

+ 7 - 7
core/_preload.odin

@@ -25,7 +25,7 @@ Calling_Convention :: enum {
 	FAST = 3,
 	FAST = 3,
 }
 }
 
 
-Type_Info_Record :: struct {
+Type_Info_Record :: struct #ordered {
 	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 {
+Allocator :: struct #ordered {
 	procedure: Allocator_Proc,
 	procedure: Allocator_Proc,
 	data:      rawptr,
 	data:      rawptr,
 }
 }
 
 
 
 
-Context :: struct {
+Context :: struct #ordered {
 	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 {
+__Map_Key :: struct #ordered {
 	hash: u64,
 	hash: u64,
 	str:  string,
 	str:  string,
 }
 }
 
 
-__Map_Find_Result :: struct {
+__Map_Find_Result :: struct #ordered {
 	hash_index:  int,
 	hash_index:  int,
 	entry_prev:  int,
 	entry_prev:  int,
 	entry_index: int,
 	entry_index: int,
 }
 }
 
 
-__Map_Entry_Header :: struct {
+__Map_Entry_Header :: struct #ordered {
 	key:  __Map_Key,
 	key:  __Map_Key,
 	next: int,
 	next: int,
 /*
 /*
@@ -578,7 +578,7 @@ __Map_Entry_Header :: struct {
 */
 */
 }
 }
 
 
-__Map_Header :: struct {
+__Map_Header :: struct #ordered {
 	m:             ^raw.Dynamic_Map,
 	m:             ^raw.Dynamic_Map,
 	is_key_string: bool,
 	is_key_string: bool,
 	entry_size:    int,
 	entry_size:    int,

+ 2 - 2
core/os_linux.odin

@@ -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 {
+_File_Time :: struct #ordered {
 	seconds:     i64,
 	seconds:     i64,
 	nanoseconds: i32,
 	nanoseconds: i32,
 	reserved:    i32,
 	reserved:    i32,
@@ -46,7 +46,7 @@ _File_Time :: struct {
 //  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 {
+Stat :: struct #ordered {
 	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
core/os_x.odin

@@ -41,12 +41,12 @@ RTLD_FIRST    :: 0x100;
 
 
 args: [dynamic]string;
 args: [dynamic]string;
 
 
-FileTime :: struct {
+FileTime :: struct #ordered {
 	seconds: i64,
 	seconds: i64,
 	nanoseconds: i64
 	nanoseconds: i64
 }
 }
 
 
-Stat :: struct {
+Stat :: struct #ordered {
 	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

+ 16 - 16
core/sys/windows.odin

@@ -65,11 +65,11 @@ SM_CYSCREEN :: 1;
 SW_SHOW :: 5;
 SW_SHOW :: 5;
 
 
 
 
-Point :: struct {
+Point :: struct #ordered {
 	x, y: i32,
 	x, y: i32,
 }
 }
 
 
-WndClassExA :: struct {
+WndClassExA :: struct #ordered {
 	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 {
 	sm:                    Hicon,
 	sm:                    Hicon,
 }
 }
 
 
-Msg :: struct {
+Msg :: struct #ordered {
 	hwnd:    Hwnd,
 	hwnd:    Hwnd,
 	message: u32,
 	message: u32,
 	wparam:  Wparam,
 	wparam:  Wparam,
@@ -90,24 +90,24 @@ Msg :: struct {
 	pt:      Point,
 	pt:      Point,
 }
 }
 
 
-Rect :: struct {
+Rect :: struct #ordered {
 	left:   i32,
 	left:   i32,
 	top:    i32,
 	top:    i32,
 	right:  i32,
 	right:  i32,
 	bottom: i32,
 	bottom: i32,
 }
 }
 
 
-Filetime :: struct {
+Filetime :: struct #ordered {
 	lo, hi: u32,
 	lo, hi: u32,
 }
 }
 
 
-Systemtime :: struct {
+Systemtime :: struct #ordered {
 	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 {
+By_Handle_File_Information :: struct #ordered {
 	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 {
 	file_index_low:       u32,
 	file_index_low:       u32,
 }
 }
 
 
-File_Attribute_Data :: struct {
+File_Attribute_Data :: struct #ordered {
 	file_attributes:  u32,
 	file_attributes:  u32,
 	creation_time,
 	creation_time,
 	last_access_time,
 	last_access_time,
@@ -129,7 +129,7 @@ File_Attribute_Data :: struct {
 	file_size_low:    u32,
 	file_size_low:    u32,
 }
 }
 
 
-Find_Data :: struct {
+Find_Data :: struct #ordered {
     file_attributes     : u32,
     file_attributes     : u32,
     creation_time       : Filetime,
     creation_time       : Filetime,
     last_access_time    : Filetime,
     last_access_time    : Filetime,
@@ -299,7 +299,7 @@ HEAP_ZERO_MEMORY :: 0x00000008;
 
 
 // Synchronization
 // Synchronization
 
 
-Security_Attributes :: struct {
+Security_Attributes :: struct #ordered {
 	length:              u32,
 	length:              u32,
 	security_descriptor: rawptr,
 	security_descriptor: rawptr,
 	inherit_handle:      Bool,
 	inherit_handle:      Bool,
@@ -350,14 +350,14 @@ SWP_NOSIZE        :: 0x0001;
 SWP_NOMOVE        :: 0x0002;
 SWP_NOMOVE        :: 0x0002;
 
 
 
 
-Monitor_Info :: struct {
+Monitor_Info :: struct #ordered {
 	size:      u32,
 	size:      u32,
 	monitor:   Rect,
 	monitor:   Rect,
 	work:      Rect,
 	work:      Rect,
 	flags:     u32,
 	flags:     u32,
 }
 }
 
 
-Window_Placement :: struct {
+Window_Placement :: struct #ordered {
 	length:     u32,
 	length:     u32,
 	flags:      u32,
 	flags:      u32,
 	show_cmd:   u32,
 	show_cmd:   u32,
@@ -394,7 +394,7 @@ LOWORD :: proc(lParam: Lparam) -> u16 { return u16(lParam); }
 
 
 
 
 
 
-Bitmap_Info_Header :: struct {
+Bitmap_Info_Header :: struct #ordered {
 	size:              u32,
 	size:              u32,
 	width, height:     i32,
 	width, height:     i32,
 	planes, bit_count: i16,
 	planes, bit_count: i16,
@@ -405,13 +405,13 @@ Bitmap_Info_Header :: struct {
 	clr_used:          u32,
 	clr_used:          u32,
 	clr_important:     u32,
 	clr_important:     u32,
 }
 }
-Bitmap_Info :: struct {
+Bitmap_Info :: struct #ordered {
 	using header: Bitmap_Info_Header,
 	using header: Bitmap_Info_Header,
 	colors:       [1]Rgb_Quad,
 	colors:       [1]Rgb_Quad,
 }
 }
 
 
 
 
-Rgb_Quad :: struct { blue, green, red, reserved: byte }
+Rgb_Quad :: struct #ordered { blue, green, red, reserved: byte }
 
 
 BI_RGB         :: 0;
 BI_RGB         :: 0;
 DIB_RGB_COLORS :: 0x00;
 DIB_RGB_COLORS :: 0x00;
@@ -457,7 +457,7 @@ PFD_DOUBLEBUFFER_DONTCARE :: 0x40000000;
 PFD_STEREO_DONTCARE       :: 0x80000000;
 PFD_STEREO_DONTCARE       :: 0x80000000;
 
 
 
 
-PIXELFORMATDESCRIPTOR :: struct {
+PIXELFORMATDESCRIPTOR :: struct #ordered {
 	size,
 	size,
 	version,
 	version,
 	flags: u32,
 	flags: u32,

+ 8 - 5
src/check_expr.c

@@ -555,7 +555,13 @@ void check_struct_type(Checker *c, Type *struct_type, AstNode *node) {
 	struct_type->Record.field_count         = field_count;
 	struct_type->Record.field_count         = field_count;
 	struct_type->Record.names = make_names_field_for_record(c, c->context.scope);
 	struct_type->Record.names = make_names_field_for_record(c, c->context.scope);
 
 
-	if (false && !st->is_packed && !st->is_ordered) {
+	type_set_offsets(c->allocator, struct_type);
+
+
+	if (!struct_type->failure && !st->is_packed && !st->is_ordered) {
+		struct_type->failure = false;
+		struct_type->Record.are_offsets_set = false;
+		struct_type->Record.offsets = NULL;
 		// NOTE(bill): Reorder fields for reduced size/performance
 		// NOTE(bill): Reorder fields for reduced size/performance
 
 
 		Entity **reordered_fields = gb_alloc_array(c->allocator, Entity *, field_count);
 		Entity **reordered_fields = gb_alloc_array(c->allocator, Entity *, field_count);
@@ -576,12 +582,9 @@ void check_struct_type(Checker *c, Type *struct_type, AstNode *node) {
 		struct_type->Record.fields = reordered_fields;
 		struct_type->Record.fields = reordered_fields;
 	}
 	}
 
 
-	{
-		// i64 size = type_size_of(c->allocator, struct_type);
-	}
-
 	type_set_offsets(c->allocator, struct_type);
 	type_set_offsets(c->allocator, struct_type);
 
 
+
 	if (st->align != NULL) {
 	if (st->align != NULL) {
 		if (st->is_packed) {
 		if (st->is_packed) {
 			syntax_error_node(st->align, "`#align` cannot be applied with `#packed`");
 			syntax_error_node(st->align, "`#align` cannot be applied with `#packed`");

+ 5 - 5
src/parser.c

@@ -2746,11 +2746,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"))) {
-				// if (is_ordered) {
-					// syntax_error(tag, "Duplicate struct tag `#%.*s`", LIT(tag.string));
-				// }
-				// is_ordered = true;
+			} else if (str_eq(tag.string, str_lit("ordered"))) {
+				if (is_ordered) {
+					syntax_error(tag, "Duplicate struct tag `#%.*s`", LIT(tag.string));
+				}
+				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));