From bbf378efe2fa8c710472c6f2a123efe50a2ad6d3 Mon Sep 17 00:00:00 2001 From: "K. Lange" Date: Sun, 29 May 2022 20:00:41 +0900 Subject: [PATCH] Reorder arguments to callNativeOnStack for better fallthrough to native call --- src/kuroko.c | 2 +- src/kuroko/vm.h | 2 +- src/obj_list.c | 2 +- src/obj_tuple.c | 2 +- src/vm.c | 6 +++--- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/kuroko.c b/src/kuroko.c index 3af32fd..2099e73 100644 --- a/src/kuroko.c +++ b/src/kuroko.c @@ -883,7 +883,7 @@ _finishArgs: for (int arg = optind; arg < argc; ++arg) { krk_push(OBJECT_VAL(krk_copyString(argv[arg],strlen(argv[arg])))); } - KrkValue argList = krk_callNativeOnStack(krk_list_of, argc - optind + (optind == argc), &krk_currentThread.stackTop[-(argc - optind + (optind == argc))], 0); + KrkValue argList = krk_callNativeOnStack(argc - optind + (optind == argc), &krk_currentThread.stackTop[-(argc - optind + (optind == argc))], 0, krk_list_of); krk_push(argList); krk_attachNamedValue(&vm.system->fields, "argv", argList); krk_pop(); diff --git a/src/kuroko/vm.h b/src/kuroko/vm.h index d89df59..060e59c 100644 --- a/src/kuroko/vm.h +++ b/src/kuroko/vm.h @@ -860,4 +860,4 @@ extern void krk_setMaximumRecursionDepth(size_t maxDepth); * held stack is reallocated, it will be freed when execution returns to the call * to @c krk_callNativeOnStack that holds it. */ -KrkValue krk_callNativeOnStack(NativeFn native, size_t argCount, const KrkValue *stackArgs, int hasKw); +KrkValue krk_callNativeOnStack(size_t argCount, const KrkValue *stackArgs, int hasKw, NativeFn native); diff --git a/src/obj_list.c b/src/obj_list.c index 4d6b3dd..efe8503 100644 --- a/src/obj_list.c +++ b/src/obj_list.c @@ -81,7 +81,7 @@ KRK_METHOD(list,__getitem__,{ } /* make into a list */ - KrkValue result = krk_callNativeOnStack(krk_list_of, len, &krk_currentThread.stackTop[-len], 0); + KrkValue result = krk_callNativeOnStack(len, &krk_currentThread.stackTop[-len], 0, krk_list_of); krk_currentThread.stackTop[-len-1] = result; while (len) { krk_pop(); diff --git a/src/obj_tuple.c b/src/obj_tuple.c index cc7c3a7..920b2bf 100644 --- a/src/obj_tuple.c +++ b/src/obj_tuple.c @@ -87,7 +87,7 @@ KRK_METHOD(tuple,__getitem__,{ } /* make into a list */ - KrkValue result = krk_callNativeOnStack(krk_tuple_of, len, &krk_currentThread.stackTop[-len], 0); + KrkValue result = krk_callNativeOnStack(len, &krk_currentThread.stackTop[-len], 0, krk_tuple_of); krk_currentThread.stackTop[-len-1] = result; while (len) { krk_pop(); diff --git a/src/vm.c b/src/vm.c index 03cb580..08e8dec 100644 --- a/src/vm.c +++ b/src/vm.c @@ -790,7 +790,7 @@ _errorAfterKeywords: * If the stack is reallocated within this call, the old stack will not be freed until * all such nested calls through krk_callNativeOnStack have returned. */ -KrkValue krk_callNativeOnStack(NativeFn native, size_t argCount, const KrkValue *stackArgs, int hasKw) { +inline KrkValue krk_callNativeOnStack(size_t argCount, const KrkValue *stackArgs, int hasKw, NativeFn native) { /** * If someone is already preserving this stack, we can just call directly. @@ -861,7 +861,7 @@ int krk_callValue(KrkValue callee, int argCount, int returnDepth) { krk_pop(); krk_push(result); } else { - KrkValue result = krk_callNativeOnStack(native, argCount, krk_currentThread.stackTop - argCount, 0); + KrkValue result = krk_callNativeOnStack(argCount, krk_currentThread.stackTop - argCount, 0, native); if (unlikely(krk_currentThread.stackTop == krk_currentThread.stack)) return 0; krk_currentThread.stackTop -= argCount + returnDepth; krk_push(result); @@ -3170,7 +3170,7 @@ _finishReturn: (void)0; } #define doMake(func) { \ size_t count = OPERAND; \ - KrkValue collection = krk_callNativeOnStack(func, count, &krk_currentThread.stackTop[-count], 0); \ + KrkValue collection = krk_callNativeOnStack(count, &krk_currentThread.stackTop[-count], 0, func); \ if (count) { \ krk_currentThread.stackTop[-count] = collection; \ while (count > 1) { \