From 4bd5988e310d5596b558cde6553bfc12d4f9b972 Mon Sep 17 00:00:00 2001 From: "K. Lange" Date: Mon, 4 Mar 2024 21:40:43 +0900 Subject: [PATCH] Rearrange class compilation for cleaner line number mappings --- src/compiler.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/compiler.c b/src/compiler.c index f575991..697b657 100644 --- a/src/compiler.c +++ b/src/compiler.c @@ -1863,18 +1863,19 @@ _pop_class: state->currentClass = state->currentClass->enclosing; KrkCodeObject * makeclass = endCompiler(state); size_t indFunc = krk_addConstant(currentChunk(), OBJECT_VAL(makeclass)); - EMIT_OPERAND_OP(OP_CLOSURE, indFunc); - doUpvalues(state, &subcompiler, makeclass); - freeCompiler(&subcompiler); RewindState afterFunction = {recordChunk(currentChunk()), krk_tellScanner(&state->scanner), state->parser}; size_t nameInd = nonidentifierTokenConstant(state, &classNameToken); - EMIT_OPERAND_OP(OP_CONSTANT, nameInd); krk_rewindScanner(&state->scanner, parameters.oldScanner); state->parser = parameters.oldParser; + EMIT_OPERAND_OP(OP_CLOSURE, indFunc); + doUpvalues(state, &subcompiler, makeclass); + freeCompiler(&subcompiler); + EMIT_OPERAND_OP(OP_CONSTANT, nameInd); + if (match(TOKEN_LEFT_PAREN)) { call(state, EXPR_CLASS_PARAMETERS, NULL); } else {