Move some special method names to the special method name table
This commit is contained in:
parent
0918776d00
commit
294bd0376b
@ -363,19 +363,19 @@ KRK_Function(chr) {
|
|||||||
|
|
||||||
KRK_Function(hex) {
|
KRK_Function(hex) {
|
||||||
FUNCTION_TAKES_EXACTLY(1);
|
FUNCTION_TAKES_EXACTLY(1);
|
||||||
trySlowMethod(OBJECT_VAL(S("__hex__")));
|
trySlowMethod(vm.specialMethodNames[METHOD_HEX]);
|
||||||
return TYPE_ERROR(int,argv[0]);
|
return TYPE_ERROR(int,argv[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
KRK_Function(oct) {
|
KRK_Function(oct) {
|
||||||
FUNCTION_TAKES_EXACTLY(1);
|
FUNCTION_TAKES_EXACTLY(1);
|
||||||
trySlowMethod(OBJECT_VAL(S("__oct__")));
|
trySlowMethod(vm.specialMethodNames[METHOD_OCT]);
|
||||||
return TYPE_ERROR(int,argv[0]);
|
return TYPE_ERROR(int,argv[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
KRK_Function(bin) {
|
KRK_Function(bin) {
|
||||||
FUNCTION_TAKES_EXACTLY(1);
|
FUNCTION_TAKES_EXACTLY(1);
|
||||||
trySlowMethod(OBJECT_VAL(S("__bin__")));
|
trySlowMethod(vm.specialMethodNames[METHOD_BIN]);
|
||||||
return TYPE_ERROR(int,argv[0]);
|
return TYPE_ERROR(int,argv[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1269,7 +1269,7 @@ KRK_Function(abs) {
|
|||||||
return FLOATING_VAL(i >= 0 ? i : -i);
|
return FLOATING_VAL(i >= 0 ? i : -i);
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} 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]);
|
return krk_runtimeError(vm.exceptions->typeError, "bad operand type for 'abs()': '%T'", argv[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -62,4 +62,8 @@ SPECIAL_ATTRS(CHR, "__chr__")
|
|||||||
SPECIAL_ATTRS(ORD, "__ord__")
|
SPECIAL_ATTRS(ORD, "__ord__")
|
||||||
SPECIAL_ATTRS(FLOAT, "__float__")
|
SPECIAL_ATTRS(FLOAT, "__float__")
|
||||||
SPECIAL_ATTRS(STRSTRIP, " \t\n\r")
|
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__")
|
||||||
|
@ -111,7 +111,7 @@ KRK_Function(dis) {
|
|||||||
}
|
}
|
||||||
} else if (IS_CLASS(funcVal)) {
|
} else if (IS_CLASS(funcVal)) {
|
||||||
KrkValue code;
|
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;
|
KrkCodeObject * func = AS_CLOSURE(code)->function;
|
||||||
krk_disassembleCodeObject(stdout, func, AS_CLASS(funcVal)->name->chars);
|
krk_disassembleCodeObject(stdout, func, AS_CLASS(funcVal)->name->chars);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user