diff options
| -rw-r--r-- | asm/lexer.c | 2 | ||||
| -rw-r--r-- | asm/parser.c | 10 | ||||
| -rw-r--r-- | lib/inst.c | 20 | ||||
| -rw-r--r-- | lib/inst.h | 3 | ||||
| -rw-r--r-- | vm/runtime.c | 9 | 
5 files changed, 9 insertions, 35 deletions
| diff --git a/asm/lexer.c b/asm/lexer.c index 01c2e5d..836dd08 100644 --- a/asm/lexer.c +++ b/asm/lexer.c @@ -137,7 +137,7 @@ bool is_valid_hex_char(char c)  token_t tokenise_symbol(buffer_t *buffer, size_t *column)  { -  static_assert(NUMBER_OF_OPCODES == 96, "tokenise_buffer: Out of date!"); +  static_assert(NUMBER_OF_OPCODES == 95, "tokenise_buffer: Out of date!");    size_t sym_size = 0;    for (; sym_size < space_left(buffer) && diff --git a/asm/parser.c b/asm/parser.c index f9eb975..da0c93c 100644 --- a/asm/parser.c +++ b/asm/parser.c @@ -413,16 +413,6 @@ perr_t parse_next(token_stream_t *stream, presult_t *ret)          return PERR_EXPECTED_OPERAND;        return parse_word_label_or_relative(stream, ret);      } -    else if (token.str_size == 9 && strncmp(token.str, ".REGISTER", 9) == 0) -    { -      *ret = (presult_t){.instruction = INST_JUMP_REGISTER(0), -                         .type        = PRES_COMPLETE_RESULT}; -      ++stream->used; -      if (stream->used >= stream->available) -        return PERR_EXPECTED_OPERAND; -      return parse_word(TOKEN_STREAM_AT(stream->data, stream->used), -                        &ret->instruction.operand.as_word); -    }      else if (token.str_size == 6 && strncmp(token.str, ".STACK", 6) == 0)        *ret = (presult_t){.instruction = INST_JUMP_STACK,                           .type        = PRES_COMPLETE_RESULT}; @@ -193,8 +193,6 @@ const char *opcode_as_cstr(opcode_t code)      return "JUMP_ABS";    case OP_JUMP_STACK:      return "JUMP_STACK"; -  case OP_JUMP_REGISTER: -    return "JUMP_REGISTER";    case OP_JUMP_IF_BYTE:      return "JUMP_IF_BYTE";    case OP_JUMP_IF_HWORD: @@ -241,7 +239,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 == 96, "inst_bytecode_size: Out of date"); +  static_assert(NUMBER_OF_OPCODES == 95, "inst_bytecode_size: Out of date");    fprintf(fp, "%s(", opcode_as_cstr(instruction.opcode));    if (OPCODE_IS_TYPE(instruction.opcode, OP_PUSH))    { @@ -250,8 +248,7 @@ void inst_print(inst_t instruction, FILE *fp)      data_print(instruction.operand, type, fp);    }    else if (OPCODE_IS_TYPE(instruction.opcode, OP_PUSH_REGISTER) || -           OPCODE_IS_TYPE(instruction.opcode, OP_MOV) || -           instruction.opcode == OP_JUMP_REGISTER) +           OPCODE_IS_TYPE(instruction.opcode, OP_MOV))    {      fprintf(fp, "reg=0x");      data_print(instruction.operand, DATA_TYPE_BYTE, fp); @@ -274,7 +271,7 @@ void inst_print(inst_t instruction, FILE *fp)  size_t inst_bytecode_size(inst_t inst)  { -  static_assert(NUMBER_OF_OPCODES == 96, "inst_bytecode_size: Out of date"); +  static_assert(NUMBER_OF_OPCODES == 95, "inst_bytecode_size: Out of date");    size_t size = 1; // for opcode    if (OPCODE_IS_TYPE(inst.opcode, OP_PUSH))    { @@ -291,7 +288,6 @@ size_t inst_bytecode_size(inst_t inst)             OPCODE_IS_TYPE(inst.opcode, OP_MALLOC) ||             OPCODE_IS_TYPE(inst.opcode, OP_MSET) ||             OPCODE_IS_TYPE(inst.opcode, OP_MGET) || inst.opcode == OP_JUMP_ABS || -           inst.opcode == OP_JUMP_REGISTER ||             OPCODE_IS_TYPE(inst.opcode, OP_JUMP_IF))      size += WORD_SIZE;    return size; @@ -299,7 +295,7 @@ size_t inst_bytecode_size(inst_t inst)  void inst_write_bytecode(inst_t inst, darr_t *darr)  { -  static_assert(NUMBER_OF_OPCODES == 96, "inst_write_bytecode: Out of date"); +  static_assert(NUMBER_OF_OPCODES == 95, "inst_write_bytecode: Out of date");    // Append opcode    darr_append_byte(darr, inst.opcode);    // Then append 0 or more operands @@ -311,8 +307,7 @@ void inst_write_bytecode(inst_t inst, darr_t *darr)             OPCODE_IS_TYPE(inst.opcode, OP_DUP) ||             OPCODE_IS_TYPE(inst.opcode, OP_MALLOC) ||             OPCODE_IS_TYPE(inst.opcode, OP_MSET) || -           OPCODE_IS_TYPE(inst.opcode, OP_MGET) || -           inst.opcode == OP_JUMP_REGISTER || inst.opcode == OP_JUMP_ABS || +           OPCODE_IS_TYPE(inst.opcode, OP_MGET) || inst.opcode == OP_JUMP_ABS ||             OPCODE_IS_TYPE(inst.opcode, OP_JUMP_IF))      to_append = DATA_TYPE_WORD; @@ -375,7 +370,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 == 96, "inst_read_bytecode: Out of date"); +  static_assert(NUMBER_OF_OPCODES == 95, "inst_read_bytecode: Out of date");    if (darr->used >= darr->available)      return (inst_t){0};    inst_t inst     = {0}; @@ -387,8 +382,7 @@ inst_t inst_read_bytecode(darr_t *darr)      inst.operand = read_type_from_darr(darr, (data_type_t)opcode);    // Read register (as a byte)    else if (OPCODE_IS_TYPE(opcode, OP_PUSH_REGISTER) || -           OPCODE_IS_TYPE(opcode, OP_MOV) || opcode == OP_JUMP_REGISTER || -           OPCODE_IS_TYPE(opcode, OP_DUP) || +           OPCODE_IS_TYPE(opcode, OP_MOV) || OPCODE_IS_TYPE(opcode, OP_DUP) ||             OPCODE_IS_TYPE(opcode, OP_MALLOC) ||             OPCODE_IS_TYPE(opcode, OP_MSET) || OPCODE_IS_TYPE(opcode, OP_MGET) ||             opcode == OP_JUMP_ABS || OPCODE_IS_TYPE(opcode, OP_JUMP_IF)) @@ -145,7 +145,6 @@ typedef enum    // Program control flow    OP_JUMP_ABS,    OP_JUMP_STACK, -  OP_JUMP_REGISTER,    OP_JUMP_IF_BYTE,    OP_JUMP_IF_HWORD,    OP_JUMP_IF_WORD, @@ -230,8 +229,6 @@ inst_t *insts_read_bytecode_file(FILE *, size_t *);  #define INST_JUMP_ABS(OP) \    ((inst_t){.opcode = OP_JUMP_ABS, .operand = DWORD(OP)})  #define INST_JUMP_STACK ((inst_t){.opcode = OP_JUMP_STACK}) -#define INST_JUMP_REGISTER(OP) \ -  ((inst_t){.opcode = OP_JUMP_REGISTER, .operand = DWORD(OP)})  #define INST_JUMP_IF(TYPE, OP) \    ((inst_t){.opcode = OP_JUMP_IF_##TYPE, .operand = DWORD(OP)}) diff --git a/vm/runtime.c b/vm/runtime.c index 5d5333b..c927662 100644 --- a/vm/runtime.c +++ b/vm/runtime.c @@ -60,7 +60,7 @@ const char *err_as_cstr(err_t err)  err_t vm_execute(vm_t *vm)  { -  static_assert(NUMBER_OF_OPCODES == 96, "vm_execute: Out of date"); +  static_assert(NUMBER_OF_OPCODES == 95, "vm_execute: Out of date");    struct Program *prog = &vm->program;    if (prog->ptr >= prog->max)      return ERR_END_OF_PROGRAM; @@ -133,13 +133,6 @@ err_t vm_execute(vm_t *vm)        return err;      return vm_jump(vm, ret.as_word);    } -  else if (instruction.opcode == OP_JUMP_REGISTER) -  { -    if (instruction.operand.as_word >= vm->registers.available) -      return ERR_INVALID_REGISTER_WORD; -    word addr = vm->registers.data[instruction.operand.as_word]; -    return vm_jump(vm, addr); -  }    else if (OPCODE_IS_TYPE(instruction.opcode, OP_JUMP_IF))    {      data_t datum = {0}; | 
