aboutsummaryrefslogtreecommitdiff
path: root/lib/inst.c
diff options
context:
space:
mode:
authorAryadev Chavali <aryadev@aryadevchavali.com>2023-11-01 22:07:08 +0000
committerAryadev Chavali <aryadev@aryadevchavali.com>2023-11-01 22:07:08 +0000
commit0649b3f3804fa1b8924eed9214f33bce6a2c06e8 (patch)
tree1ad6cf4b4da09eebdbaf368e5104f0bbc882ba8d /lib/inst.c
parent44125d7ad9fedbe693136969bf4a11d8c33bcab1 (diff)
downloadovm-0649b3f3804fa1b8924eed9214f33bce6a2c06e8.tar.gz
ovm-0649b3f3804fa1b8924eed9214f33bce6a2c06e8.tar.bz2
ovm-0649b3f3804fa1b8924eed9214f33bce6a2c06e8.zip
Added stack based versions of MSET and MGET
Essentially they use the stack for their one and only operand. This allows user level control, in particular it allows for loops to work correctly while using these operands.
Diffstat (limited to 'lib/inst.c')
-rw-r--r--lib/inst.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/lib/inst.c b/lib/inst.c
index 0fc66f3..048862b 100644
--- a/lib/inst.c
+++ b/lib/inst.c
@@ -65,12 +65,24 @@ const char *opcode_as_cstr(opcode_t code)
return "MSET_HWORD";
case OP_MSET_WORD:
return "MSET_WORD";
+ case OP_MSET_STACK_BYTE:
+ return "MSET_STACK_BYTE";
+ case OP_MSET_STACK_HWORD:
+ return "MSET_STACK_HWORD";
+ case OP_MSET_STACK_WORD:
+ return "MSET_STACK_WORD";
case OP_MGET_BYTE:
return "MGET_BYTE";
case OP_MGET_HWORD:
return "MGET_HWORD";
case OP_MGET_WORD:
return "MGET_WORD";
+ case OP_MGET_STACK_BYTE:
+ return "MGET_STACK_BYTE";
+ case OP_MGET_STACK_HWORD:
+ return "MGET_STACK_HWORD";
+ case OP_MGET_STACK_WORD:
+ return "MGET_STACK_WORD";
case OP_MDELETE:
return "MDELETE";
case OP_MSIZE:
@@ -217,7 +229,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 == 84, "inst_bytecode_size: Out of date");
+ static_assert(NUMBER_OF_OPCODES == 90, "inst_bytecode_size: Out of date");
fprintf(fp, "%s(", opcode_as_cstr(instruction.opcode));
if (OPCODE_IS_TYPE(instruction.opcode, OP_PUSH))
{
@@ -250,7 +262,7 @@ void inst_print(inst_t instruction, FILE *fp)
size_t inst_bytecode_size(inst_t inst)
{
- static_assert(NUMBER_OF_OPCODES == 84, "inst_bytecode_size: Out of date");
+ static_assert(NUMBER_OF_OPCODES == 90, "inst_bytecode_size: Out of date");
size_t size = 1; // for opcode
if (OPCODE_IS_TYPE(inst.opcode, OP_PUSH))
{
@@ -275,7 +287,7 @@ size_t inst_bytecode_size(inst_t inst)
void inst_write_bytecode(inst_t inst, darr_t *darr)
{
- static_assert(NUMBER_OF_OPCODES == 84, "inst_write_bytecode: Out of date");
+ static_assert(NUMBER_OF_OPCODES == 90, "inst_write_bytecode: Out of date");
// Append opcode
darr_append_byte(darr, inst.opcode);
// Then append 0 or more operands
@@ -351,7 +363,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 == 84, "inst_read_bytecode: Out of date");
+ static_assert(NUMBER_OF_OPCODES == 90, "inst_read_bytecode: Out of date");
if (darr->used >= darr->available)
return (inst_t){0};
inst_t inst = {0};