Skip to content

Commit

Permalink
Rearrange class compilation for cleaner line number mappings
Browse files Browse the repository at this point in the history
  • Loading branch information
klange committed Mar 4, 2024
1 parent 5949a49 commit 4bd5988
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/compiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -1863,18 +1863,19 @@ static KrkToken classDeclaration(struct GlobalState * state) {
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 {
Expand Down

0 comments on commit 4bd5988

Please sign in to comment.