X-Git-Url: https://code.kerkeslager.com/?p=fur;a=blobdiff_plain;f=templates%2Farithmetic_instruction.c;fp=templates%2Farithmetic_instruction.c;h=a78a5795e3843795578312b0ef952d7d130b88ca;hp=0000000000000000000000000000000000000000;hb=b7a244b6319f5c770582283097f6184e5a6ec192;hpb=c45c61444aae3df328e4dc84acf7e31e58a1f64e diff --git a/templates/arithmetic_instruction.c b/templates/arithmetic_instruction.c new file mode 100644 index 0000000..a78a579 --- /dev/null +++ b/templates/arithmetic_instruction.c @@ -0,0 +1,14 @@ +void {{ name }}(struct Thread* thread, const union Argument argument) { + // We're going to reuse result as both the addend and the sum + 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(result.type == INTEGER); + + result.value.integer = other.value.integer {{ operation }} result.value.integer; + + Stack_push(&(thread->stack), result); +}