From 0649b3f3804fa1b8924eed9214f33bce6a2c06e8 Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Wed, 1 Nov 2023 22:07:08 +0000 Subject: 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. --- lib/inst.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'lib/inst.c') 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}; -- cgit v1.2.3-13-gbd6f