diff --git a/main.c b/main.c index afb43b6..007a025 100644 --- a/main.c +++ b/main.c @@ -50,6 +50,7 @@ static bool interpret(CState *state, const char *script, const char *mod) // cosmoV_compileString pushes the result onto the stack (COBJ_ERROR or COBJ_CLOSURE) if (cosmoV_compileString(state, script, mod)) { + cosmoG_disassemble(cosmoV_readClosure(*cosmoV_getTop(state, 0))); if (!cosmoV_pcall(state, 0, 1)) { cosmoV_printBacktrace(state, cosmoV_readError(*cosmoV_pop(state))); return false; diff --git a/src/cdebug.c b/src/cdebug.c index 27748cd..c870aa2 100644 --- a/src/cdebug.c +++ b/src/cdebug.c @@ -223,3 +223,8 @@ int disasmInstr(CChunk *chunk, int offset, int indent) return 1; } + +void cosmoG_disassemble(CObjClosure *closure) +{ + disasmChunk(&closure->function->chunk, closure->function->name == NULL ? UNNAMEDCHUNK : closure->function->name->str, 0); +} \ No newline at end of file diff --git a/src/cdebug.h b/src/cdebug.h index d869f7f..9877bc2 100644 --- a/src/cdebug.h +++ b/src/cdebug.h @@ -2,10 +2,13 @@ #define CDEBUG_H #include "cchunk.h" +#include "cobj.h" COSMO_API void disasmChunk(CChunk *chunk, const char *name, int indent); COSMO_API int disasmInstr(CChunk *chunk, int offset, int indent); void printIndent(int indent); +COSMO_API void cosmoG_disassemble(CObjClosure *closure); + #endif