Browse Source

Fix for in enum iteration

gingerBill 7 years ago
parent
commit
a65eadee63
5 changed files with 9 additions and 31 deletions
  1. 0 5
      core/fmt/fmt.odin
  2. 0 1
      core/runtime/core.odin
  3. 1 1
      core/runtime/internal.odin
  4. 1 14
      src/check_expr.cpp
  5. 7 10
      src/ir.cpp

+ 0 - 5
core/fmt/fmt.odin

@@ -717,9 +717,6 @@ enum_value_to_string :: proc(v: any) -> (string, bool) {
 		case u64:     return get_str(v, e);
 		case u64:     return get_str(v, e);
 		case uint:    return get_str(v, e);
 		case uint:    return get_str(v, e);
 		case uintptr: return get_str(v, e);
 		case uintptr: return get_str(v, e);
-
-		case f32:  return get_str(v, e);
-		case f64:  return get_str(v, e);
 		}
 		}
 	}
 	}
 
 
@@ -778,8 +775,6 @@ enum_value_to_u64 :: proc(ev: runtime.Type_Info_Enum_Value) -> u64 {
 	case u64:     return u64(i);
 	case u64:     return u64(i);
 	case uint:    return u64(i);
 	case uint:    return u64(i);
 	case uintptr: return u64(i);
 	case uintptr: return u64(i);
-	case f32:     return u64(i);
-	case f64:     return u64(i);
 	}
 	}
 	return 0;
 	return 0;
 }
 }

+ 0 - 1
core/runtime/core.odin

@@ -37,7 +37,6 @@ Type_Info_Enum_Value :: union {
 	rune,
 	rune,
 	i8, i16, i32, i64, int,
 	i8, i16, i32, i64, int,
 	u8, u16, u32, u64, uint, uintptr,
 	u8, u16, u32, u64, uint, uintptr,
-	f32, f64,
 };
 };
 
 
 // Variant Types
 // Variant Types

+ 1 - 1
core/runtime/internal.odin

