From 3a02da216122c890c1218fe0c5488bc477e89031 Mon Sep 17 00:00:00 2001 From: Tom Willemse Date: Tue, 17 Aug 2021 20:47:18 -0700 Subject: Chapter 17.7 --- clox/src/common.h | 1 + clox/src/compiler.c | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) 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); -- cgit v1.2.3-54-g00ecf