From 294bd0376b8d448a0dca127a11865f7c547e41fe Mon Sep 17 00:00:00 2001 From: "K. Lange" Date: Sat, 2 Mar 2024 12:20:58 +0900 Subject: [PATCH] Move some special method names to the special method name table --- src/builtins.c | 8 ++++---- src/methods.h | 6 +++++- src/modules/module_dis.c | 2 +- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/builtins.c b/src/builtins.c index 3e930a2..9ca4215 100644 --- a/src/builtins.c +++ b/src/builtins.c @@ -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]); } } diff --git a/src/methods.h b/src/methods.h index 83d2b54..23481be 100644 --- a/src/methods.h +++ b/src/methods.h @@ -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__") diff --git a/src/modules/module_dis.c b/src/modules/module_dis.c index 5eaa043..4a9fb6e 100644 --- a/src/modules/module_dis.c +++ b/src/modules/module_dis.c @@ -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); }