@@ -299,7 +299,7 @@ type_assertion_check :: proc "contextless" (ok: bool, file: string, line, column
 
 
 	fd := os.stderr;
 	fd := os.stderr;
 	__print_caller_location(fd, Source_Code_Location{file, line, column, ""});
 	__print_caller_location(fd, Source_Code_Location{file, line, column, ""});
-	os.write_string(fd, " Invalid type assertion from");
+	os.write_string(fd, " Invalid type assertion from ");
 	__print_typeid(fd, from);
 	__print_typeid(fd, from);
 	os.write_string(fd, " to ");
 	os.write_string(fd, " to ");
 	__print_typeid(fd, to);
 	__print_typeid(fd, to);

+ 1 - 14
src/check_expr.cpp

@@ -1839,23 +1839,10 @@ bool check_is_castable_to(CheckerContext *c, Operand *operand, Type *y) {
 
 
 	// Cast between pointers
 	// Cast between pointers
 	if (is_type_pointer(src) && is_type_pointer(dst)) {
 	if (is_type_pointer(src) && is_type_pointer(dst)) {
-		#if 0
-		Type *s = base_type(type_deref(src));
-		if (is_type_union(s)) {
-			// NOTE(bill): Should the error be here?!
-			// NOTE(bill): This error should suppress the next casting error as it's at the same position
-			gbString xs = type_to_string(x);
-			gbString ys = type_to_string(y);
-			error(operand->expr, "Cannot cast from a union pointer '%s' to '%s', try using 'union_cast' or cast to a 'rawptr'", xs, ys);
-			gb_string_free(ys);
-			gb_string_free(xs);
-			return false;
-		}
-		#endif
 		return true;
 		return true;
 	}
 	}
 
 
-	// (u)int <-> pointer
+	// uintptr <-> pointer
 	if (is_type_uintptr(src) && is_type_pointer(dst)) {
 	if (is_type_uintptr(src) && is_type_pointer(dst)) {
 		return true;
 		return true;
 	}
 	}

+ 7 - 10
src/ir.cpp

@@ -6419,11 +6419,12 @@ void ir_build_range_enum(irProcedure *proc, Type *enum_type, Type *val_type, irV
 	Type *enum_ptr = alloc_type_pointer(t);
 	Type *enum_ptr = alloc_type_pointer(t);
 	t = base_type(t);
 	t = base_type(t);
 	Type *core_elem = core_type(t);
 	Type *core_elem = core_type(t);
+	GB_ASSERT(t->kind == Type_Enum);
 	i64 enum_count = t->Enum.fields.count;
 	i64 enum_count = t->Enum.fields.count;
 	irValue *max_count = ir_const_int(enum_count);
 	irValue *max_count = ir_const_int(enum_count);
 
 
 	irValue *ti          = ir_type_info(proc, t);
 	irValue *ti          = ir_type_info(proc, t);
-	irValue *variant     = ir_emit_struct_ep(proc, ti, 2);
+	irValue *variant     = ir_emit_struct_ep(proc, ti, 3);
 	irValue *eti_ptr     = ir_emit_conv(proc, variant, t_type_info_enum_ptr);
 	irValue *eti_ptr     = ir_emit_conv(proc, variant, t_type_info_enum_ptr);
 	irValue *values      = ir_emit_load(proc, ir_emit_struct_ep(proc, eti_ptr, 2));
 	irValue *values      = ir_emit_load(proc, ir_emit_struct_ep(proc, eti_ptr, 2));
 	irValue *values_data = ir_slice_elem(proc, values);
 	irValue *values_data = ir_slice_elem(proc, values);
@@ -6448,10 +6449,9 @@ void ir_build_range_enum(irProcedure *proc, Type *enum_type, Type *val_type, irV
 
 
 	irValue *val = nullptr;
 	irValue *val = nullptr;
 	if (val_type != nullptr) {
 	if (val_type != nullptr) {
-		if (is_type_float(core_elem)) {
-			irValue *f = ir_emit_load(proc, ir_emit_conv(proc, val_ptr, t_f64_ptr));
-			val = ir_emit_conv(proc, f, t);
-		} else if (is_type_integer(core_elem)) {
+		GB_ASSERT(are_types_identical(enum_type, val_type));
+
+		if (is_type_integer(core_elem)) {
 			irValue *i = ir_emit_load(proc, ir_emit_conv(proc, val_ptr, t_i64_ptr));
 			irValue *i = ir_emit_load(proc, ir_emit_conv(proc, val_ptr, t_i64_ptr));
 			val = ir_emit_conv(proc, i, t);
 			val = ir_emit_conv(proc, i, t);
 		} else {
 		} else {
@@ -6831,7 +6831,7 @@ void ir_build_stmt_internal(irProcedure *proc, Ast *node) {
 		if (is_ast_range(expr)) {
 		if (is_ast_range(expr)) {
 			ir_build_range_interval(proc, &expr->BinaryExpr, val0_type, &val, &key, &loop, &done);
 			ir_build_range_interval(proc, &expr->BinaryExpr, val0_type, &val, &key, &loop, &done);
 		} else if (tav.mode == Addressing_Type) {
 		} else if (tav.mode == Addressing_Type) {
-			ir_build_range_enum(proc, tav.type, val0_type, &val, &key, &loop, &done);
+			ir_build_range_enum(proc, type_deref(tav.type), val0_type, &val, &key, &loop, &done);
 		} else {
 		} else {
 			Type *expr_type = type_of_expr(rs->expr);
 			Type *expr_type = type_of_expr(rs->expr);
 			Type *et = base_type(type_deref(expr_type));
 			Type *et = base_type(type_deref(expr_type));
@@ -7936,10 +7936,7 @@ void ir_setup_type_info_data(irProcedure *proc) { // NOTE(bill): Setup type_info
 					irValue *value_array = ir_generate_array(m, t_type_info_enum_value, fields.count,
 					irValue *value_array = ir_generate_array(m, t_type_info_enum_value, fields.count,
 					                                         str_lit("__$enum_values"), cast(i64)entry_index);
 					                                         str_lit("__$enum_values"), cast(i64)entry_index);
 
 
-					bool is_value_int = is_type_integer(t->Enum.base_type);
-					if (!is_value_int) {
-						GB_ASSERT(is_type_float(t->Enum.base_type));
-					}
+					GB_ASSERT(is_type_integer(t->Enum.base_type));
 
 
 					for_array(i, fields) {
 					for_array(i, fields) {
 						irValue *name_ep  = ir_emit_array_epi(proc, name_array, cast(i32)i);
 						irValue *name_ep  = ir_emit_array_epi(proc, name_array, cast(i32)i);