aboutsummaryrefslogtreecommitdiff
path: root/vm
diff options
context:
space:
mode:
authorAryadev Chavali <aryadev@aryadevchavali.com>2023-10-31 20:59:01 +0000
committerAryadev Chavali <aryadev@aryadevchavali.com>2023-10-31 20:59:01 +0000
commit4d8b855d87194b4a011211c7633af35704572a13 (patch)
treeb20987d96e3c77a99fa32ee67d08fc97a4f63d80 /vm
parent0975d924938a3500380b22395b3262053f720ee2 (diff)
downloadovm-4d8b855d87194b4a011211c7633af35704572a13.tar.gz
ovm-4d8b855d87194b4a011211c7633af35704572a13.tar.bz2
ovm-4d8b855d87194b4a011211c7633af35704572a13.zip
Created routines for new comparator opcodes (not implemented)
Will cause error if used currently, which is fine.
Diffstat (limited to 'vm')
-rw-r--r--vm/runtime.c173
-rw-r--r--vm/runtime.h52
2 files changed, 219 insertions, 6 deletions
diff --git a/vm/runtime.c b/vm/runtime.c
index ccda9d0..6fd6ab4 100644
--- a/vm/runtime.c
+++ b/vm/runtime.c
@@ -55,7 +55,7 @@ const char *err_as_cstr(err_t err)
err_t vm_execute(vm_t *vm)
{
- static_assert(NUMBER_OF_OPCODES == 46, "vm_execute: Out of date");
+ static_assert(NUMBER_OF_OPCODES == 73, "vm_execute: Out of date");
struct Program *prog = &vm->program;
if (prog->ptr >= prog->max)
return ERR_END_OF_PROGRAM;
@@ -103,6 +103,10 @@ err_t vm_execute(vm_t *vm)
OPCODE_IS_TYPE(instruction.opcode, OP_AND) ||
OPCODE_IS_TYPE(instruction.opcode, OP_XOR) ||
OPCODE_IS_TYPE(instruction.opcode, OP_EQ) ||
+ OPCODE_IS_TYPE(instruction.opcode, OP_LT) ||
+ OPCODE_IS_TYPE(instruction.opcode, OP_LTE) ||
+ OPCODE_IS_TYPE(instruction.opcode, OP_GT) ||
+ OPCODE_IS_TYPE(instruction.opcode, OP_GTE) ||
OPCODE_IS_TYPE(instruction.opcode, OP_PLUS))
{
prog->ptr++;
@@ -146,14 +150,13 @@ err_t vm_execute(vm_t *vm)
else
++prog->ptr;
}
- else if (instruction.opcode >= OP_PRINT_CHAR &&
- instruction.opcode <= OP_PRINT_WORD)
+ else if (OPCODE_IS_TYPE(instruction.opcode, OP_PRINT))
{
data_t datum = {0};
enum
{
- TYPE_CHAR,
TYPE_BYTE,
+ TYPE_CHAR,
TYPE_INT,
TYPE_HWORD,
TYPE_LONG,
@@ -716,6 +719,12 @@ err_t vm_eq_byte(vm_t *vm)
return vm_push_byte(vm, DBYTE(a.as_byte == b.as_byte));
}
+err_t vm_eq_char(vm_t *vm)
+{
+ (void)vm;
+ return ERR_END_OF_PROGRAM;
+}
+
err_t vm_eq_hword(vm_t *vm)
{
data_t a = {0}, b = {0};
@@ -728,6 +737,18 @@ err_t vm_eq_hword(vm_t *vm)
return vm_push_hword(vm, DHWORD(a.as_hword == b.as_hword));
}
+err_t vm_eq_int(vm_t *vm)
+{
+ (void)vm;
+ return ERR_END_OF_PROGRAM;
+}
+
+err_t vm_eq_long(vm_t *vm)
+{
+ (void)vm;
+ return ERR_END_OF_PROGRAM;
+}
+
err_t vm_eq_word(vm_t *vm)
{
data_t a = {0}, b = {0};
@@ -740,6 +761,150 @@ err_t vm_eq_word(vm_t *vm)
return vm_push_word(vm, DWORD(a.as_word == b.as_word));
}
+err_t vm_lt_byte(vm_t *vm)
+{
+ (void)vm;
+ return ERR_END_OF_PROGRAM;
+}
+
+err_t vm_lt_char(vm_t *vm)
+{
+ (void)vm;
+ return ERR_END_OF_PROGRAM;
+}
+
+err_t vm_lt_int(vm_t *vm)
+{
+ (void)vm;
+ return ERR_END_OF_PROGRAM;
+}
+
+err_t vm_lt_hword(vm_t *vm)
+{
+ (void)vm;
+ return ERR_END_OF_PROGRAM;
+}
+
+err_t vm_lt_long(vm_t *vm)
+{
+ (void)vm;
+ return ERR_END_OF_PROGRAM;
+}
+
+err_t vm_lt_word(vm_t *vm)
+{
+ (void)vm;
+ return ERR_END_OF_PROGRAM;
+}
+
+err_t vm_lte_byte(vm_t *vm)
+{
+ (void)vm;
+ return ERR_END_OF_PROGRAM;
+}
+
+err_t vm_lte_char(vm_t *vm)
+{
+ (void)vm;
+ return ERR_END_OF_PROGRAM;
+}
+
+err_t vm_lte_int(vm_t *vm)
+{
+ (void)vm;
+ return ERR_END_OF_PROGRAM;
+}
+
+err_t vm_lte_hword(vm_t *vm)
+{
+ (void)vm;
+ return ERR_END_OF_PROGRAM;
+}
+
+err_t vm_lte_long(vm_t *vm)
+{
+ (void)vm;
+ return ERR_END_OF_PROGRAM;
+}
+
+err_t vm_lte_word(vm_t *vm)
+{
+ (void)vm;
+ return ERR_END_OF_PROGRAM;
+}
+
+err_t vm_gt_byte(vm_t *vm)
+{
+ (void)vm;
+ return ERR_END_OF_PROGRAM;
+}
+
+err_t vm_gt_char(vm_t *vm)
+{
+ (void)vm;
+ return ERR_END_OF_PROGRAM;
+}
+
+err_t vm_gt_int(vm_t *vm)
+{
+ (void)vm;
+ return ERR_END_OF_PROGRAM;
+}
+
+err_t vm_gt_hword(vm_t *vm)
+{
+ (void)vm;
+ return ERR_END_OF_PROGRAM;
+}
+
+err_t vm_gt_long(vm_t *vm)
+{
+ (void)vm;
+ return ERR_END_OF_PROGRAM;
+}
+
+err_t vm_gt_word(vm_t *vm)
+{
+ (void)vm;
+ return ERR_END_OF_PROGRAM;
+}
+
+err_t vm_gte_byte(vm_t *vm)
+{
+ (void)vm;
+ return ERR_END_OF_PROGRAM;
+}
+
+err_t vm_gte_char(vm_t *vm)
+{
+ (void)vm;
+ return ERR_END_OF_PROGRAM;
+}
+
+err_t vm_gte_int(vm_t *vm)
+{
+ (void)vm;
+ return ERR_END_OF_PROGRAM;
+}
+
+err_t vm_gte_hword(vm_t *vm)
+{
+ (void)vm;
+ return ERR_END_OF_PROGRAM;
+}
+
+err_t vm_gte_long(vm_t *vm)
+{
+ (void)vm;
+ return ERR_END_OF_PROGRAM;
+}
+
+err_t vm_gte_word(vm_t *vm)
+{
+ (void)vm;
+ return ERR_END_OF_PROGRAM;
+}
+
err_t vm_plus_byte(vm_t *vm)
{
data_t a = {0}, b = {0};
diff --git a/vm/runtime.h b/vm/runtime.h
index 316b4c6..c2acfce 100644
--- a/vm/runtime.h
+++ b/vm/runtime.h
@@ -133,9 +133,40 @@ err_t vm_xor_hword(vm_t *);
err_t vm_xor_word(vm_t *);
err_t vm_eq_byte(vm_t *);
+err_t vm_eq_char(vm_t *);
+err_t vm_eq_int(vm_t *);
err_t vm_eq_hword(vm_t *);
+err_t vm_eq_long(vm_t *);
err_t vm_eq_word(vm_t *);
+err_t vm_lt_byte(vm_t *);
+err_t vm_lt_char(vm_t *);
+err_t vm_lt_int(vm_t *);
+err_t vm_lt_hword(vm_t *);
+err_t vm_lt_long(vm_t *);
+err_t vm_lt_word(vm_t *);
+
+err_t vm_lte_byte(vm_t *);
+err_t vm_lte_char(vm_t *);
+err_t vm_lte_int(vm_t *);
+err_t vm_lte_hword(vm_t *);
+err_t vm_lte_long(vm_t *);
+err_t vm_lte_word(vm_t *);
+
+err_t vm_gt_byte(vm_t *);
+err_t vm_gt_char(vm_t *);
+err_t vm_gt_int(vm_t *);
+err_t vm_gt_hword(vm_t *);
+err_t vm_gt_long(vm_t *);
+err_t vm_gt_word(vm_t *);
+
+err_t vm_gte_byte(vm_t *);
+err_t vm_gte_char(vm_t *);
+err_t vm_gte_int(vm_t *);
+err_t vm_gte_hword(vm_t *);
+err_t vm_gte_long(vm_t *);
+err_t vm_gte_word(vm_t *);
+
err_t vm_plus_byte(vm_t *);
err_t vm_plus_hword(vm_t *);
err_t vm_plus_word(vm_t *);
@@ -154,8 +185,25 @@ static const stack_f STACK_ROUTINES[] = {
[OP_XOR_BYTE] = vm_xor_byte, [OP_XOR_HWORD] = vm_xor_hword,
[OP_XOR_WORD] = vm_xor_word,
- [OP_EQ_BYTE] = vm_eq_byte, [OP_EQ_HWORD] = vm_eq_hword,
- [OP_EQ_WORD] = vm_eq_word,
+ [OP_EQ_BYTE] = vm_eq_byte, [OP_EQ_CHAR] = vm_eq_char,
+ [OP_EQ_INT] = vm_eq_int, [OP_EQ_HWORD] = vm_eq_hword,
+ [OP_EQ_LONG] = vm_eq_long, [OP_EQ_WORD] = vm_eq_word,
+
+ [OP_LT_BYTE] = vm_lt_byte, [OP_LT_CHAR] = vm_lt_char,
+ [OP_LT_INT] = vm_lt_int, [OP_LT_HWORD] = vm_lt_hword,
+ [OP_LT_LONG] = vm_lt_long, [OP_LT_WORD] = vm_lt_word,
+
+ [OP_LTE_BYTE] = vm_lte_byte, [OP_LTE_CHAR] = vm_lte_char,
+ [OP_LTE_INT] = vm_lte_int, [OP_LTE_HWORD] = vm_lte_hword,
+ [OP_LTE_LONG] = vm_lte_long, [OP_LTE_WORD] = vm_lte_word,
+
+ [OP_GT_BYTE] = vm_gt_byte, [OP_GT_CHAR] = vm_gt_char,
+ [OP_GT_INT] = vm_gt_int, [OP_GT_HWORD] = vm_gt_hword,
+ [OP_GT_LONG] = vm_gt_long, [OP_GT_WORD] = vm_gt_word,
+
+ [OP_GTE_BYTE] = vm_gte_byte, [OP_GTE_CHAR] = vm_gte_char,
+ [OP_GTE_INT] = vm_gte_int, [OP_GTE_HWORD] = vm_gte_hword,
+ [OP_GTE_LONG] = vm_gte_long, [OP_GTE_WORD] = vm_gte_word,
[OP_PLUS_BYTE] = vm_plus_byte, [OP_PLUS_HWORD] = vm_plus_hword,
[OP_PLUS_WORD] = vm_plus_word,