aboutsummaryrefslogtreecommitdiff
path: root/vm/runtime.c
diff options
context:
space:
mode:
authorAryadev Chavali <aryadev@aryadevchavali.com>2023-10-31 21:24:54 +0000
committerAryadev Chavali <aryadev@aryadevchavali.com>2023-10-31 21:24:54 +0000
commitf7f566b106a29b91f2a1651aad2d91b49bdd8e45 (patch)
tree3cb2764304115b7481cb7ae35fe7c23bac65d0b1 /vm/runtime.c
parent7817b5acc9ff82038e10fb8dee987195bfa8e6e0 (diff)
downloadovm-f7f566b106a29b91f2a1651aad2d91b49bdd8e45.tar.gz
ovm-f7f566b106a29b91f2a1651aad2d91b49bdd8e45.tar.bz2
ovm-f7f566b106a29b91f2a1651aad2d91b49bdd8e45.zip
Implemented all the comparators
So much reused code, I definitely need to find a way to make this cleaner.
Diffstat (limited to 'vm/runtime.c')
-rw-r--r--vm/runtime.c276
1 files changed, 228 insertions, 48 deletions
diff --git a/vm/runtime.c b/vm/runtime.c
index 536ac6d..6f9495a 100644
--- a/vm/runtime.c
+++ b/vm/runtime.c
@@ -764,146 +764,326 @@ err_t vm_eq_word(vm_t *vm)
err_t vm_lt_byte(vm_t *vm)
{
- (void)vm;
- return ERR_END_OF_PROGRAM;
+ data_t a = {0}, b = {0};
+ err_t err = vm_pop_byte(vm, &a);
+ if (err)
+ return err;
+ err = vm_pop_byte(vm, &b);
+ if (err)
+ return err;
+ return vm_push_byte(vm, DBYTE(a.as_byte < b.as_byte));
}
err_t vm_lt_char(vm_t *vm)
{
- (void)vm;
- return ERR_END_OF_PROGRAM;
+ data_t a = {0}, b = {0};
+ err_t err = vm_pop_byte(vm, &a);
+ if (err)
+ return err;
+ err = vm_pop_byte(vm, &b);
+ if (err)
+ return err;
+ char a_, b_;
+ memcpy(&a_, &a.as_byte, 1);
+ memcpy(&b_, &b.as_byte, 1);
+ return vm_push_byte(vm, DBYTE(a_ < b_));
}
err_t vm_lt_int(vm_t *vm)
{
- (void)vm;
- return ERR_END_OF_PROGRAM;
+ data_t a = {0}, b = {0};
+ err_t err = vm_pop_hword(vm, &a);
+ if (err)
+ return err;
+ err = vm_pop_hword(vm, &b);
+ if (err)
+ return err;
+ s_hword a_, b_;
+ memcpy(&a_, &a.as_hword, HWORD_SIZE);
+ memcpy(&b_, &b.as_hword, HWORD_SIZE);
+ return vm_push_byte(vm, DBYTE(a_ < b_));
}
err_t vm_lt_hword(vm_t *vm)
{
- (void)vm;
- return ERR_END_OF_PROGRAM;
+ data_t a = {0}, b = {0};
+ err_t err = vm_pop_hword(vm, &a);
+ if (err)
+ return err;
+ err = vm_pop_hword(vm, &b);
+ if (err)
+ return err;
+ return vm_push_byte(vm, DBYTE(a.as_byte < b.as_byte));
}
err_t vm_lt_long(vm_t *vm)
{
- (void)vm;
- return ERR_END_OF_PROGRAM;
+ data_t a = {0}, b = {0};
+ err_t err = vm_pop_word(vm, &a);
+ if (err)
+ return err;
+ err = vm_pop_word(vm, &b);
+ if (err)
+ return err;
+ s_word a_, b_;
+ memcpy(&a_, &a.as_word, WORD_SIZE);
+ memcpy(&b_, &b.as_word, WORD_SIZE);
+ return vm_push_byte(vm, DBYTE(a_ < b_));
}
err_t vm_lt_word(vm_t *vm)
{
- (void)vm;
- return ERR_END_OF_PROGRAM;
+ data_t a = {0}, b = {0};
+ err_t err = vm_pop_word(vm, &a);
+ if (err)
+ return err;
+ err = vm_pop_word(vm, &b);
+ if (err)
+ return err;
+ return vm_push_byte(vm, DBYTE(a.as_word < b.as_word));
}
err_t vm_lte_byte(vm_t *vm)
{
- (void)vm;
- return ERR_END_OF_PROGRAM;
+ data_t a = {0}, b = {0};
+ err_t err = vm_pop_byte(vm, &a);
+ if (err)
+ return err;
+ err = vm_pop_byte(vm, &b);
+ if (err)
+ return err;
+ return vm_push_byte(vm, DBYTE(a.as_byte <= b.as_byte));
}
err_t vm_lte_char(vm_t *vm)
{
- (void)vm;
- return ERR_END_OF_PROGRAM;
+ data_t a = {0}, b = {0};
+ err_t err = vm_pop_byte(vm, &a);
+ if (err)
+ return err;
+ err = vm_pop_byte(vm, &b);
+ if (err)
+ return err;
+ char a_, b_;
+ memcpy(&a_, &a.as_byte, 1);
+ memcpy(&b_, &b.as_byte, 1);
+ return vm_push_byte(vm, DBYTE(a_ <= b_));
}
err_t vm_lte_int(vm_t *vm)
{
- (void)vm;
- return ERR_END_OF_PROGRAM;
+ data_t a = {0}, b = {0};
+ err_t err = vm_pop_hword(vm, &a);
+ if (err)
+ return err;
+ err = vm_pop_hword(vm, &b);
+ if (err)
+ return err;
+ s_hword a_, b_;
+ memcpy(&a_, &a.as_hword, HWORD_SIZE);
+ memcpy(&b_, &b.as_hword, HWORD_SIZE);
+ return vm_push_byte(vm, DBYTE(a_ <= b_));
}
err_t vm_lte_hword(vm_t *vm)
{
- (void)vm;
- return ERR_END_OF_PROGRAM;
+ data_t a = {0}, b = {0};
+ err_t err = vm_pop_hword(vm, &a);
+ if (err)
+ return err;
+ err = vm_pop_hword(vm, &b);
+ if (err)
+ return err;
+ return vm_push_byte(vm, DBYTE(a.as_byte <= b.as_byte));
}
err_t vm_lte_long(vm_t *vm)
{
- (void)vm;
- return ERR_END_OF_PROGRAM;
+ data_t a = {0}, b = {0};
+ err_t err = vm_pop_word(vm, &a);
+ if (err)
+ return err;
+ err = vm_pop_word(vm, &b);
+ if (err)
+ return err;
+ s_word a_, b_;
+ memcpy(&a_, &a.as_word, WORD_SIZE);
+ memcpy(&b_, &b.as_word, WORD_SIZE);
+ return vm_push_byte(vm, DBYTE(a_ <= b_));
}
err_t vm_lte_word(vm_t *vm)
{
- (void)vm;
- return ERR_END_OF_PROGRAM;
+ data_t a = {0}, b = {0};
+ err_t err = vm_pop_word(vm, &a);
+ if (err)
+ return err;
+ err = vm_pop_word(vm, &b);
+ if (err)
+ return err;
+ return vm_push_byte(vm, DBYTE(a.as_word <= b.as_word));
}
err_t vm_gt_byte(vm_t *vm)
{
- (void)vm;
- return ERR_END_OF_PROGRAM;
+ data_t a = {0}, b = {0};
+ err_t err = vm_pop_byte(vm, &a);
+ if (err)
+ return err;
+ err = vm_pop_byte(vm, &b);
+ if (err)
+ return err;
+ return vm_push_byte(vm, DBYTE(a.as_byte > b.as_byte));
}
err_t vm_gt_char(vm_t *vm)
{
- (void)vm;
- return ERR_END_OF_PROGRAM;
+ data_t a = {0}, b = {0};
+ err_t err = vm_pop_byte(vm, &a);
+ if (err)
+ return err;
+ err = vm_pop_byte(vm, &b);
+ if (err)
+ return err;
+ char a_, b_;
+ memcpy(&a_, &a.as_byte, 1);
+ memcpy(&b_, &b.as_byte, 1);
+ return vm_push_byte(vm, DBYTE(a_ > b_));
}
err_t vm_gt_int(vm_t *vm)
{
- (void)vm;
- return ERR_END_OF_PROGRAM;
+ data_t a = {0}, b = {0};
+ err_t err = vm_pop_hword(vm, &a);
+ if (err)
+ return err;
+ err = vm_pop_hword(vm, &b);
+ if (err)
+ return err;
+ s_hword a_, b_;
+ memcpy(&a_, &a.as_hword, HWORD_SIZE);
+ memcpy(&b_, &b.as_hword, HWORD_SIZE);
+ return vm_push_byte(vm, DBYTE(a_ > b_));
}
err_t vm_gt_hword(vm_t *vm)
{
- (void)vm;
- return ERR_END_OF_PROGRAM;
+ data_t a = {0}, b = {0};
+ err_t err = vm_pop_hword(vm, &a);
+ if (err)
+ return err;
+ err = vm_pop_hword(vm, &b);
+ if (err)
+ return err;
+ return vm_push_byte(vm, DBYTE(a.as_byte > b.as_byte));
}
err_t vm_gt_long(vm_t *vm)
{
- (void)vm;
- return ERR_END_OF_PROGRAM;
+ data_t a = {0}, b = {0};
+ err_t err = vm_pop_word(vm, &a);
+ if (err)
+ return err;
+ err = vm_pop_word(vm, &b);
+ if (err)
+ return err;
+ s_word a_, b_;
+ memcpy(&a_, &a.as_word, WORD_SIZE);
+ memcpy(&b_, &b.as_word, WORD_SIZE);
+ return vm_push_byte(vm, DBYTE(a_ > b_));
}
err_t vm_gt_word(vm_t *vm)
{
- (void)vm;
- return ERR_END_OF_PROGRAM;
+ data_t a = {0}, b = {0};
+ err_t err = vm_pop_word(vm, &a);
+ if (err)
+ return err;
+ err = vm_pop_word(vm, &b);
+ if (err)
+ return err;
+ return vm_push_byte(vm, DBYTE(a.as_word > b.as_word));
}
err_t vm_gte_byte(vm_t *vm)
{
- (void)vm;
- return ERR_END_OF_PROGRAM;
+ data_t a = {0}, b = {0};
+ err_t err = vm_pop_byte(vm, &a);
+ if (err)
+ return err;
+ err = vm_pop_byte(vm, &b);
+ if (err)
+ return err;
+ return vm_push_byte(vm, DBYTE(a.as_byte >= b.as_byte));
}
err_t vm_gte_char(vm_t *vm)
{
- (void)vm;
- return ERR_END_OF_PROGRAM;
+ data_t a = {0}, b = {0};
+ err_t err = vm_pop_byte(vm, &a);
+ if (err)
+ return err;
+ err = vm_pop_byte(vm, &b);
+ if (err)
+ return err;
+ char a_, b_;
+ memcpy(&a_, &a.as_byte, 1);
+ memcpy(&b_, &b.as_byte, 1);
+ return vm_push_byte(vm, DBYTE(a_ >= b_));
}
err_t vm_gte_int(vm_t *vm)
{
- (void)vm;
- return ERR_END_OF_PROGRAM;
+ data_t a = {0}, b = {0};
+ err_t err = vm_pop_hword(vm, &a);
+ if (err)
+ return err;
+ err = vm_pop_hword(vm, &b);
+ if (err)
+ return err;
+ s_hword a_, b_;
+ memcpy(&a_, &a.as_hword, HWORD_SIZE);
+ memcpy(&b_, &b.as_hword, HWORD_SIZE);
+ return vm_push_byte(vm, DBYTE(a_ >= b_));
}
err_t vm_gte_hword(vm_t *vm)
{
- (void)vm;
- return ERR_END_OF_PROGRAM;
+ data_t a = {0}, b = {0};
+ err_t err = vm_pop_hword(vm, &a);
+ if (err)
+ return err;
+ err = vm_pop_hword(vm, &b);
+ if (err)
+ return err;
+ return vm_push_byte(vm, DBYTE(a.as_byte >= b.as_byte));
}
err_t vm_gte_long(vm_t *vm)
{
- (void)vm;
- return ERR_END_OF_PROGRAM;
+ data_t a = {0}, b = {0};
+ err_t err = vm_pop_word(vm, &a);
+ if (err)
+ return err;
+ err = vm_pop_word(vm, &b);
+ if (err)
+ return err;
+ s_word a_, b_;
+ memcpy(&a_, &a.as_word, WORD_SIZE);
+ memcpy(&b_, &b.as_word, WORD_SIZE);
+ return vm_push_byte(vm, DBYTE(a_ >= b_));
}
err_t vm_gte_word(vm_t *vm)
{
- (void)vm;
- return ERR_END_OF_PROGRAM;
+ data_t a = {0}, b = {0};
+ err_t err = vm_pop_word(vm, &a);
+ if (err)
+ return err;
+ err = vm_pop_word(vm, &b);
+ if (err)
+ return err;
+ return vm_push_byte(vm, DBYTE(a.as_word >= b.as_word));
}
err_t vm_plus_byte(vm_t *vm)