aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/inst.c20
-rw-r--r--lib/inst.h10
2 files changed, 26 insertions, 4 deletions
diff --git a/lib/inst.c b/lib/inst.c
index 048862b..85fb23b 100644
--- a/lib/inst.c
+++ b/lib/inst.c
@@ -59,6 +59,12 @@ const char *opcode_as_cstr(opcode_t code)
return "MALLOC_HWORD";
case OP_MALLOC_WORD:
return "MALLOC_WORD";
+ case OP_MALLOC_STACK_BYTE:
+ return "MALLOC_STACK_BYTE";
+ case OP_MALLOC_STACK_HWORD:
+ return "MALLOC_STACK_HWORD";
+ case OP_MALLOC_STACK_WORD:
+ return "MALLOC_STACK_WORD";
case OP_MSET_BYTE:
return "MSET_BYTE";
case OP_MSET_HWORD:
@@ -171,6 +177,12 @@ const char *opcode_as_cstr(opcode_t code)
return "PLUS_HWORD";
case OP_PLUS_WORD:
return "PLUS_WORD";
+ case OP_SUB_BYTE:
+ return "SUB_BYTE";
+ case OP_SUB_HWORD:
+ return "SUB_HWORD";
+ case OP_SUB_WORD:
+ return "SUB_WORD";
case OP_MULT_BYTE:
return "MULT_BYTE";
case OP_MULT_HWORD:
@@ -229,7 +241,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 == 90, "inst_bytecode_size: Out of date");
+ static_assert(NUMBER_OF_OPCODES == 96, "inst_bytecode_size: Out of date");
fprintf(fp, "%s(", opcode_as_cstr(instruction.opcode));
if (OPCODE_IS_TYPE(instruction.opcode, OP_PUSH))
{
@@ -262,7 +274,7 @@ void inst_print(inst_t instruction, FILE *fp)
size_t inst_bytecode_size(inst_t inst)
{
- static_assert(NUMBER_OF_OPCODES == 90, "inst_bytecode_size: Out of date");
+ static_assert(NUMBER_OF_OPCODES == 96, "inst_bytecode_size: Out of date");
size_t size = 1; // for opcode
if (OPCODE_IS_TYPE(inst.opcode, OP_PUSH))
{
@@ -287,7 +299,7 @@ size_t inst_bytecode_size(inst_t inst)
void inst_write_bytecode(inst_t inst, darr_t *darr)
{
- static_assert(NUMBER_OF_OPCODES == 90, "inst_write_bytecode: Out of date");
+ static_assert(NUMBER_OF_OPCODES == 96, "inst_write_bytecode: Out of date");
// Append opcode
darr_append_byte(darr, inst.opcode);
// Then append 0 or more operands
@@ -363,7 +375,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 == 90, "inst_read_bytecode: Out of date");
+ static_assert(NUMBER_OF_OPCODES == 96, "inst_read_bytecode: Out of date");
if (darr->used >= darr->available)
return (inst_t){0};
inst_t inst = {0};
diff --git a/lib/inst.h b/lib/inst.h
index 5671b47..10f8dc7 100644
--- a/lib/inst.h
+++ b/lib/inst.h
@@ -49,6 +49,10 @@ typedef enum
OP_MALLOC_HWORD,
OP_MALLOC_WORD,
+ OP_MALLOC_STACK_BYTE,
+ OP_MALLOC_STACK_HWORD,
+ OP_MALLOC_STACK_WORD,
+
OP_MSET_BYTE,
OP_MSET_HWORD,
OP_MSET_WORD,
@@ -122,6 +126,10 @@ typedef enum
OP_PLUS_HWORD,
OP_PLUS_WORD,
+ OP_SUB_BYTE,
+ OP_SUB_HWORD,
+ OP_SUB_WORD,
+
OP_MULT_BYTE,
OP_MULT_HWORD,
OP_MULT_WORD,
@@ -196,6 +204,7 @@ inst_t *insts_read_bytecode_file(FILE *, size_t *);
#define INST_MALLOC(TYPE, OP) \
((inst_t){.opcode = OP_MALLOC_##TYPE, .operand = DWORD(OP)})
+#define INST_MALLOC_STACK(TYPE) ((inst_t){.opcode = OP_MALLOC_STACK_##TYPE})
#define INST_MSET(TYPE, OP) \
((inst_t){.opcode = OP_MSET_##TYPE, .operand = DWORD(OP)})
#define INST_MSET_STACK(TYPE) ((inst_t){.opcode = OP_MSET_STACK_##TYPE})
@@ -215,6 +224,7 @@ inst_t *insts_read_bytecode_file(FILE *, size_t *);
#define INST_GT(TYPE) ((inst_t){.opcode = OP_GT_##TYPE})
#define INST_GTE(TYPE) ((inst_t){.opcode = OP_GTE_##TYPE})
#define INST_PLUS(TYPE) ((inst_t){.opcode = OP_PLUS_##TYPE})
+#define INST_SUB(TYPE) ((inst_t){.opcode = OP_SUB_##TYPE})
#define INST_MULT(TYPE) ((inst_t){.opcode = OP_MULT_##TYPE})
#define INST_JUMP_ABS(OP) \