aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAryadev Chavali <aryadev@aryadevchavali.com>2023-10-21 23:55:51 +0100
committerAryadev Chavali <aryadev@aryadevchavali.com>2023-10-21 23:55:51 +0100
commit95723f36d2aa7e1bcd343b2e072c0bcf28a3b1b5 (patch)
tree94aee91ce70a4f648f7813d4c1fd5393faba6e66 /src
parent50ce1b35cd1ce5e93f90c43b0657dced380d89fa (diff)
downloadovm-95723f36d2aa7e1bcd343b2e072c0bcf28a3b1b5.tar.gz
ovm-95723f36d2aa7e1bcd343b2e072c0bcf28a3b1b5.tar.bz2
ovm-95723f36d2aa7e1bcd343b2e072c0bcf28a3b1b5.zip
Implemented vm routines for OP_EQ_*
Diffstat (limited to 'src')
-rw-r--r--src/runtime.c29
-rw-r--r--src/runtime.h10
2 files changed, 39 insertions, 0 deletions
diff --git a/src/runtime.c b/src/runtime.c
index 19115b6..b330a61 100644
--- a/src/runtime.c
+++ b/src/runtime.c
@@ -456,3 +456,32 @@ void vm_xor_word(vm_t *vm)
vm_push_word(vm, DWORD(a ^ b));
}
+void vm_eq_byte(vm_t *vm)
+{
+ if (vm->stack.ptr < 2)
+ // TODO: Error STACK_UNDERFLOW
+ return;
+ byte a = vm_pop_byte(vm).as_byte;
+ byte b = vm_pop_byte(vm).as_byte;
+ vm_push_byte(vm, DBYTE(a == b));
+}
+
+void vm_eq_hword(vm_t *vm)
+{
+ if (vm->stack.ptr < (HWORD_SIZE * 2))
+ // TODO: Error STACK_UNDERFLOW
+ return;
+ hword a = vm_pop_hword(vm).as_hword;
+ hword b = vm_pop_hword(vm).as_hword;
+ vm_push_hword(vm, DHWORD(a == b));
+}
+
+void vm_eq_word(vm_t *vm)
+{
+ if (vm->stack.ptr < (WORD_SIZE * 2))
+ // TODO: Error STACK_UNDERFLOW
+ return;
+ word a = vm_pop_word(vm).as_word;
+ word b = vm_pop_word(vm).as_word;
+ vm_push_word(vm, DWORD(a == b));
+}
diff --git a/src/runtime.h b/src/runtime.h
index ea4edb9..2ec01df 100644
--- a/src/runtime.h
+++ b/src/runtime.h
@@ -141,4 +141,14 @@ static const xor_f XOR_ROUTINES[] = {
[OP_XOR_WORD] = vm_xor_word,
};
+void vm_eq_byte(vm_t *);
+void vm_eq_hword(vm_t *);
+void vm_eq_word(vm_t *);
+typedef void (*eq_f)(vm_t *);
+static const eq_f EQ_ROUTINES[] = {
+ [OP_EQ_BYTE] = vm_eq_byte,
+ [OP_EQ_HWORD] = vm_eq_hword,
+ [OP_EQ_WORD] = vm_eq_word,
+};
+
#endif