X-Git-Url: https://code.kerkeslager.com/?p=fur;a=blobdiff_plain;f=templates%2Fprogram2.c;fp=templates%2Fprogram2.c;h=180a4c79efb2e120ecb332f4c2b14627ac5dde15;hp=ffd014ca1ffeede9cef8c49f7abdba8b41c87070;hb=4efcfd00920263da31dc2bb216050df4041299e7;hpb=edc05c8d2d465653c02c350592eff62c542a37ed diff --git a/templates/program2.c b/templates/program2.c index ffd014c..180a4c7 100644 --- a/templates/program2.c +++ b/templates/program2.c @@ -174,6 +174,20 @@ void end(struct Thread* thread, Argument argument) { {% include "arithmetic_instruction.c" %} {% endwith %} +void jump(Thread* thread, Argument argument) { + thread->program_counter = argument.label - 1; // We will increment before running +} + +void jump_if_false(Thread* thread, Argument argument) { + assert(!Stack_isEmpty(&(thread->stack))); + Object result = Stack_pop(&(thread->stack)); + assert(result.type == BOOLEAN); + + if(!(result.value.boolean)) { + jump(thread, argument); + } +} + {% with name='lt', operation='<' %} {% include "comparison_instruction.c" %} {% endwith %} @@ -194,7 +208,7 @@ void end(struct Thread* thread, Argument argument) { {% include "comparison_instruction.c" %} {% endwith %} -void neg(struct Thread* thread, Argument argument) { +void neg(Thread* thread, Argument argument) { assert(!Stack_isEmpty(&(thread->stack))); Object result = Stack_pop(&(thread->stack)); assert(result.type == INTEGER); @@ -286,7 +300,7 @@ const Instruction program[] = { int main() { Thread thread; - Thread_initialize(&thread, 0); + Thread_initialize(&thread, LABEL___main__); for(; program[thread.program_counter].instruction != end; thread.program_counter++) { program[thread.program_counter].instruction(