From 90fb9816b495167c66f40284b66a9d4da22ae769 Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Tue, 31 Oct 2023 22:30:58 +0000 Subject: Added new macro for bitwise comparison construction This pushes a datum of the same type as the operands, which is why it cannot use the comparator macro as that always pushes bytes. --- vm/runtime.c | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) (limited to 'vm') diff --git a/vm/runtime.c b/vm/runtime.c index 402b541..b29fcdc 100644 --- a/vm/runtime.c +++ b/vm/runtime.c @@ -604,6 +604,19 @@ VM_NOT_TYPE(byte, BYTE) VM_NOT_TYPE(hword, HWORD) VM_NOT_TYPE(word, WORD) +#define VM_BITWISE_TYPE(COMPNAME, COMP, TYPEL, TYPEU) \ + err_t vm_##COMPNAME##_##TYPEL(vm_t *vm) \ + { \ + data_t a = {0}, b = {0}; \ + err_t err = vm_pop_##TYPEL(vm, &a); \ + if (err) \ + return err; \ + err = vm_pop_##TYPEL(vm, &b); \ + if (err) \ + return err; \ + return vm_push_##TYPEL(vm, D##TYPEU(a.as_##TYPEL COMP b.as_##TYPEL)); \ + } + #define VM_COMPARATOR_TYPE(COMPNAME, COMP, TYPEL, GETL) \ err_t vm_##COMPNAME##_##GETL(vm_t *vm) \ { \ @@ -617,15 +630,15 @@ VM_NOT_TYPE(word, WORD) return vm_push_byte(vm, DBYTE(a.as_##GETL COMP b.as_##GETL)); \ } -VM_COMPARATOR_TYPE(or, |, byte, byte) -VM_COMPARATOR_TYPE(or, |, hword, hword) -VM_COMPARATOR_TYPE(or, |, word, word) -VM_COMPARATOR_TYPE(and, &, byte, byte) -VM_COMPARATOR_TYPE(and, &, hword, hword) -VM_COMPARATOR_TYPE(and, &, word, word) -VM_COMPARATOR_TYPE(xor, ^, byte, byte) -VM_COMPARATOR_TYPE(xor, ^, hword, hword) -VM_COMPARATOR_TYPE(xor, ^, word, word) +VM_BITWISE_TYPE(or, |, byte, BYTE) +VM_BITWISE_TYPE(or, |, hword, HWORD) +VM_BITWISE_TYPE(or, |, word, WORD) +VM_BITWISE_TYPE(and, &, byte, BYTE) +VM_BITWISE_TYPE(and, &, hword, HWORD) +VM_BITWISE_TYPE(and, &, word, WORD) +VM_BITWISE_TYPE(xor, ^, byte, BYTE) +VM_BITWISE_TYPE(xor, ^, hword, HWORD) +VM_BITWISE_TYPE(xor, ^, word, WORD) VM_COMPARATOR_TYPE(eq, ==, byte, byte) VM_COMPARATOR_TYPE(eq, ==, byte, char) -- cgit v1.2.3-13-gbd6f