diff --git a/Makefile b/Makefile index 064862a..b8310fc 100644 --- a/Makefile +++ b/Makefile @@ -133,6 +133,7 @@ src/debug.o: src/opcodes.h src/value.o: src/opcodes.h src/vm.o: src/opcodes.h src/exceptions.o: src/opcodes.h +modules/dis.so: src/opcodes.h %.o: %.c ${HEADERS} diff --git a/src/debug.c b/src/debug.c index 900220b..0ea9f31 100644 --- a/src/debug.c +++ b/src/debug.c @@ -197,6 +197,8 @@ static int isJumpTarget(KrkCodeObject * func, size_t startPoint) { KrkChunk * chunk = &func->chunk; size_t offset = 0; + if (IS_NONE(func->jumpTargets)) { + func->jumpTargets = krk_dict_of(0,NULL,0); #define SIMPLE(opc) case opc: size = 1; break; #define CONSTANT(opc,more) case opc: { size_t constant _unused = chunk->code[offset + 1]; size = 2; more; break; } \ case opc ## _LONG: { size_t constant _unused = (chunk->code[offset + 1] << 16) | \ @@ -205,7 +207,7 @@ static int isJumpTarget(KrkCodeObject * func, size_t startPoint) { #define OPERAND(opc,more) OPERANDB(opc,more) \ case opc ## _LONG: { size = 4; more; break; } #define JUMP(opc,sign) case opc: { uint16_t jump = (chunk->code[offset + 1] << 8) | (chunk->code[offset + 2]); \ - if ((size_t)(offset + 3 sign jump) == startPoint) return 1; \ + krk_tableSet(AS_DICT(func->jumpTargets), INTEGER_VAL((size_t)(offset + 3 sign jump)), BOOLEAN_VAL(1)); \ size = 3; break; } #define CLOSURE_MORE \ KrkCodeObject * function = AS_codeobject(chunk->constants.values[constant]); \ @@ -228,7 +230,6 @@ static int isJumpTarget(KrkCodeObject * func, size_t startPoint) { } offset += size; } - return 0; #undef SIMPLE #undef OPERANDB #undef OPERAND @@ -238,6 +239,12 @@ static int isJumpTarget(KrkCodeObject * func, size_t startPoint) { #undef LOCAL_MORE #undef EXPAND_ARGS_MORE #undef FORMAT_VALUE_MORE + } + + if (!IS_dict(func->jumpTargets)) return 0; + KrkValue garbage; + if (krk_tableGet(AS_DICT(func->jumpTargets), INTEGER_VAL(startPoint), &garbage)) return 1; + return 0; } #define OPARGS FILE * f, const char * fullName, size_t * size, size_t * offset, KrkCodeObject * func, KrkChunk * chunk diff --git a/src/kuroko/object.h b/src/kuroko/object.h index 267efc9..a810ec6 100644 --- a/src/kuroko/object.h +++ b/src/kuroko/object.h @@ -173,6 +173,7 @@ typedef struct { size_t expressionsCapacity; /**< @brief Capacity of @ref expressions */ size_t expressionsCount; /**< @brief Number of entries in @ref expressions */ KrkExpressionsMap * expressions; /**< @brief Mapping of bytecode offsets to expression spans for debugging */ + KrkValue jumpTargets; /**< @brief Possibly a set of jump targets... */ } KrkCodeObject; diff --git a/src/memory.c b/src/memory.c index 15aca63..fc07306 100644 --- a/src/memory.c +++ b/src/memory.c @@ -365,6 +365,7 @@ static void blackenObject(KrkObj * object) { for (size_t i = 0; i < function->localNameCount; ++i) { krk_markObject((KrkObj*)function->localNames[i].name); } + krk_markValue(function->jumpTargets); break; } case KRK_OBJ_UPVALUE: diff --git a/src/object.c b/src/object.c index a9119a4..9092961 100644 --- a/src/object.c +++ b/src/object.c @@ -274,6 +274,7 @@ KrkCodeObject * krk_newCodeObject(void) { krk_initValueArray(&codeobject->positionalArgNames); krk_initValueArray(&codeobject->keywordArgNames); krk_initChunk(&codeobject->chunk); + codeobject->jumpTargets = NONE_VAL(); return codeobject; }