🐛 🐛 void function and compiler segfault.

main
bog 2024-02-17 22:06:20 +01:00
parent 76e0cdbeef
commit 6420e283a1
2 changed files with 10 additions and 3 deletions

View File

@ -76,6 +76,7 @@ int compiler_compile(struct compiler* self,
struct node* ident = idents.data[j]; struct node* ident = idents.data[j];
struct type* ty = malloc(sizeof(struct type)); struct type* ty = malloc(sizeof(struct type));
type_init(ty, TYPE_VOID);
compiler_get_type(self, param, ty); compiler_get_type(self, param, ty);
sym_table_declare_const(&compiler.sym_table, sym_table_declare_const(&compiler.sym_table,

View File

@ -208,13 +208,19 @@ int vm_exec(struct vm* self, struct program* program)
vec_free(&args); vec_free(&args);
struct value* ret_val = struct value* ret_val =
fun->program.constant_pool.data[my_frame->stack[my_frame->sp - 1]]; (my_frame->sp > 0)
? fun->program.constant_pool.data
[my_frame->stack[my_frame->sp - 1]]
: NULL;
struct value* new_ret = value_new_clone(ret_val); struct value* new_ret = ret_val ? value_new_clone(ret_val) : NULL;
vm_remove_frame(self); vm_remove_frame(self);
if (new_ret)
{
vm_push(self, program_push_constant(program, new_ret)); vm_push(self, program_push_constant(program, new_ret));
}
self->pc = ret_addr + 1; self->pc = ret_addr + 1;