Browse Source

Fix LLVM API backend for procedure "constant" values

gingerBill 5 years ago
parent
commit
4438b3e7af
3 changed files with 25 additions and 26 deletions
  1. 1 1
      core/runtime/default_allocators.odin
  2. 1 1
      src/check_expr.cpp
  3. 23 24
      src/llvm_backend.cpp

+ 1 - 1
core/runtime/default_allocators.odin

@@ -50,7 +50,7 @@ default_temp_allocator_proc :: proc(allocator_data: rawptr, mode: Allocator_Mode
 		     context.allocator.data != allocator_data) {
 		     context.allocator.data != allocator_data) {
 			a = default_allocator();
 			a = default_allocator();
 		}
 		}
-		default_temp_allocator_init(allocator, make([]byte, 1<<22, a), a);
+		default_temp_allocator_init(allocator, make([]byte, DEFAULT_SCRATCH_BACKING_SIZE, a), a);
 	}
 	}
 
 
 	switch mode {
 	switch mode {

+ 1 - 1
src/check_expr.cpp

@@ -8038,7 +8038,7 @@ ExprKind check_expr_base_internal(CheckerContext *c, Operand *o, Ast *node, Type
 					fields_visited[sel.index[0]] = true;
 					fields_visited[sel.index[0]] = true;
 					check_expr_or_type(c, o, fv->value, field->type);
 					check_expr_or_type(c, o, fv->value, field->type);
 
 
-					if (is_type_any(field->type) || is_type_union(field->type) || is_type_raw_union(field->type)) {
+					if (is_type_any(field->type) || is_type_union(field->type) || is_type_raw_union(field->type) || is_type_typeid(field->type)) {
 						is_constant = false;
 						is_constant = false;
 					}
 					}
 					if (is_constant) {
 					if (is_constant) {

+ 23 - 24
src/llvm_backend.cpp

@@ -4330,6 +4330,22 @@ lbValue lb_const_value(lbModule *m, Type *type, ExactValue value) {
 		return lb_const_nil(m, type);
 		return lb_const_nil(m, type);
 	}
 	}
 
 
+	if (value.kind == ExactValue_Procedure) {
+		Ast *expr = value.value_procedure;
+		if (expr->kind == Ast_ProcLit) {
+			return lb_generate_anonymous_proc_lit(m, str_lit("_proclit"), expr);
+		}
+		Entity *e = entity_from_expr(expr);
+		e = strip_entity_wrapping(e);
+		GB_ASSERT(e != nullptr);
+		auto *found = map_get(&m->values, hash_entity(e));
+		if (found) {
+			return *found;
+		}
+
+		GB_PANIC("Error in: %.*s(%td:%td), missing procedure %.*s\n", LIT(e->token.pos.file), e->token.pos.line, e->token.pos.column, LIT(e->token.string));
+	}
+
 	// GB_ASSERT_MSG(is_type_typed(type), "%s", type_to_string(type));
 	// GB_ASSERT_MSG(is_type_typed(type), "%s", type_to_string(type));
 
 
 	if (is_type_slice(type)) {
 	if (is_type_slice(type)) {
@@ -7951,6 +7967,13 @@ lbValue lb_emit_comp_against_nil(lbProcedure *p, TokenKind op_kind, lbValue x) {
 			res.value = LLVMBuildIsNotNull(p->builder, ptr.value, "");
 			res.value = LLVMBuildIsNotNull(p->builder, ptr.value, "");
 		}
 		}
 		return res;
 		return res;
+	} else if (is_type_proc(t)) {
+		if (op_kind == Token_CmpEq) {
+			res.value = LLVMBuildIsNull(p->builder, x.value, "");
+		} else if (op_kind == Token_NotEq) {
+			res.value = LLVMBuildIsNotNull(p->builder, x.value, "");
+		}
+		return res;
 	} else if (is_type_any(t)) {
 	} else if (is_type_any(t)) {
 		// TODO(bill): is this correct behaviour for nil comparison for any?
 		// TODO(bill): is this correct behaviour for nil comparison for any?
 		lbValue data = lb_emit_struct_ev(p, x, 0);
 		lbValue data = lb_emit_struct_ev(p, x, 0);
@@ -8567,30 +8590,6 @@ lbValue lb_build_expr(lbProcedure *p, Ast *expr) {
 	GB_ASSERT(tv.mode != Addressing_Type);
 	GB_ASSERT(tv.mode != Addressing_Type);
 
 
 	if (tv.value.kind != ExactValue_Invalid) {
 	if (tv.value.kind != ExactValue_Invalid) {
-		if (tv.value.kind == ExactValue_Procedure) {
-			Ast *expr = tv.value.value_procedure;
-			if (expr->kind == Ast_ProcLit) {
-				return lb_generate_anonymous_proc_lit(m, str_lit("_proclit"), expr);
-			}
-			Entity *e = entity_from_expr(expr);
-			e = strip_entity_wrapping(e);
-			GB_ASSERT(e != nullptr);
-			auto *found = map_get(&p->module->values, hash_entity(e));
-			if (found) {
-				auto v = *found;
-				// NOTE(bill): This is because pointers are already pointers in LLVM
-				if (is_type_proc(v.type)) {
-					return v;
-				}
-				return lb_emit_load(p, v);
-			} else if (e != nullptr && e->kind == Entity_Variable) {
-				return lb_addr_load(p, lb_build_addr(p, expr));
-			}
-
-			GB_PANIC("Error in: %.*s(%td:%td) %s\n", LIT(p->name), e->token.pos.line, e->token.pos.column);
-			// GB_PANIC("nullptr value for expression from identifier: %.*s.%.*s (%p) : %s @ %p", LIT(e->pkg->name), LIT(e->token.string), e, type_to_string(e->type), expr);
-		}
-
 		// NOTE(bill): Short on constant values
 		// NOTE(bill): Short on constant values
 		return lb_const_value(p->module, tv.type, tv.value);
 		return lb_const_value(p->module, tv.type, tv.value);
 	}
 	}