Browse Source

Merge remote-tracking branch 'origin/master'

gingerBill 5 years ago
parent
commit
527b39ce2b
3 changed files with 61 additions and 6 deletions
  1. 2 1
      core/fmt/fmt.odin
  2. 27 0
      src/check_expr.cpp
  3. 32 5
      src/ir.cpp

+ 2 - 1
core/fmt/fmt.odin

@@ -1036,7 +1036,8 @@ fmt_bit_set :: proc(fi: ^Info, v: any, name: string = "") {
 					continue loop;
 				}
 			}
-			strings.write_i64(fi.buf, i64(i), 10);
+			v := i64(i) + info.lower;
+			strings.write_i64(fi.buf, v, 10);
 			commas += 1;
 		}
 	}

+ 27 - 0
src/check_expr.cpp

@@ -8391,6 +8391,33 @@ ExprKind check_expr_base_internal(CheckerContext *c, Operand *o, Ast *node, Type
 					bits |= bit;
 				}
 				o->value = exact_value_u64(bits);
+			} else if (is_type_constant_type(type) && cl->elems.count == 0) {
+				ExactValue value = exact_value_compound(node);
+				Type *bt = core_type(type);
+				if (bt->kind == Type_Basic) {
+					if (bt->Basic.flags & BasicFlag_Boolean) {
+						value = exact_value_bool(false);
+					} else if (bt->Basic.flags & BasicFlag_Integer) {
+						value = exact_value_i64(0);
+					} else if (bt->Basic.flags & BasicFlag_Unsigned) {
+						value = exact_value_i64(0);
+					} else if (bt->Basic.flags & BasicFlag_Float) {
+						value = exact_value_float(0);
+					} else if (bt->Basic.flags & BasicFlag_Complex) {
+						value = exact_value_complex(0, 0);
+					} else if (bt->Basic.flags & BasicFlag_Quaternion) {
+						value = exact_value_quaternion(0, 0, 0, 0);
+					} else if (bt->Basic.flags & BasicFlag_Pointer) {
+						value = exact_value_pointer(0);
+					} else if (bt->Basic.flags & BasicFlag_String) {
+						String empty_string = {};
+						value = exact_value_string(empty_string);
+					} else if (bt->Basic.flags & BasicFlag_Rune) {
+						value = exact_value_i64(0);
+					}
+				}
+
+				o->value = value;
 			} else {
 				o->value = exact_value_compound(node);
 			}

+ 32 - 5
src/ir.cpp

@@ -2664,6 +2664,20 @@ irDebugInfo *ir_add_debug_info_type(irModule *module, Type *type, Entity *e, irD
 		return di;
 	}
 
+	if (is_type_enumerated_array(type)) {
+		irDebugInfo *di = ir_alloc_debug_info(irDebugInfo_CompositeType);
+		di->CompositeType.size = ir_debug_size_bits(type);
+		di->CompositeType.align = ir_debug_align_bits(type);
+		di->CompositeType.tag = irDebugBasicEncoding_array_type;
+		di->CompositeType.array_count = (i32)type->EnumeratedArray.count;
+
+		map_set(&module->debug_info, hash_type(type), di);
+		di->CompositeType.base_type = ir_add_debug_info_type(module, type->EnumeratedArray.elem, e, scope, file);
+		GB_ASSERT(base->kind != Type_Named);
+
+		return di;
+	}
+
 	if (is_type_slice(type)) {
 		// NOTE(lachsinc): Every slice type has its own composite type / field debug infos created. This is sorta wasteful.
 		irDebugInfo *di = ir_alloc_debug_info(irDebugInfo_CompositeType);
@@ -3917,7 +3931,7 @@ irValue *ir_addr_get_ptr(irProcedure *proc, irAddr const &addr) {
 }
 
 irValue *ir_build_addr_ptr(irProcedure *proc, Ast *expr) {
-	irAddr const &addr = ir_build_addr(proc, expr);
+	irAddr addr = ir_build_addr(proc, expr);
 	return ir_addr_get_ptr(proc, addr);
 }
 
@@ -4714,6 +4728,10 @@ irValue *ir_emit_struct_ep(irProcedure *proc, irValue *s, i32 index) {
 	Type *t = base_type(type_deref(ir_type(s)));
 	Type *result_type = nullptr;
 
+	if (t->kind == Type_Opaque) {
+		t = t->Opaque.elem;
+	}
+
 	if (is_type_struct(t)) {
 		result_type = alloc_type_pointer(t->Struct.fields[index]->type);
 	} else if (is_type_union(t)) {
@@ -4897,6 +4915,9 @@ irValue *ir_emit_deep_field_gep(irProcedure *proc, irValue *e, Selection sel) {
 			// e = ir_emit_ptr_offset(proc, e, v_zero); // TODO(bill): Do I need these copies?
 		}
 		type = core_type(type);
+		if (type->kind == Type_Opaque) {
+			type = type->Opaque.elem;
+		}
 
 		if (is_type_quaternion(type)) {
 			e = ir_emit_struct_ep(proc, e, index);
@@ -6588,7 +6609,7 @@ irValue *ir_build_builtin_proc(irProcedure *proc, Ast *expr, TypeAndValue tv, Bu
 
 	case BuiltinProc_swizzle: {
 		ir_emit_comment(proc, str_lit("swizzle.begin"));
-		irAddr const &addr = ir_build_addr(proc, ce->args[0]);
+		irAddr addr = ir_build_addr(proc, ce->args[0]);
 		isize index_count = ce->args.count-1;
 		if (index_count == 0) {
 			return ir_addr_load(proc, addr);
@@ -7709,7 +7730,13 @@ bool ir_is_elem_const(irModule *m, Ast *elem, Type *elem_type) {
 
 irAddr ir_build_addr_from_entity(irProcedure *proc, Entity *e, Ast *expr) {
 	GB_ASSERT(e != nullptr);
-	GB_ASSERT(e->kind != Entity_Constant);
+	if (e->kind == Entity_Constant) {
+		Type *t = default_type(type_of_expr(expr));
+		irValue *v = ir_add_module_constant(proc->module, t, e->Constant.value);
+		irValue *g = ir_add_global_generated(proc->module, ir_type(v), v);
+		return ir_addr(g);
+	}
+
 
 	irValue *v = nullptr;
 	irValue **found = map_get(&proc->module->values, hash_entity(e));
@@ -7816,7 +7843,7 @@ irAddr ir_build_addr(irProcedure *proc, Ast *expr) {
 
 
 			if (sel.entity->type->kind == Type_BitFieldValue) {
-				irAddr const &addr = ir_build_addr(proc, se->expr);
+				irAddr addr = ir_build_addr(proc, se->expr);
 				Type *bft = type_deref(ir_addr_type(addr));
 				if (sel.index.count == 1) {
 					GB_ASSERT(is_type_bit_field(bft));
@@ -9900,7 +9927,7 @@ void ir_build_stmt_internal(irProcedure *proc, Ast *node) {
 			case Type_Map: {
 				is_map = true;
 				gbAllocator a = ir_allocator();
-				irAddr const &addr = ir_build_addr(proc, expr);
+				irAddr addr = ir_build_addr(proc, expr);
 				irValue *map = ir_addr_get_ptr(proc, addr);
 				if (is_type_pointer(type_deref(ir_addr_type(addr)))) {
 					map = ir_addr_load(proc, addr);