Browse Source

Fix typeid information for enumerated arrays

gingerBill 5 years ago
parent
commit
978d7fcb99
2 changed files with 21 additions and 20 deletions
  1. 7 8
      core/runtime/core.odin
  2. 14 12
      src/ir.cpp

+ 7 - 8
core/runtime/core.odin

@@ -192,6 +192,7 @@ Typeid_Kind :: enum u8 {
 	Pointer,
 	Procedure,
 	Array,
+	Enumerated_Array,
 	Dynamic_Array,
 	Slice,
 	Tuple,
@@ -280,10 +281,10 @@ Logger :: struct {
 }
 
 Context :: struct {
-	allocator:      Allocator,
-	temp_allocator: Allocator,
+	allocator:              Allocator,
+	temp_allocator:         Allocator,
 	assertion_failure_proc: Assertion_Failure_Proc,
-	logger: Logger,
+	logger:                 Logger,
 
 	stdin:  os.Handle,
 	stdout: os.Handle,
@@ -294,8 +295,6 @@ Context :: struct {
 	user_data:  any,
 	user_ptr:   rawptr,
 	user_index: int,
-
-	derived:    any, // May be used for derived data types
 }
 
 
@@ -488,14 +487,14 @@ default_assertion_failure_proc :: proc(prefix, message: string, loc: Source_Code
 @builtin
 copy_slice :: proc "contextless" (dst, src: $T/[]$E) -> int {
 	n := max(0, min(len(dst), len(src)));
-	if n > 0 do mem_copy(&dst[0], &src[0], n*size_of(E));
+	#no_bounds_check if n > 0 do mem_copy(&dst[0], &src[0], n*size_of(E));
 	return n;
 }
 @builtin
 copy_from_string :: proc "contextless" (dst: $T/[]$E/u8, src: $S/string) -> int {
 	n := max(0, min(len(dst), len(src)));
 	if n > 0 {
-		d := &dst[0];
+		d := (transmute(Raw_Slice)dst).data;
 		s := (transmute(Raw_String)src).data;
 		mem_copy(d, s, n);
 	}
@@ -511,7 +510,7 @@ copy :: proc{copy_slice, copy_from_string};
 pop :: proc "contextless" (array: ^$T/[dynamic]$E) -> E {
 	if array == nil do return E{};
 	assert(len(array) > 0);
-	res := array[len(array)-1];
+	res := #no_bounds_check array[len(array)-1];
 	(^Raw_Dynamic_Array)(array).len -= 1;
 	return res;
 }

+ 14 - 12
src/ir.cpp

@@ -5853,6 +5853,7 @@ enum Typeid_Kind : u8 {
 	Typeid_Pointer,
 	Typeid_Procedure,
 	Typeid_Array,
+	Typeid_Enumerated_Array,
 	Typeid_Dynamic_Array,
 	Typeid_Slice,
 	Typeid_Tuple,
@@ -5890,18 +5891,19 @@ irValue *ir_typeid(irModule *m, Type *type) {
 		if (flags & BasicFlag_String)   kind = Typeid_String;
 		if (flags & BasicFlag_Rune)     kind = Typeid_Rune;
 	} break;
-	case Type_Pointer:      kind = Typeid_Pointer;       break;
-	case Type_Array:        kind = Typeid_Array;         break;
-	case Type_Slice:        kind = Typeid_Slice;         break;
-	case Type_DynamicArray: kind = Typeid_Dynamic_Array; break;
-	case Type_Map:          kind = Typeid_Map;           break;
-	case Type_Struct:       kind = Typeid_Struct;        break;
-	case Type_Enum:         kind = Typeid_Enum;          break;
-	case Type_Union:        kind = Typeid_Union;         break;
-	case Type_Tuple:        kind = Typeid_Tuple;         break;
-	case Type_Proc:         kind = Typeid_Procedure;     break;
-	case Type_BitField:     kind = Typeid_Bit_Field;     break;
-	case Type_BitSet:       kind = Typeid_Bit_Set;       break;
+	case Type_Pointer:         kind = Typeid_Pointer;       break;
+	case Type_Array:           kind = Typeid_Array;         break;
+	case Type_EnumeratedArray: kind = Typeid_Enumerated_Array; break;
+	case Type_Slice:           kind = Typeid_Slice;         break;
+	case Type_DynamicArray:    kind = Typeid_Dynamic_Array; break;
+	case Type_Map:             kind = Typeid_Map;           break;
+	case Type_Struct:          kind = Typeid_Struct;        break;
+	case Type_Enum:            kind = Typeid_Enum;          break;
+	case Type_Union:           kind = Typeid_Union;         break;
+	case Type_Tuple:           kind = Typeid_Tuple;         break;
+	case Type_Proc:            kind = Typeid_Procedure;     break;
+	case Type_BitField:        kind = Typeid_Bit_Field;     break;
+	case Type_BitSet:          kind = Typeid_Bit_Set;       break;
 	}
 
 	if (is_type_cstring(type)) {