X-Git-Url: https://code.kerkeslager.com/?p=fur;a=blobdiff_plain;f=templates%2Fcomparison_instruction.c;fp=templates%2Fcomparison_instruction.c;h=dabd90569f9a0e19c7d018fe8bd83da5063fb475;hp=0000000000000000000000000000000000000000;hb=edc05c8d2d465653c02c350592eff62c542a37ed;hpb=d28e140fd317ef3d63286ba6d87eb0418ee536c9 diff --git a/templates/comparison_instruction.c b/templates/comparison_instruction.c new file mode 100644 index 0000000..dabd905 --- /dev/null +++ b/templates/comparison_instruction.c @@ -0,0 +1,15 @@ +void {{ name }}(struct Thread* thread, const union Argument argument) { + // We're going to reuse result as both the first input and the result + assert(!Stack_isEmpty(&(thread->stack))); + Object result = Stack_pop(&(thread->stack)); + assert(result.type == INTEGER); + + assert(!Stack_isEmpty(&(thread->stack))); + Object other = Stack_pop(&(thread->stack)); + assert(other.type == INTEGER); + + result.type = BOOLEAN; + result.value.boolean = other.value.integer {{ operation }} result.value.integer; + + Stack_push(&(thread->stack), result); +}