Move some special method names to the special method name table

This commit is contained in:
K. Lange 2024-03-02 12:20:58 +09:00
parent 0918776d00
commit 294bd0376b
3 changed files with 10 additions and 6 deletions

View File

@ -363,19 +363,19 @@ KRK_Function(chr) {
KRK_Function(hex) {
FUNCTION_TAKES_EXACTLY(1);
trySlowMethod(OBJECT_VAL(S("__hex__")));
trySlowMethod(vm.specialMethodNames[METHOD_HEX]);
return TYPE_ERROR(int,argv[0]);
}
KRK_Function(oct) {
FUNCTION_TAKES_EXACTLY(1);
trySlowMethod(OBJECT_VAL(S("__oct__")));
trySlowMethod(vm.specialMethodNames[METHOD_OCT]);
return TYPE_ERROR(int,argv[0]);
}
KRK_Function(bin) {
FUNCTION_TAKES_EXACTLY(1);
trySlowMethod(OBJECT_VAL(S("__bin__")));
trySlowMethod(vm.specialMethodNames[METHOD_BIN]);
return TYPE_ERROR(int,argv[0]);
}
@ -1269,7 +1269,7 @@ KRK_Function(abs) {
return FLOATING_VAL(i >= 0 ? i : -i);
#endif
} else {
trySlowMethod(OBJECT_VAL(S("__abs__")));
trySlowMethod(vm.specialMethodNames[METHOD_ABS]);
return krk_runtimeError(vm.exceptions->typeError, "bad operand type for 'abs()': '%T'", argv[0]);
}
}

View File

@ -62,4 +62,8 @@ SPECIAL_ATTRS(CHR, "__chr__")
SPECIAL_ATTRS(ORD, "__ord__")
SPECIAL_ATTRS(FLOAT, "__float__")
SPECIAL_ATTRS(STRSTRIP, " \t\n\r")
SPECIAL_ATTRS(HEX, "__hex__")
SPECIAL_ATTRS(OCT, "__oct__")
SPECIAL_ATTRS(BIN, "__bin__")
SPECIAL_ATTRS(ABS, "__abs__")
SPECIAL_ATTRS(FUNC, "__func__")

View File

@ -111,7 +111,7 @@ KRK_Function(dis) {
}
} else if (IS_CLASS(funcVal)) {
KrkValue code;
if (krk_tableGet(&AS_CLASS(funcVal)->methods, OBJECT_VAL(S("__func__")), &code) && IS_CLOSURE(code)) {
if (krk_tableGet(&AS_CLASS(funcVal)->methods, vm.specialMethodNames[METHOD_FUNC], &code) && IS_CLOSURE(code)) {
KrkCodeObject * func = AS_CLOSURE(code)->function;
krk_disassembleCodeObject(stdout, func, AS_CLASS(funcVal)->name->chars);
}