aboutsummaryrefslogtreecommitdiff
path: root/vm/inst.c
diff options
context:
space:
mode:
authorAryadev Chavali <aryadev@aryadevchavali.com>2023-10-31 20:40:55 +0000
committerAryadev Chavali <aryadev@aryadevchavali.com>2023-10-31 20:50:28 +0000
commit0975d924938a3500380b22395b3262053f720ee2 (patch)
treeaf284af75e63950aacce4b45d216f42b311254b5 /vm/inst.c
parent7ca8f2c6445a902c681f4b871d15e0eda3724895 (diff)
downloadovm-0975d924938a3500380b22395b3262053f720ee2.tar.gz
ovm-0975d924938a3500380b22395b3262053f720ee2.tar.bz2
ovm-0975d924938a3500380b22395b3262053f720ee2.zip
Introduced new instructions for comparison
Comparing signed and unsigned versions of numbers. Same for EQ as well. Notice the irregular pattern of BYTE, CHAR, INT, HWORD,LONG,WORD as OPCODE_IS_TYPE requires the subcodes to be surrounded by BYTE and WORD.
Diffstat (limited to 'vm/inst.c')
-rw-r--r--vm/inst.c89
1 files changed, 85 insertions, 4 deletions
diff --git a/vm/inst.c b/vm/inst.c
index 1c245fa..5be2438 100644
--- a/vm/inst.c
+++ b/vm/inst.c
@@ -108,12 +108,93 @@ const char *opcode_as_cstr(opcode_t code)
case OP_EQ_BYTE:
return "EQ_BYTE";
break;
+ case OP_EQ_CHAR:
+ return "EQ_CHAR";
+ break;
+ case OP_EQ_INT:
+ return "EQ_INT";
+ break;
case OP_EQ_HWORD:
return "EQ_HWORD";
break;
+ case OP_EQ_LONG:
+ return "EQ_LONG";
+ break;
case OP_EQ_WORD:
return "EQ_WORD";
break;
+ case OP_LT_BYTE:
+ return "LT_BYTE";
+ break;
+ case OP_LT_CHAR:
+ return "LT_CHAR";
+ break;
+ case OP_LT_HWORD:
+ return "LT_HWORD";
+ break;
+ case OP_LT_INT:
+ return "LT_INT";
+ break;
+ case OP_LT_LONG:
+ return "LT_LONG";
+ break;
+ case OP_LT_WORD:
+ return "LT_WORD";
+ break;
+ case OP_LTE_BYTE:
+ return "LTE_BYTE";
+ break;
+ case OP_LTE_CHAR:
+ return "LTE_CHAR";
+ break;
+ case OP_LTE_HWORD:
+ return "LTE_HWORD";
+ break;
+ case OP_LTE_INT:
+ return "LTE_INT";
+ break;
+ case OP_LTE_LONG:
+ return "LTE_LONG";
+ break;
+ case OP_LTE_WORD:
+ return "LTE_WORD";
+ break;
+ case OP_GT_BYTE:
+ return "GT_BYTE";
+ break;
+ case OP_GT_CHAR:
+ return "GT_CHAR";
+ break;
+ case OP_GT_HWORD:
+ return "GT_HWORD";
+ break;
+ case OP_GT_INT:
+ return "GT_INT";
+ break;
+ case OP_GT_LONG:
+ return "GT_LONG";
+ break;
+ case OP_GT_WORD:
+ return "GT_WORD";
+ break;
+ case OP_GTE_BYTE:
+ return "GTE_BYTE";
+ break;
+ case OP_GTE_CHAR:
+ return "GTE_CHAR";
+ break;
+ case OP_GTE_HWORD:
+ return "GTE_HWORD";
+ break;
+ case OP_GTE_INT:
+ return "GTE_INT";
+ break;
+ case OP_GTE_LONG:
+ return "GTE_LONG";
+ break;
+ case OP_GTE_WORD:
+ return "GTE_WORD";
+ break;
case OP_PLUS_BYTE:
return "PLUS_BYTE";
break;
@@ -189,7 +270,7 @@ void data_print(data_t datum, data_type_t type, FILE *fp)
void inst_print(inst_t instruction, FILE *fp)
{
- static_assert(NUMBER_OF_OPCODES == 46, "inst_bytecode_size: Out of date");
+ static_assert(NUMBER_OF_OPCODES == 73, "inst_bytecode_size: Out of date");
fprintf(fp, "%s(", opcode_as_cstr(instruction.opcode));
if (OPCODE_IS_TYPE(instruction.opcode, OP_PUSH))
{
@@ -219,7 +300,7 @@ void inst_print(inst_t instruction, FILE *fp)
size_t inst_bytecode_size(inst_t inst)
{
- static_assert(NUMBER_OF_OPCODES == 46, "inst_bytecode_size: Out of date");
+ static_assert(NUMBER_OF_OPCODES == 73, "inst_bytecode_size: Out of date");
size_t size = 1; // for opcode
if (OPCODE_IS_TYPE(inst.opcode, OP_PUSH))
{
@@ -243,7 +324,7 @@ size_t inst_bytecode_size(inst_t inst)
void inst_write_bytecode(inst_t inst, darr_t *darr)
{
- static_assert(NUMBER_OF_OPCODES == 46, "inst_write_bytecode: Out of date");
+ static_assert(NUMBER_OF_OPCODES == 73, "inst_write_bytecode: Out of date");
// Append opcode
darr_append_byte(darr, inst.opcode);
// Then append 0 or more operands
@@ -317,7 +398,7 @@ data_t read_type_from_darr(darr_t *darr, data_type_t type)
inst_t inst_read_bytecode(darr_t *darr)
{
- static_assert(NUMBER_OF_OPCODES == 46, "inst_read_bytecode: Out of date");
+ static_assert(NUMBER_OF_OPCODES == 73, "inst_read_bytecode: Out of date");
if (darr->used >= darr->available)
return (inst_t){0};
inst_t inst = {0};