Rearrange class compilation for cleaner line number mappings

This commit is contained in:
K. Lange 2024-03-04 21:40:43 +09:00
parent 5949a4998e
commit 4bd5988e31

View File

@ -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 {