Implement MSG instruction

This commit is contained in:
Nunuhara Cabbage
2019-11-19 20:34:31 -08:00
parent 7ec7124d01
commit 80ff1902e6
3 changed files with 22 additions and 1 deletions
+1 -1
View File
@@ -135,7 +135,7 @@ const struct instruction instructions[NR_OPCODES] = {
OP(A_FILL, 0),
OP(C_REF, 0),
OP(C_ASSIGN, 0),
OP(MSG, 0), // TODO
JMP(MSG, 1, INSTR_INT),
OP(CALLHLL, 2, INSTR_INT, INSTR_INT),
OP(PUSHSTRUCTPAGE, 0),
JMP(CALLMETHOD, 1, INSTR_FUN),
+13
View File
@@ -120,4 +120,17 @@ void test_lang(void)
test_equal("string switch (no default)", test_string_switch("d"), 100);
test_equal("string switch (default)", test_string_switch_default("d"), 100);
test_equal("local ref escape", (set_page_ref(42), gi), 42);
'message1';
'message2';
}
int msg_count = 0;
void message(int msg_nr, int nr_messages, string msg)
{
if (msg_count == 0)
test_string("message1", msg, "message1");
else if (msg_count == 1)
test_string("message2", msg, "message2");
msg_count++;
}
+8
View File
@@ -626,6 +626,14 @@ static void execute_instruction(int16_t opcode)
case SJUMP:
scenario_call(stack_pop().i);
break;
case MSG:
if (ain->msgf < 0)
break;
stack_push(get_argument(0));
stack_push(ain->nr_messages);
stack_push_string(string_ref(ain->messages[get_argument(0)]));
function_call(ain->msgf, instr_ptr + instruction_width(MSG));
break;
case JUMP: // ADDR
instr_ptr = get_argument(0);
break;