diff --git a/clox/src/common.h b/clox/src/common.h index ddab699..25fc22f 100644 --- a/clox/src/common.h +++ b/clox/src/common.h @@ -5,6 +5,7 @@ #include #include +#define DEBUG_PRINT_CODE #define DEBUG_TRACE_EXECUTION #endif diff --git a/clox/src/compiler.c b/clox/src/compiler.c index 578af94..75df7aa 100644 --- a/clox/src/compiler.c +++ b/clox/src/compiler.c @@ -5,6 +5,10 @@ #include "compiler.h" #include "scanner.h" +#ifdef DEBUG_PRINT_CODE +#include "debug.h" +#endif + typedef struct { Token current; Token previous; @@ -109,7 +113,14 @@ static void emitConstant(Value value) { emitBytes(OP_CONSTANT, makeConstant(value)); } -static void endCompiler() { emitReturn(); } +static void endCompiler() { + emitReturn(); +#ifdef DEBUG_PRINT_CODE + if (!parser.hadError) { + disassembleChunk(currentChunk(), "code"); + } +#endif +} static void expression(); static ParseRule *getRule(TokenType type);