]> git.kaiwu.me - njs.git/commitdiff
Refactored njs_function_lambda_call().
authorhongzhidao <hongzhidao@gmail.com>
Fri, 11 Jan 2019 10:57:57 +0000 (18:57 +0800)
committerhongzhidao <hongzhidao@gmail.com>
Fri, 11 Jan 2019 10:57:57 +0000 (18:57 +0800)
njs/njs_function.c
njs/njs_function.h
njs/njs_vm.c

index 7bb1b94913205247dccdd50739e73e4214606720..8eaab3911c88218cfc67cd52fd490eced0b445dc 100644 (file)
@@ -394,7 +394,8 @@ njs_function_frame_alloc(njs_vm_t *vm, size_t size)
 
 
 nxt_noinline njs_ret_t
-njs_function_lambda_call(njs_vm_t *vm, njs_index_t retval, size_t advance)
+njs_function_lambda_call(njs_vm_t *vm, njs_index_t retval,
+    u_char *return_address)
 {
     size_t                 size;
     njs_ret_t              ret;
@@ -408,9 +409,9 @@ njs_function_lambda_call(njs_vm_t *vm, njs_index_t retval, size_t advance)
     frame = (njs_frame_t *) vm->top_frame;
 
     frame->retval = retval;
+    frame->return_address = return_address;
 
     function = frame->native.function;
-    frame->return_address = vm->current + advance;
 
     lambda = function->u.lambda;
     vm->current = lambda->start;
@@ -947,35 +948,35 @@ njs_function_activate(njs_vm_t *vm, njs_function_t *function,
     const njs_value_t *this, const njs_value_t *args, nxt_uint_t nargs,
     njs_index_t retval, size_t advance)
 {
+    u_char              *return_address;
     njs_ret_t           ret;
     njs_continuation_t  *cont;
 
-    if (function->native) {
-        ret = njs_function_native_frame(vm, function, this, args, nargs,
-                                        NJS_CONTINUATION_SIZE, 0);
-        if (nxt_slow_path(ret != NXT_OK)) {
-            return ret;
-        }
+    ret = njs_function_frame(vm, function, this, args, nargs,
+                             NJS_CONTINUATION_SIZE, 0);
+    if (nxt_slow_path(ret != NXT_OK)) {
+        return ret;
+    }
+
+    return_address = vm->current + advance;
 
+    if (function->native) {
         cont = njs_vm_continuation(vm);
 
         cont->function = function->u.native;
         cont->args_types = function->args_types;
         cont->retval = retval;
+        cont->return_address = return_address;
 
-        cont->return_address = vm->current + advance;
         vm->current = (u_char *) njs_continuation_nexus;
 
-        return NJS_APPLIED;
-    }
-
-    ret = njs_function_lambda_frame(vm, function, this, args, nargs, 0);
+        ret = NJS_APPLIED;
 
-    if (nxt_slow_path(ret != NXT_OK)) {
-        return ret;
+    } else {
+        ret = njs_function_lambda_call(vm, retval, return_address);
     }
 
-    return njs_function_lambda_call(vm, retval, advance);
+    return ret;
 }
 
 
index bf04e295f64a25f867f0977caf7f46f98089e1b2..6b45f482104b898000f06794a665eb45fd35bd59 100644 (file)
@@ -171,7 +171,7 @@ njs_ret_t njs_function_activate(njs_vm_t *vm, njs_function_t *function,
     const njs_value_t *this, const njs_value_t *args, nxt_uint_t nargs,
     njs_index_t retval, size_t advance);
 njs_ret_t njs_function_lambda_call(njs_vm_t *vm, njs_index_t retval,
-    size_t advance);
+    u_char *return_address);
 njs_ret_t njs_function_native_call(njs_vm_t *vm, njs_function_native_t native,
     njs_value_t *args, uint8_t *args_types, nxt_uint_t nargs,
     njs_index_t retval);
index 00f6d47f0f5ddf920658ee3fb909e3df0db29c22..0a5d4faa8a5ce98b53ca555d4337d4684593348c 100644 (file)
@@ -2014,9 +2014,8 @@ njs_vmcode_method_frame(njs_vm_t *vm, njs_value_t *object, njs_value_t *name)
 njs_ret_t
 njs_vmcode_function_call(njs_vm_t *vm, njs_value_t *invld, njs_value_t *retval)
 {
+    u_char              *return_address;
     njs_ret_t           ret;
-    nxt_uint_t          nargs;
-    njs_value_t         *args;
     njs_function_t      *function;
     njs_continuation_t  *cont;
     njs_native_frame_t  *frame;
@@ -2024,37 +2023,33 @@ njs_vmcode_function_call(njs_vm_t *vm, njs_value_t *invld, njs_value_t *retval)
     frame = vm->top_frame;
     function = frame->function;
 
-    if (!function->native) {
-        ret = njs_function_lambda_call(vm, (njs_index_t) retval,
-                                       sizeof(njs_vmcode_function_call_t));
-
-        if (nxt_fast_path(ret != NJS_ERROR)) {
-            return 0;
-        }
+    return_address = vm->current + sizeof(njs_vmcode_function_call_t);
 
-        return ret;
-    }
+    if (function->native) {
+        if (function->continuation_size != 0) {
+            cont = njs_vm_continuation(vm);
 
-    args = frame->arguments;
-    nargs = frame->nargs;
+            cont->function = function->u.native;
+            cont->args_types = function->args_types;
+            cont->retval = (njs_index_t) retval;
+            cont->return_address = return_address;
 
-    if (function->continuation_size != 0) {
-        cont = njs_vm_continuation(vm);
+            vm->current = (u_char *) njs_continuation_nexus;
 
-        cont->function = function->u.native;
-        cont->args_types = function->args_types;
-        cont->retval = (njs_index_t) retval;
+            ret = NJS_APPLIED;
 
-        cont->return_address = vm->current + sizeof(njs_vmcode_function_call_t);
-        vm->current = (u_char *) njs_continuation_nexus;
+        } else {
+            ret = njs_function_native_call(vm, function->u.native,
+                                           frame->arguments,
+                                           function->args_types, frame->nargs,
+                                           (njs_index_t) retval);
+        }
 
-        return 0;
+    } else {
+        ret = njs_function_lambda_call(vm, (njs_index_t) retval,
+                                       return_address);
     }
 
-    ret = njs_function_native_call(vm, function->u.native, args,
-                                   function->args_types, nargs,
-                                   (njs_index_t) retval);
-
     switch (ret) {
     case NXT_OK:
         return sizeof(njs_vmcode_function_call_t);