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.
This commit is contained in:
20
lib/inst.c
20
lib/inst.c
@@ -65,12 +65,24 @@ const char *opcode_as_cstr(opcode_t code)
|
|||||||
return "MSET_HWORD";
|
return "MSET_HWORD";
|
||||||
case OP_MSET_WORD:
|
case OP_MSET_WORD:
|
||||||
return "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:
|
case OP_MGET_BYTE:
|
||||||
return "MGET_BYTE";
|
return "MGET_BYTE";
|
||||||
case OP_MGET_HWORD:
|
case OP_MGET_HWORD:
|
||||||
return "MGET_HWORD";
|
return "MGET_HWORD";
|
||||||
case OP_MGET_WORD:
|
case OP_MGET_WORD:
|
||||||
return "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:
|
case OP_MDELETE:
|
||||||
return "MDELETE";
|
return "MDELETE";
|
||||||
case OP_MSIZE:
|
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)
|
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));
|
fprintf(fp, "%s(", opcode_as_cstr(instruction.opcode));
|
||||||
if (OPCODE_IS_TYPE(instruction.opcode, OP_PUSH))
|
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)
|
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
|
size_t size = 1; // for opcode
|
||||||
if (OPCODE_IS_TYPE(inst.opcode, OP_PUSH))
|
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)
|
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
|
// Append opcode
|
||||||
darr_append_byte(darr, inst.opcode);
|
darr_append_byte(darr, inst.opcode);
|
||||||
// Then append 0 or more operands
|
// 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)
|
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)
|
if (darr->used >= darr->available)
|
||||||
return (inst_t){0};
|
return (inst_t){0};
|
||||||
inst_t inst = {0};
|
inst_t inst = {0};
|
||||||
|
|||||||
17
lib/inst.h
17
lib/inst.h
@@ -48,12 +48,23 @@ typedef enum
|
|||||||
OP_MALLOC_BYTE,
|
OP_MALLOC_BYTE,
|
||||||
OP_MALLOC_HWORD,
|
OP_MALLOC_HWORD,
|
||||||
OP_MALLOC_WORD,
|
OP_MALLOC_WORD,
|
||||||
|
|
||||||
OP_MSET_BYTE,
|
OP_MSET_BYTE,
|
||||||
OP_MSET_HWORD,
|
OP_MSET_HWORD,
|
||||||
OP_MSET_WORD,
|
OP_MSET_WORD,
|
||||||
|
|
||||||
|
OP_MSET_STACK_BYTE,
|
||||||
|
OP_MSET_STACK_HWORD,
|
||||||
|
OP_MSET_STACK_WORD,
|
||||||
|
|
||||||
OP_MGET_BYTE,
|
OP_MGET_BYTE,
|
||||||
OP_MGET_HWORD,
|
OP_MGET_HWORD,
|
||||||
OP_MGET_WORD,
|
OP_MGET_WORD,
|
||||||
|
|
||||||
|
OP_MGET_STACK_BYTE,
|
||||||
|
OP_MGET_STACK_HWORD,
|
||||||
|
OP_MGET_STACK_WORD,
|
||||||
|
|
||||||
OP_MDELETE,
|
OP_MDELETE,
|
||||||
OP_MSIZE,
|
OP_MSIZE,
|
||||||
|
|
||||||
@@ -187,10 +198,12 @@ inst_t *insts_read_bytecode_file(FILE *, size_t *);
|
|||||||
((inst_t){.opcode = OP_MALLOC_##TYPE, .operand = DWORD(OP)})
|
((inst_t){.opcode = OP_MALLOC_##TYPE, .operand = DWORD(OP)})
|
||||||
#define INST_MSET(TYPE, OP) \
|
#define INST_MSET(TYPE, OP) \
|
||||||
((inst_t){.opcode = OP_MSET_##TYPE, .operand = DWORD(OP)})
|
((inst_t){.opcode = OP_MSET_##TYPE, .operand = DWORD(OP)})
|
||||||
|
#define INST_MSET_STACK(TYPE) ((inst_t){.opcode = OP_MSET_STACK_##TYPE})
|
||||||
#define INST_MGET(TYPE, OP) \
|
#define INST_MGET(TYPE, OP) \
|
||||||
((inst_t){.opcode = OP_MGET_##TYPE, .operand = DWORD(OP)})
|
((inst_t){.opcode = OP_MGET_##TYPE, .operand = DWORD(OP)})
|
||||||
#define INST_MDELETE ((inst_t){.opcode = OP_MDELETE})
|
#define INST_MGET_STACK(TYPE) ((inst_t){.opcode = OP_MGET_STACK_##TYPE})
|
||||||
#define INST_MSIZE ((inst_t){.opcode = OP_MSIZE})
|
#define INST_MDELETE ((inst_t){.opcode = OP_MDELETE})
|
||||||
|
#define INST_MSIZE ((inst_t){.opcode = OP_MSIZE})
|
||||||
|
|
||||||
#define INST_NOT(TYPE) ((inst_t){.opcode = OP_NOT_##TYPE})
|
#define INST_NOT(TYPE) ((inst_t){.opcode = OP_NOT_##TYPE})
|
||||||
#define INST_OR(TYPE) ((inst_t){.opcode = OP_OR_##TYPE})
|
#define INST_OR(TYPE) ((inst_t){.opcode = OP_OR_##TYPE})
|
||||||
|
|||||||
Reference in New Issue
Block a user