aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2020-07-28 17:25:58 +0200
committerdec05eba <dec05eba@protonmail.com>2020-07-28 17:25:58 +0200
commite5821148c6b469a48f536b4cd18f06fd5be20e1f (patch)
tree2ea1fe6b3285a4b8450821c070a6c31d67b2a7a7 /src
parent45ba8188d181c4b9316366f89fc955956c26e502 (diff)
Fix build issues in release mode
Diffstat (limited to 'src')
-rw-r--r--src/ast.c7
-rw-r--r--src/compiler.c4
-rw-r--r--src/ir/ir.c24
-rw-r--r--src/std/file.c47
-rw-r--r--src/std/misc.c5
5 files changed, 34 insertions, 53 deletions
diff --git a/src/ast.c b/src/ast.c
index f0bb528..297014d 100644
--- a/src/ast.c
+++ b/src/ast.c
@@ -661,8 +661,8 @@ static void assignmentexpr_resolve(Ast *ast, AstCompilerContext *context) {
if(resolved_var->type == NAMED_OBJECT_FUNC_PARAM || LHS_EXPR_IS_CONST(resolved_var->value.lhs_expr))
is_lhs_const = bool_true;
} else if(self->lhs_expr->type == AST_BINOP) {
- LhsExpr *lhs_expr;
- lhs_expr = binop_get_lhs_expr(self->lhs_expr->value.binop);
+ LhsExpr *lhs_expr = binop_get_lhs_expr(self->lhs_expr->value.binop);
+ check(lhs_expr);
is_lhs_const = LHS_EXPR_IS_CONST(lhs_expr);
}
@@ -764,7 +764,8 @@ static bool resolve_data_type_equals(AstResolvedType *self, AstResolvedType *oth
case RESOLVED_TYPE_FUNC_SIG:
return function_signature_equals(self->value.func_sig, other->value.func_sig);
}
- assert(bool_false);
+ check(bool_false);
+ return bool_false;
}
static bool function_parameter_is_c_vararg(FunctionParameter *self, AstCompilerContext *context) {
diff --git a/src/compiler.c b/src/compiler.c
index f9d9355..eac51ba 100644
--- a/src/compiler.c
+++ b/src/compiler.c
@@ -294,11 +294,11 @@ static CHECK_RESULT int thread_generate_bytecode(Parser *parser) {
}
static int thread_callback_generic(void *userdata) {
- int result;
+ int result = -1;
CompilerGenericThreadUserData *compiler_userdata = userdata;
switch(compiler_userdata->work_type) {
case THREAD_WORK_PARSE: {
- assert(bool_false && "Thread work type can't be 'parse' for generic work");
+ check(bool_false && "Thread work type can't be 'parse' for generic work");
break;
}
case THREAD_WORK_RESOLVE_AST:
diff --git a/src/ir/ir.c b/src/ir/ir.c
index a6ed931..f0c1ee2 100644
--- a/src/ir/ir.c
+++ b/src/ir/ir.c
@@ -559,8 +559,6 @@ static CHECK_RESULT IrRegister lhsexpr_export_generate_ir(LhsExpr *self, IrCompi
#endif
static CHECK_RESULT IrRegister lhsexpr_generate_ir(LhsExpr *self, AstResolveData *resolve_data, IrCompilerContext *context) {
- IrRegister reg;
-
if(LHS_EXPR_IS_EXTERN(self))
return lhsexpr_extern_generate_ir(self, context);
@@ -582,6 +580,7 @@ static CHECK_RESULT IrRegister lhsexpr_generate_ir(LhsExpr *self, AstResolveData
}
return rhs_reg;
} else {
+ IrRegister reg = 0;
/* TODO: Do not assign if we dont want default value */
if(resolve_data->type.type == RESOLVED_TYPE_LHS_EXPR) {
IrNumber number;
@@ -590,16 +589,16 @@ static CHECK_RESULT IrRegister lhsexpr_generate_ir(LhsExpr *self, AstResolveData
else if(resolve_data->type.value.lhs_expr == (LhsExpr*)context->compiler->default_types.f64)
number = create_ir_float(0.0);
else
- assert(bool_false && "TODO: assign default value to reg depending on LhsExpr type");
+ check(bool_false && "TODO: assign default value to reg depending on LhsExpr type");
throw_if_error(ir_get_unique_reg(context->ir, &reg));
throw_if_error(ir_ins_assign_inter(context->ir, reg, number));
} else if(resolve_data->type.type == RESOLVED_TYPE_FUNC_SIG) {
- assert(bool_false && "TODO: Implement this when variable can be null. Then the function pointer should be null");
+ check(bool_false && "TODO: Implement this when variable can be null. Then the function pointer should be null");
} else {
- assert(bool_false);
+ check(bool_false);
}
+ return reg;
}
- return reg;
}
static CHECK_RESULT IrRegister assignmentexpr_generate_ir(AssignmentExpr *self, IrCompilerContext *context) {
@@ -682,6 +681,7 @@ static CHECK_RESULT IrRegister funccall_generate_ir(FunctionCall *self, IrCompil
FunctionParameter *func_param_expr;
int import_index = context->import_index;
+ func_sig = NULL;
func_lhs_expr = NULL;
func_param_expr = NULL;
context->import_index = 0;
@@ -689,7 +689,8 @@ static CHECK_RESULT IrRegister funccall_generate_ir(FunctionCall *self, IrCompil
switch(self->func.resolved_var.type) {
case NAMED_OBJECT_NONE:
- assert(bool_false);
+ check(bool_false);
+ func_sig = NULL;
break;
case NAMED_OBJECT_LHS_EXPR: {
func_lhs_expr = self->func.resolved_var.value.lhs_expr;
@@ -697,22 +698,23 @@ static CHECK_RESULT IrRegister funccall_generate_ir(FunctionCall *self, IrCompil
func_sig = func_lhs_expr->type.value.signature;
} else if(func_lhs_expr->type.type == VARIABLE_TYPE_VARIABLE) {
AstResolveData *resolve_data = func_lhs_expr->type.value.variable->resolved_var.resolve_data;
- assert(resolve_data->type.type == RESOLVED_TYPE_FUNC_SIG);
+ check(resolve_data->type.type == RESOLVED_TYPE_FUNC_SIG);
func_sig = resolve_data->type.value.func_sig;
} else {
- assert(func_lhs_expr->rhs_expr && func_lhs_expr->rhs_expr->resolve_data.type.type == RESOLVED_TYPE_FUNC_SIG);
+ check(func_lhs_expr->rhs_expr && func_lhs_expr->rhs_expr->resolve_data.type.type == RESOLVED_TYPE_FUNC_SIG);
func_sig = func_lhs_expr->rhs_expr->resolve_data.type.value.func_sig;
}
break;
}
case NAMED_OBJECT_FUNC_PARAM: {
func_param_expr = self->func.resolved_var.value.func_param;
- assert(func_param_expr->type.type == VARIABLE_TYPE_SIGNATURE);
+ check(func_param_expr->type.type == VARIABLE_TYPE_SIGNATURE);
func_sig = func_param_expr->type.value.signature;
break;
}
}
+ check(func_sig);
func_decl = func_sig->func_decl;
/* Push return arguments */
@@ -952,7 +954,7 @@ static CHECK_RESULT IrRegister ast_generate_ir_resolve_data(void *ast_data, AstT
resolve_data->ir_reg = 0;/*structdecl_generate_ir(ast_data, context);*/
break;
case AST_STRUCT_FIELD:
- assert(bool_false);
+ check(bool_false);
resolve_data->ir_reg = 0;/*structfield_generate_ir(ast_data, context);*/
break;
case AST_LHS:
diff --git a/src/std/file.c b/src/std/file.c
index d61e871..f0d769e 100644
--- a/src/std/file.c
+++ b/src/std/file.c
@@ -170,49 +170,15 @@ int mapped_file_deinit(MappedFile *self) {
}
#endif
-typedef enum {
- REGULAR,
- DIRECTORY,
- OTHER
-} FileType;
-
-/*
- TODO: Remove this and instead use fstat, and then read the file.
- Otherwise this is not atomic and the file type can change between the calls
-*/
-static CHECK_RESULT int file_get_type(const char *filepath, FileType *type) {
- struct stat file_stats;
- if(stat(filepath, &file_stats) == -1) {
- amal_log_error("file_get_type: %s failed, error: %s", filepath, strerror(errno));
- return -1;
- }
-
- if(file_stats.st_mode & S_IFDIR)
- *type = DIRECTORY;
- else if(file_stats.st_mode & S_IFREG)
- *type = REGULAR;
- else
- *type = OTHER;
- return 0;
-}
-
int read_whole_file(const char *filepath, Buffer *data_result) {
- FileType file_type;
FILE *file;
int result;
usize bytes_read;
- usize size;
-
- return_if_error(file_get_type(filepath, &file_type));
- if(file_type != REGULAR) {
- amal_log_error("Expected file %s to be a regular file", filepath);
- return -2;
- }
+ long size;
file = fopen(filepath, "rb");
if(!file) {
- int error;
- error = errno;
+ int error = errno;
amal_log_error("read_whole_file: %s failed, error: %s", filepath, strerror(error));
return error;
}
@@ -224,6 +190,13 @@ int read_whole_file(const char *filepath, Buffer *data_result) {
}
size = ftell(file);
+ if(size == -1) {
+ int error = errno;
+ result = error;
+ amal_log_error("read_whole_file: %s failed, error: %s", filepath, strerror(error));
+ goto cleanup;
+ }
+
result = fseek(file, 0, SEEK_SET);
if(result != 0) {
result = ferror(file);
@@ -239,7 +212,7 @@ int read_whole_file(const char *filepath, Buffer *data_result) {
assert(data_result->capacity == 0 && data_result->size == 0);
cleanup_if_error(buffer_append_empty(data_result, size));
bytes_read = fread(data_result->data, 1, data_result->size, file);
- if(bytes_read != size)
+ if(bytes_read != (unsigned long)size)
result = ferror(file);
cleanup:
diff --git a/src/std/misc.c b/src/std/misc.c
index f53797d..33ae2be 100644
--- a/src/std/misc.c
+++ b/src/std/misc.c
@@ -1,4 +1,5 @@
#include "../../include/std/misc.h"
+#include <stdlib.h>
#if defined(_MSC_VER)
u16 byteswap16(u16 value) {
@@ -52,3 +53,7 @@ u64 byteswap64(u64 value) {
return result;
}
#endif
+
+void check_abort() {
+ abort();
+}