aboutsummaryrefslogtreecommitdiff
path: root/src/program.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/program.c')
-rw-r--r--src/program.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/src/program.c b/src/program.c
index 55bfda4..eef49b6 100644
--- a/src/program.c
+++ b/src/program.c
@@ -125,7 +125,7 @@ static CHECK_RESULT int amal_program_set_exported_function_instruction_offset_ad
num_args = self->exported_funcs[sizeof(instruction_offset)];
func_name_size = self->exported_funcs[sizeof(instruction_offset) + sizeof(num_args)];
self->exported_funcs += sizeof(instruction_offset) + sizeof(num_args) + sizeof(func_name_size);
- if(self->main_func_instruction_offset == ~0U && am_memeql(self->exported_funcs, "main", 4))
+ if(self->main_func_instruction_offset == ~0U && func_name_size == 4 && am_memeql(self->exported_funcs, "main", 4))
self->main_func_instruction_offset = instruction_offset;
/* +1 to skip null-termination character */
@@ -521,16 +521,18 @@ static CHECK_RESULT int amal_program_read_instructions(amal_program *self, amal_
break;
}
case AMAL_OP_JZ: {
- i16 jump_offset;
- am_memcpy(&jump_offset, &self->data.data[self->read_index + sizeof(i8)], sizeof(jump_offset));
- return_if_error(amal_exec_jz(executor, self->data.data[self->read_index], jump_offset));
+ i8 reg;
+ u16 target_label;
+ reg = self->data.data[self->read_index];
+ am_memcpy(&target_label, self->data.data + self->read_index + sizeof(reg), sizeof(target_label));
+ return_if_error(amal_exec_jz(executor, reg, target_label));
self->read_index += 3;
break;
}
case AMAL_OP_JMP: {
- i16 jump_offset;
- am_memcpy(&jump_offset, &self->data.data[self->read_index], sizeof(jump_offset));
- return_if_error(amal_exec_jmp(executor, jump_offset));
+ u16 target_label;
+ am_memcpy(&target_label, self->data.data + self->read_index, sizeof(target_label));
+ return_if_error(amal_exec_jmp(executor, target_label));
self->read_index += 2;
break;
}
@@ -564,6 +566,10 @@ static CHECK_RESULT int amal_program_read_instructions(amal_program *self, amal_
return_if_error(amal_exec_func_end(executor));
break;
}
+ case AMAL_OP_LABEL: {
+ return_if_error(amal_exec_label(executor));
+ break;
+ }
}
}