Reorder arguments to callNativeOnStack for better fallthrough to native call

This commit is contained in:
K. Lange 2022-05-29 20:00:41 +09:00
parent d18b08ea46
commit bbf378efe2
5 changed files with 7 additions and 7 deletions

View File

@ -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();

View File

@ -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);

View File

@ -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();

View File

@ -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();

View File

@ -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) { \