Removed OP_EQ signed versions as they're useless
A negative number under 2s complement can never be equal to its positive as the top bit *must* be on. If two numbers are equivalent bit-by-bit then they are equal for both signed and unsigned numbers.
This commit is contained in:
17
lib/inst.c
17
lib/inst.c
@@ -108,18 +108,9 @@ const char *opcode_as_cstr(opcode_t code)
|
|||||||
case OP_EQ_BYTE:
|
case OP_EQ_BYTE:
|
||||||
return "EQ_BYTE";
|
return "EQ_BYTE";
|
||||||
break;
|
break;
|
||||||
case OP_EQ_CHAR:
|
|
||||||
return "EQ_CHAR";
|
|
||||||
break;
|
|
||||||
case OP_EQ_INT:
|
|
||||||
return "EQ_INT";
|
|
||||||
break;
|
|
||||||
case OP_EQ_HWORD:
|
case OP_EQ_HWORD:
|
||||||
return "EQ_HWORD";
|
return "EQ_HWORD";
|
||||||
break;
|
break;
|
||||||
case OP_EQ_LONG:
|
|
||||||
return "EQ_LONG";
|
|
||||||
break;
|
|
||||||
case OP_EQ_WORD:
|
case OP_EQ_WORD:
|
||||||
return "EQ_WORD";
|
return "EQ_WORD";
|
||||||
break;
|
break;
|
||||||
@@ -270,7 +261,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 == 73, "inst_bytecode_size: Out of date");
|
static_assert(NUMBER_OF_OPCODES == 70, "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))
|
||||||
{
|
{
|
||||||
@@ -300,7 +291,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 == 73, "inst_bytecode_size: Out of date");
|
static_assert(NUMBER_OF_OPCODES == 70, "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))
|
||||||
{
|
{
|
||||||
@@ -324,7 +315,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 == 73, "inst_write_bytecode: Out of date");
|
static_assert(NUMBER_OF_OPCODES == 70, "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
|
||||||
@@ -398,7 +389,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 == 73, "inst_read_bytecode: Out of date");
|
static_assert(NUMBER_OF_OPCODES == 70, "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};
|
||||||
|
|||||||
@@ -62,10 +62,7 @@ typedef enum
|
|||||||
OP_XOR_WORD,
|
OP_XOR_WORD,
|
||||||
|
|
||||||
OP_EQ_BYTE,
|
OP_EQ_BYTE,
|
||||||
OP_EQ_CHAR,
|
|
||||||
OP_EQ_HWORD,
|
OP_EQ_HWORD,
|
||||||
OP_EQ_INT,
|
|
||||||
OP_EQ_LONG,
|
|
||||||
OP_EQ_WORD,
|
OP_EQ_WORD,
|
||||||
|
|
||||||
// Mathematical operations
|
// Mathematical operations
|
||||||
@@ -75,24 +72,28 @@ typedef enum
|
|||||||
OP_LT_INT,
|
OP_LT_INT,
|
||||||
OP_LT_LONG,
|
OP_LT_LONG,
|
||||||
OP_LT_WORD,
|
OP_LT_WORD,
|
||||||
|
|
||||||
OP_LTE_BYTE,
|
OP_LTE_BYTE,
|
||||||
OP_LTE_CHAR,
|
OP_LTE_CHAR,
|
||||||
OP_LTE_HWORD,
|
OP_LTE_HWORD,
|
||||||
OP_LTE_INT,
|
OP_LTE_INT,
|
||||||
OP_LTE_LONG,
|
OP_LTE_LONG,
|
||||||
OP_LTE_WORD,
|
OP_LTE_WORD,
|
||||||
|
|
||||||
OP_GT_BYTE,
|
OP_GT_BYTE,
|
||||||
OP_GT_CHAR,
|
OP_GT_CHAR,
|
||||||
OP_GT_HWORD,
|
OP_GT_HWORD,
|
||||||
OP_GT_INT,
|
OP_GT_INT,
|
||||||
OP_GT_LONG,
|
OP_GT_LONG,
|
||||||
OP_GT_WORD,
|
OP_GT_WORD,
|
||||||
|
|
||||||
OP_GTE_BYTE,
|
OP_GTE_BYTE,
|
||||||
OP_GTE_CHAR,
|
OP_GTE_CHAR,
|
||||||
OP_GTE_HWORD,
|
OP_GTE_HWORD,
|
||||||
OP_GTE_INT,
|
OP_GTE_INT,
|
||||||
OP_GTE_LONG,
|
OP_GTE_LONG,
|
||||||
OP_GTE_WORD,
|
OP_GTE_WORD,
|
||||||
|
|
||||||
OP_PLUS_BYTE,
|
OP_PLUS_BYTE,
|
||||||
OP_PLUS_HWORD,
|
OP_PLUS_HWORD,
|
||||||
OP_PLUS_WORD,
|
OP_PLUS_WORD,
|
||||||
@@ -100,8 +101,8 @@ typedef enum
|
|||||||
// Simple I/O
|
// Simple I/O
|
||||||
OP_PRINT_BYTE,
|
OP_PRINT_BYTE,
|
||||||
OP_PRINT_CHAR,
|
OP_PRINT_CHAR,
|
||||||
OP_PRINT_INT,
|
|
||||||
OP_PRINT_HWORD,
|
OP_PRINT_HWORD,
|
||||||
|
OP_PRINT_INT,
|
||||||
OP_PRINT_LONG,
|
OP_PRINT_LONG,
|
||||||
OP_PRINT_WORD,
|
OP_PRINT_WORD,
|
||||||
|
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ const char *err_as_cstr(err_t err)
|
|||||||
|
|
||||||
err_t vm_execute(vm_t *vm)
|
err_t vm_execute(vm_t *vm)
|
||||||
{
|
{
|
||||||
static_assert(NUMBER_OF_OPCODES == 73, "vm_execute: Out of date");
|
static_assert(NUMBER_OF_OPCODES == 70, "vm_execute: Out of date");
|
||||||
struct Program *prog = &vm->program;
|
struct Program *prog = &vm->program;
|
||||||
if (prog->ptr >= prog->max)
|
if (prog->ptr >= prog->max)
|
||||||
return ERR_END_OF_PROGRAM;
|
return ERR_END_OF_PROGRAM;
|
||||||
|
|||||||
@@ -181,9 +181,8 @@ static const stack_f STACK_ROUTINES[] = {
|
|||||||
[OP_XOR_BYTE] = vm_xor_byte, [OP_XOR_HWORD] = vm_xor_hword,
|
[OP_XOR_BYTE] = vm_xor_byte, [OP_XOR_HWORD] = vm_xor_hword,
|
||||||
[OP_XOR_WORD] = vm_xor_word,
|
[OP_XOR_WORD] = vm_xor_word,
|
||||||
|
|
||||||
[OP_EQ_BYTE] = vm_eq_byte, [OP_EQ_CHAR] = vm_eq_char,
|
[OP_EQ_BYTE] = vm_eq_byte, [OP_EQ_HWORD] = vm_eq_hword,
|
||||||
[OP_EQ_INT] = vm_eq_int, [OP_EQ_HWORD] = vm_eq_hword,
|
[OP_EQ_WORD] = vm_eq_word,
|
||||||
[OP_EQ_LONG] = vm_eq_long, [OP_EQ_WORD] = vm_eq_word,
|
|
||||||
|
|
||||||
[OP_LT_BYTE] = vm_lt_byte, [OP_LT_CHAR] = vm_lt_char,
|
[OP_LT_BYTE] = vm_lt_byte, [OP_LT_CHAR] = vm_lt_char,
|
||||||
[OP_LT_INT] = vm_lt_int, [OP_LT_HWORD] = vm_lt_hword,
|
[OP_LT_INT] = vm_lt_int, [OP_LT_HWORD] = vm_lt_hword,
|
||||||
|
|||||||
Reference in New Issue
Block a user