Skip to content

Commit

Permalink
Add PUSH_BUILD_CLASS opcode
Browse files Browse the repository at this point in the history
  • Loading branch information
klange committed Mar 4, 2024
1 parent dae53fa commit 5949a49
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
4 changes: 1 addition & 3 deletions src/compiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -1786,9 +1786,7 @@ static KrkToken classDeclaration(struct GlobalState * state) {

consume(TOKEN_IDENTIFIER, "Expected class name after 'class'.");

KrkToken buildClass = syntheticToken("__build_class__");
size_t ind = identifierConstant(state, &buildClass);
EMIT_OPERAND_OP(OP_GET_GLOBAL, ind);
emitByte(OP_PUSH_BUILD_CLASS);

Compiler subcompiler;
initCompiler(state, &subcompiler, TYPE_CLASS);
Expand Down
1 change: 1 addition & 0 deletions src/methods.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,4 @@ SPECIAL_ATTRS(OCT, "__oct__")
SPECIAL_ATTRS(BIN, "__bin__")
SPECIAL_ATTRS(ABS, "__abs__")
SPECIAL_ATTRS(FUNC, "__func__")
SPECIAL_ATTRS(BLDCLS, "__build_class__")
1 change: 1 addition & 0 deletions src/opcodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,4 @@ OPERAND(OP_UNPACK_EX,NOOP)
JUMP(OP_ENTER_EXCEPT,+)
SIMPLE(OP_SWAP_POP)
COMPLICATED(OP_OVERLONG_JUMP,OVERLONG_JUMP_MORE)
SIMPLE(OP_PUSH_BUILD_CLASS)
7 changes: 7 additions & 0 deletions src/vm.c
Original file line number Diff line number Diff line change
Expand Up @@ -2464,6 +2464,13 @@ _finishReturn: (void)0;
goto _finishException;
}

case OP_PUSH_BUILD_CLASS: {
KrkValue build_class = NONE_VAL();
krk_tableGet_fast(&vm.builtins->fields, AS_STRING(vm.specialMethodNames[METHOD_BLDCLS]), &build_class);
krk_push(build_class);
break;
}

/*
* Two-byte operands
*/
Expand Down

0 comments on commit 5949a49

Please sign in to comment.