From: chaoskagami Date: Sat, 11 Jun 2016 15:31:05 +0000 (-0400) Subject: Make find non-aborting. We need bytecode itself to decide when it has failed imo X-Git-Tag: v0.0.9~11 X-Git-Url: https://chaos.moe/g/?a=commitdiff_plain;h=26bd4211b5ecbe0bcf71be832c9523535b09782e;p=corbenik%2Fcorbenik.git Make find non-aborting. We need bytecode itself to decide when it has failed imo --- diff --git a/host/bytecode_asm.py b/host/bytecode_asm.py index a60fd73..1915043 100755 --- a/host/bytecode_asm.py +++ b/host/bytecode_asm.py @@ -256,6 +256,28 @@ def parse_op(token_list, instr_offs): val = bytearray(struct.pack(">H", instr_offs[num])) val.reverse() return bytearray.fromhex("67") + val + elif token_list[0] == "jmpf": + if s != 2: + syn_err("invalid number of arguments") + + if instr_offs == None: + return bytearray.fromhex("070000") + else: + num = int(token_list[1]) + val = bytearray(struct.pack(">H", instr_offs[num])) + val.reverse() + return bytearray.fromhex("77") + val + elif token_list[0] == "jmpnf": + if s != 2: + syn_err("invalid number of arguments") + + if instr_offs == None: + return bytearray.fromhex("070000") + else: + num = int(token_list[1]) + val = bytearray(struct.pack(">H", instr_offs[num])) + val.reverse() + return bytearray.fromhex("87") + val def pad_zero_r(x, c): while len(x) < c: diff --git a/source/interp.c b/source/interp.c index ddf7575..c7d1970 100644 --- a/source/interp.c +++ b/source/interp.c @@ -32,6 +32,8 @@ #define OP_JMPGT 0x47 #define OP_JMPLE 0x57 #define OP_JMPGE 0x67 +#define OP_JMPF 0x77 +#define OP_JMPNF 0x87 #define OP_NEXT 0xFF @@ -140,7 +142,7 @@ exec_bytecode(uint8_t *bytecode, uint16_t ver, uint32_t len, int debug) uint32_t i; - int eq = 0, gt = 0, lt = 0; // Flags. + int eq = 0, gt = 0, lt = 0, found = 0; // Flags. uint8_t *code = bytecode; uint8_t *end = code + len; @@ -163,10 +165,11 @@ exec_bytecode(uint8_t *bytecode, uint16_t ver, uint32_t len, int debug) if (debug) log("find\n"); code += 2; - offset = (uint32_t)memfind(current_mode->memory + offset, current_mode->size - offset, code, *(code - 1)); - if ((uint8_t *)offset == NULL) { - // Error. Abort. - abort("Find opcode failed.\n"); + found = 0; + new_offset = (uint32_t)memfind(current_mode->memory + offset, current_mode->size - offset, code, *(code - 1)); + if ((uint8_t *)new_offset != NULL) { + // Pattern found, set found state flag + found = 1; } offset = offset - (uint32_t)current_mode->memory; code += *(code - 1); @@ -264,11 +267,20 @@ exec_bytecode(uint8_t *bytecode, uint16_t ver, uint32_t len, int debug) else code += 2; break; - case OP_JMPGE: // Jump to offset if greater than or equal + case OP_JMPF: // Jump to offset if pattern found if (debug) - log("jmpge\n"); + log("jmpf\n"); code++; - if (gt || eq) + if (found) + code = bytecode + (code[0] + (code[1] << 8)); + else + code += 2; + break; + case OP_JMPNF: // Jump to offset if pattern NOT found + if (debug) + log("jmpnf\n"); + code++; + if (!found) code = bytecode + (code[0] + (code[1] << 8)); else code += 2; @@ -277,7 +289,7 @@ exec_bytecode(uint8_t *bytecode, uint16_t ver, uint32_t len, int debug) if (debug) log("clf\n"); code++; - gt = lt = eq = 0; + found = gt = lt = eq = 0; break; case OP_REWIND: if (debug)