diff options
author | Tom Willemse | 2021-08-17 20:47:18 -0700 |
---|---|---|
committer | Tom Willemse | 2021-08-17 20:47:18 -0700 |
commit | 3a02da216122c890c1218fe0c5488bc477e89031 (patch) | |
tree | 16322c37b873dad031c819d8867be31eabbf34cc /clox/src | |
parent | 964859a8a135d890019ee31d0a474b90b9b78b4e (diff) | |
download | crafting-interpreters-3a02da216122c890c1218fe0c5488bc477e89031.tar.gz crafting-interpreters-3a02da216122c890c1218fe0c5488bc477e89031.zip |
Chapter 17.7
Diffstat (limited to 'clox/src')
-rw-r--r-- | clox/src/common.h | 1 | ||||
-rw-r--r-- | clox/src/compiler.c | 13 |
2 files changed, 13 insertions, 1 deletions
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 <stddef.h> #include <stdint.h> +#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); |