aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2020-02-23 10:39:57 +0000
committergingerBill <bill@gingerbill.org>2020-02-23 10:39:57 +0000
commite197af766d5ead2a1a67ead4c780848c6749a5b1 (patch)
treea874c73d31366c8fdcccd7546e4294d5df51a6d6 /src
parent2180f4a475287546b9230745343ca3e0847525c6 (diff)
parent10fe5e97b3eea5409660220a903bc6ad09478c1b (diff)
Merge branch 'master' into llvm-integration
Diffstat (limited to 'src')
-rw-r--r--src/check_decl.cpp2
-rw-r--r--src/check_expr.cpp13
-rw-r--r--src/check_stmt.cpp8
-rw-r--r--src/check_type.cpp4
-rw-r--r--src/ir.cpp7
-rw-r--r--src/main.cpp4
6 files changed, 26 insertions, 12 deletions
diff --git a/src/check_decl.cpp b/src/check_decl.cpp
index 0e669e473..ece38e84f 100644
--- a/src/check_decl.cpp
+++ b/src/check_decl.cpp
@@ -1207,7 +1207,7 @@ void check_proc_body(CheckerContext *ctx_, Token token, DeclInfo *decl, Type *ty
}
- bool where_clause_ok = evaluate_where_clauses(ctx, decl->scope, &decl->proc_lit->ProcLit.where_clauses, true);
+ bool where_clause_ok = evaluate_where_clauses(ctx, nullptr, decl->scope, &decl->proc_lit->ProcLit.where_clauses, true);
if (!where_clause_ok) {
// NOTE(bill, 2019-08-31): Don't check the body as the where clauses failed
return;
diff --git a/src/check_expr.cpp b/src/check_expr.cpp
index 6d049747f..cf9e42810 100644
--- a/src/check_expr.cpp
+++ b/src/check_expr.cpp
@@ -2260,6 +2260,8 @@ bool check_cast_internal(CheckerContext *c, Operand *x, Type *type) {
x->mode = Addressing_Value;
} else if (is_type_slice(type) && is_type_string(x->type)) {
x->mode = Addressing_Value;
+ } else if (is_type_union(type)) {
+ x->mode = Addressing_Value;
}
return true;
}
@@ -5942,7 +5944,9 @@ CALL_ARGUMENT_CHECKER(check_call_arguments_internal) {
Entity *e = sig_params[operand_index];
Type *t = e->type;
Operand o = operands[operand_index];
- call->viral_state_flags |= o.expr->viral_state_flags;
+ if (o.expr != nullptr) {
+ call->viral_state_flags |= o.expr->viral_state_flags;
+ }
if (e->kind == Entity_TypeName) {
// GB_ASSERT(!variadic);
@@ -6296,7 +6300,7 @@ Entity **populate_proc_parameter_list(CheckerContext *c, Type *proc_type, isize
}
-bool evaluate_where_clauses(CheckerContext *ctx, Scope *scope, Array<Ast *> *clauses, bool print_err) {
+bool evaluate_where_clauses(CheckerContext *ctx, Ast *call_expr, Scope *scope, Array<Ast *> *clauses, bool print_err) {
if (clauses != nullptr) {
for_array(i, *clauses) {
Ast *clause = (*clauses)[i];
@@ -6304,9 +6308,11 @@ bool evaluate_where_clauses(CheckerContext *ctx, Scope *scope, Array<Ast *> *cla
check_expr(ctx, &o, clause);
if (o.mode != Addressing_Constant) {
if (print_err) error(clause, "'where' clauses expect a constant boolean evaluation");
+ if (print_err && call_expr) error(call_expr, "at caller location");
return false;
} else if (o.value.kind != ExactValue_Bool) {
if (print_err) error(clause, "'where' clauses expect a constant boolean evaluation");
+ if (print_err && call_expr) error(call_expr, "at caller location");
return false;
} else if (!o.value.value_bool) {
if (print_err) {
@@ -6348,6 +6354,7 @@ bool evaluate_where_clauses(CheckerContext *ctx, Scope *scope, Array<Ast *> *cla
}
}
+ if (call_expr) error(call_expr, "at caller location");
}
return false;
}
@@ -6613,7 +6620,7 @@ CallArgumentData check_call_arguments(CheckerContext *c, Operand *operand, Type
ctx.curr_proc_sig = e->type;
GB_ASSERT(decl->proc_lit->kind == Ast_ProcLit);
- if (!evaluate_where_clauses(&ctx, decl->scope, &decl->proc_lit->ProcLit.where_clauses, false)) {
+ if (!evaluate_where_clauses(&ctx, operand->expr, decl->scope, &decl->proc_lit->ProcLit.where_clauses, false)) {
continue;
}
}
diff --git a/src/check_stmt.cpp b/src/check_stmt.cpp
index c365dca84..bef1919e4 100644
--- a/src/check_stmt.cpp
+++ b/src/check_stmt.cpp
@@ -314,7 +314,11 @@ Type *check_assignment_variable(CheckerContext *ctx, Operand *lhs, Operand *rhs)
gbString str = expr_to_string(lhs->expr);
if (e != nullptr && e->flags & EntityFlag_Param) {
- error(lhs->expr, "Cannot assign to '%s' which is a procedure parameter", str);
+ if (e->flags & EntityFlag_Using) {
+ error(lhs->expr, "Cannot assign to '%s' which is from a 'using' procedure parameter", str);
+ } else {
+ error(lhs->expr, "Cannot assign to '%s' which is a procedure parameter", str);
+ }
} else {
error(lhs->expr, "Cannot assign to '%s'", str);
}
@@ -497,6 +501,8 @@ bool check_using_stmt_entity(CheckerContext *ctx, AstUsingStmt *us, Ast *expr, b
Entity *f = found->elements.entries[i].value;
if (f->kind == Entity_Variable) {
Entity *uvar = alloc_entity_using_variable(e, f->token, f->type, expr);
+ if (e->flags & EntityFlag_Value) uvar->flags |= EntityFlag_Value;
+ if (e->flags & EntityFlag_Param) uvar->flags |= EntityFlag_Param;
Entity *prev = scope_insert(ctx->scope, uvar);
if (prev != nullptr) {
gbString expr_str = expr_to_string(expr);
diff --git a/src/check_type.cpp b/src/check_type.cpp
index f21ffc956..97b9985c8 100644
--- a/src/check_type.cpp
+++ b/src/check_type.cpp
@@ -527,7 +527,7 @@ void check_struct_type(CheckerContext *ctx, Type *struct_type, Ast *node, Array<
if (st->where_clauses.count > 0 && st->polymorphic_params == nullptr) {
error(st->where_clauses[0], "'where' clauses can only be used on structures with polymorphic parameters");
} else {
- bool where_clause_ok = evaluate_where_clauses(ctx, ctx->scope, &st->where_clauses, true);
+ bool where_clause_ok = evaluate_where_clauses(ctx, node, ctx->scope, &st->where_clauses, true);
}
check_struct_fields(ctx, node, &struct_type->Struct.fields, &struct_type->Struct.tags, st->fields, min_field_count, struct_type, context);
}
@@ -714,7 +714,7 @@ void check_union_type(CheckerContext *ctx, Type *union_type, Ast *node, Array<Op
if (ut->where_clauses.count > 0 && ut->polymorphic_params == nullptr) {
error(ut->where_clauses[0], "'where' clauses can only be used on unions with polymorphic parameters");
} else {
- bool where_clause_ok = evaluate_where_clauses(ctx, ctx->scope, &ut->where_clauses, true);
+ bool where_clause_ok = evaluate_where_clauses(ctx, node, ctx->scope, &ut->where_clauses, true);
}
diff --git a/src/ir.cpp b/src/ir.cpp
index 8171d774d..982576a2b 100644
--- a/src/ir.cpp
+++ b/src/ir.cpp
@@ -5714,7 +5714,7 @@ irValue *ir_emit_transmute(irProcedure *proc, irValue *value, Type *t) {
}
// TODO(bill): Actually figure out what the conversion needs to be correctly 'cause LLVM
- return ir_emit_bitcast(proc, value, dst);
+ return ir_emit_bitcast(proc, value, t);
}
@@ -7348,10 +7348,11 @@ irValue *ir_build_expr_internal(irProcedure *proc, Ast *expr) {
GB_ASSERT(are_types_identical(ir_type(left), key_type));
Type *it = bit_set_to_int(rt);
+ left = ir_emit_conv(proc, left, it);
irValue *lower = ir_value_constant(it, exact_value_i64(rt->BitSet.lower));
- irValue *key = ir_emit_arith(proc, Token_Sub, left, lower, ir_type(left));
- irValue *bit = ir_emit_arith(proc, Token_Shl, v_one, key, ir_type(left));
+ irValue *key = ir_emit_arith(proc, Token_Sub, left, lower, it);
+ irValue *bit = ir_emit_arith(proc, Token_Shl, v_one, key, it);
bit = ir_emit_conv(proc, bit, it);
irValue *old_value = ir_emit_bitcast(proc, right, it);
diff --git a/src/main.cpp b/src/main.cpp
index 119e6fc62..e814f7e0d 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1529,11 +1529,11 @@ int main(int arg_count, char const **arg_ptr) {
// Shared libraries are .dylib on MacOS and .so on Linux.
#if defined(GB_SYSTEM_OSX)
output_ext = STR_LIT(".dylib");
+ link_settings = "-dylib -dynamic";
#else
output_ext = STR_LIT(".so");
+ link_settings = "-shared";
#endif
-
- link_settings = "-shared";
} else {
// TODO: Do I need anything here?
link_settings = "";