Browse Source

Fix alignment and size bug of enums; Remove #ordered and make the default #ordered.

Ginger Bill 8 years ago
parent
commit
cc6282a6e3
10 changed files with 45 additions and 41 deletions
  1. 0 1
      code/demo.odin
  2. 7 7
      core/_preload.odin
  3. 2 2
      core/os_linux.odin
  4. 2 2
      core/os_x.odin
  5. 5 5
      core/raw.odin
  6. 3 3
      core/sys/wgl.odin
  7. 15 15
      core/sys/windows.odin
  8. 1 1
      src/check_expr.c
  9. 5 5
      src/parser.c
  10. 5 0
      src/types.c

+ 0 - 1
code/demo.odin

@@ -1,5 +1,4 @@
 #import "fmt.odin";
-#import "math.odin";
 
 main :: proc() {
 	immutable program := "+ + * - /";

+ 7 - 7
core/_preload.odin

@@ -25,7 +25,7 @@ Calling_Convention :: enum {
 	FAST = 3,
 }
 
-Type_Info_Record :: struct #ordered {
+Type_Info_Record :: struct {
 	types:        []^Type_Info,
 	names:        []string,
 	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,
                              size, alignment: int,
                              old_memory: rawptr, old_size: int, flags: u64) -> rawptr;
-Allocator :: struct #ordered {
+Allocator :: struct {
 	procedure: Allocator_Proc,
 	data:      rawptr,
 }
 
 
-Context :: struct #ordered {
+Context :: struct {
 	thread_id: int,
 
 	allocator: Allocator,
@@ -559,18 +559,18 @@ __default_hash_string :: proc(s: string) -> u64 {
 
 __INITIAL_MAP_CAP :: 16;
 
-__Map_Key :: struct #ordered {
+__Map_Key :: struct {
 	hash: u64,
 	str:  string,
 }
 
-__Map_Find_Result :: struct #ordered {
+__Map_Find_Result :: struct {
 	hash_index:  int,
 	entry_prev:  int,
 	entry_index: int,
 }
 
-__Map_Entry_Header :: struct #ordered {
+__Map_Entry_Header :: struct {
 	key:  __Map_Key,
 	next: int,
 /*
@@ -578,7 +578,7 @@ __Map_Entry_Header :: struct #ordered {
 */
 }
 
-__Map_Header :: struct #ordered {
+__Map_Header :: struct {
 	m:             ^raw.Dynamic_Map,
 	is_key_string: bool,
 	entry_size:    int,

+ 2 - 2
core/os_linux.odin

@@ -36,7 +36,7 @@ RTLD_GLOBAL       :: 0x100;
 // "Argv" arguments converted to Odin strings
 immutable args := _alloc_command_line_arguments();
 
-_File_Time :: struct #ordered {
+_File_Time :: struct {
 	seconds:     i64,
 	nanoseconds: 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
 // Validity is not guaranteed.
 
-Stat :: struct #ordered {
+Stat :: struct {
 	device_id:     u64, // ID of device containing file
 	serial:        u64, // File serial number
 	nlink:         u32, // Number of hard links

+ 2 - 2
core/os_x.odin

@@ -41,12 +41,12 @@ RTLD_FIRST    :: 0x100;
 
 args: [dynamic]string;
 
-FileTime :: struct #ordered {
+FileTime :: struct {
 	seconds: i64,
 	nanoseconds: i64
 }
 
-Stat :: struct #ordered {
+Stat :: struct {
 	device_id : i32, // ID of device containing file
 	mode      : u16, // Mode of the file
 	nlink     : u16, // Number of hard links

+ 5 - 5
core/raw.odin

@@ -1,27 +1,27 @@
-Any :: struct #ordered {
+Any :: struct {
 	data:      rawptr,
 	type_info: ^Type_Info,
 }
 
-String :: struct #ordered {
+String :: struct {
 	data: ^byte,
 	len:  int,
 };
 
-Slice :: struct #ordered {
+Slice :: struct {
 	data: rawptr,
 	len:  int,
 	cap:  int,
 };
 
-Dynamic_Array :: struct #ordered {
+Dynamic_Array :: struct {
 	data:      rawptr,
 	len:       int,
 	cap:       int,
 	allocator: Allocator,
 };
 
-Dynamic_Map :: struct #ordered {
+Dynamic_Map :: struct {
 	hashes:  [dynamic]int,
 	entries: Dynamic_Array,
 };

+ 3 - 3
core/sys/wgl.odin

@@ -12,7 +12,7 @@ CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB :: 0x00000002;
 Hglrc :: Handle;
 Color_Ref :: u32;
 
-Layer_Plane_Descriptor :: struct #ordered {
+Layer_Plane_Descriptor :: struct {
 	size:             u16,
 	version:          u16,
 	flags:            u32,
@@ -39,11 +39,11 @@ Layer_Plane_Descriptor :: struct #ordered {
 	transparent:      Color_Ref,
 }
 
-Point_Float :: struct #ordered {
+Point_Float :: struct {
 	x, y: f32,
 }
 
-Glyph_Metrics_Float :: struct #ordered {
+Glyph_Metrics_Float :: struct {
 	black_box_x:  f32,
 	black_box_y:  f32,
 	glyph_origin: Point_Float,

+ 15 - 15
core/sys/windows.odin

@@ -65,11 +65,11 @@ SM_CYSCREEN :: 1;
 SW_SHOW :: 5;
 
 
-Point :: struct #ordered {
+Point :: struct {
 	x, y: i32,
 }
 
-WndClassExA :: struct #ordered {
+WndClassExA :: struct {
 	size, style:           u32,
 	wnd_proc:              Wnd_Proc,
 	cls_extra, wnd_extra:  i32,
@@ -81,7 +81,7 @@ WndClassExA :: struct #ordered {
 	sm:                    Hicon,
 }
 
-Msg :: struct #ordered {
+Msg :: struct {
 	hwnd:    Hwnd,
 	message: u32,
 	wparam:  Wparam,
@@ -90,24 +90,24 @@ Msg :: struct #ordered {
 	pt:      Point,
 }
 
-Rect :: struct #ordered {
+Rect :: struct {
 	left:   i32,
 	top:    i32,
 	right:  i32,
 	bottom: i32,
 }
 
-Filetime :: struct #ordered {
+Filetime :: struct {
 	lo, hi: u32,
 }
 
-Systemtime :: struct #ordered {
+Systemtime :: struct {
 	year, month: u16,
 	day_of_week, day: u16,
 	hour, minute, second, millisecond: u16,
 }
 
-By_Handle_File_Information :: struct #ordered {
+By_Handle_File_Information :: struct {
 	file_attributes:      u32,
 	creation_time,
 	last_access_time,
@@ -120,7 +120,7 @@ By_Handle_File_Information :: struct #ordered {
 	file_index_low:       u32,
 }
 
-File_Attribute_Data :: struct #ordered {
+File_Attribute_Data :: struct {
 	file_attributes:  u32,
 	creation_time,
 	last_access_time,
@@ -275,7 +275,7 @@ HEAP_ZERO_MEMORY :: 0x00000008;
 
 // Synchronization
 
-Security_Attributes :: struct #ordered {
+Security_Attributes :: struct {
 	length:              u32,
 	security_descriptor: rawptr,
 	inherit_handle:      Bool,
@@ -326,14 +326,14 @@ SWP_NOSIZE        :: 0x0001;
 SWP_NOMOVE        :: 0x0002;
 
 
-Monitor_Info :: struct #ordered {
+Monitor_Info :: struct {
 	size:      u32,
 	monitor:   Rect,
 	work:      Rect,
 	flags:     u32,
 }
 
-Window_Placement :: struct #ordered {
+Window_Placement :: struct {
 	length:     u32,
 	flags:      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,
 	width, height:     i32,
 	planes, bit_count: i16,
@@ -381,13 +381,13 @@ Bitmap_Info_Header :: struct #ordered {
 	clr_used:          u32,
 	clr_important:     u32,
 }
-Bitmap_Info :: struct #ordered {
+Bitmap_Info :: struct {
 	using header: Bitmap_Info_Header,
 	colors:       [1]Rgb_Quad,
 }
 
 
-Rgb_Quad :: struct #ordered { blue, green, red, reserved: byte }
+Rgb_Quad :: struct { blue, green, red, reserved: byte }
 
 BI_RGB         :: 0;
 DIB_RGB_COLORS :: 0x00;
@@ -433,7 +433,7 @@ PFD_DOUBLEBUFFER_DONTCARE :: 0x40000000;
 PFD_STEREO_DONTCARE       :: 0x80000000;
 
 
-PIXELFORMATDESCRIPTOR :: struct #ordered {
+PIXELFORMATDESCRIPTOR :: struct {
 	size,
 	version,
 	flags: u32,

+ 1 - 1
src/check_expr.c

@@ -534,7 +534,7 @@ void check_struct_type(Checker *c, Type *struct_type, AstNode *node) {
 
 	isize field_count = 0;
 	for_array(field_index, st->fields) {
-		AstNode *field = st->fields.e[field_index];
+	AstNode *field = st->fields.e[field_index];
 		switch (field->kind) {
 		case_ast_node(f, Field, field);
 			field_count += f->names.count;

+ 5 - 5
src/parser.c

@@ -2745,11 +2745,11 @@ AstNode *parse_type_or_ident(AstFile *f) {
 					syntax_error(tag, "Duplicate struct tag `#%.*s`", LIT(tag.string));
 				}
 				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"))) {
 				if (align) {
 					syntax_error(tag, "Duplicate struct tag `#%.*s`", LIT(tag.string));

+ 5 - 0
src/types.c

@@ -1595,6 +1595,8 @@ i64 type_align_of_internal(gbAllocator allocator, Type *t, TypePath *path) {
 
 	case Type_Record: {
 		switch (t->Record.kind) {
+		case TypeRecord_Enum:
+			return type_align_of_internal(allocator, t->Record.enum_base_type, path);
 		case TypeRecord_Struct:
 			if (t->Record.custom_align > 0) {
 				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: {
 		switch (t->Record.kind) {
+		case TypeRecord_Enum:
+			return type_size_of_internal(allocator, t->Record.enum_base_type, path);
+
 		case TypeRecord_Struct: {
 			i64 count = t->Record.field_count;
 			if (count == 0) {