]> git.kaiwu.me - njs.git/commitdiff
The "args" has been removed from njs_vmcode_t.
authorIgor Sysoev <igor@sysoev.ru>
Sun, 21 Feb 2016 21:06:59 +0000 (00:06 +0300)
committerIgor Sysoev <igor@sysoev.ru>
Sun, 21 Feb 2016 21:06:59 +0000 (00:06 +0300)
njs/njs_disassembler.c
njs/njs_function.c
njs/njs_function.h
njs/njs_generator.c
njs/njs_parser.c
njs/njs_vm.c
njs/njs_vm.h

index 8667e3ce6e611a8ef95118564942f8ac28ccc1d1..78cc652744af0aab14fd72164c8e2cb137555a26 100644 (file)
@@ -49,6 +49,8 @@ static njs_code_name_t  code_names[] = {
     { njs_vmcode_instance_of, sizeof(njs_vmcode_instance_of_t),
           nxt_string("INSTANCE OF     ") },
 
+    { njs_vmcode_function_call, sizeof(njs_vmcode_function_call_t),
+          nxt_string("FUNCTION CALL   ") },
     { njs_vmcode_return, sizeof(njs_vmcode_return_t),
           nxt_string("RETURN          ") },
     { njs_vmcode_stop, sizeof(njs_vmcode_stop_t),
@@ -176,7 +178,6 @@ njs_disassemble(u_char *start, u_char *end)
     njs_vmcode_equal_jump_t      *equal;
     njs_vmcode_prop_foreach_t    *prop_foreach;
     njs_vmcode_method_frame_t    *method;
-    njs_vmcode_function_call_t   *call;
     njs_vmcode_function_frame_t  *function;
 
     p = start;
@@ -269,8 +270,8 @@ njs_disassemble(u_char *start, u_char *end)
             function = (njs_vmcode_function_frame_t *) p;
             p += sizeof(njs_vmcode_function_frame_t);
 
-            printf("FUNCTION FRAME    %04zX %d%s\n",
-                   (size_t) function->name, function->code.nargs,
+            printf("FUNCTION FRAME    %04zX %zd%s\n",
+                   (size_t) function->name, function->nargs,
                    function->code.ctor ? " CTOR" : "");
 
             continue;
@@ -280,19 +281,9 @@ njs_disassemble(u_char *start, u_char *end)
             method = (njs_vmcode_method_frame_t *) p;
             p += sizeof(njs_vmcode_method_frame_t);
 
-            printf("METHOD FRAME      %04zX %04zX %d\n",
+            printf("METHOD FRAME      %04zX %04zX %zd%s\n",
                    (size_t) method->object, (size_t) method->method,
-                   method->code.nargs);
-
-            continue;
-        }
-
-        if (operation == njs_vmcode_function_call) {
-            call = (njs_vmcode_function_call_t *) p;
-            p += sizeof(njs_vmcode_function_call_t);
-
-            printf("FUNCTION CALL     %04zX %d\n",
-                   (size_t) call->retval, call->code.nargs);
+                   method->nargs, method->code.ctor ? " CTOR" : "");
 
             continue;
         }
index 820bca908f09fb54fb4a02785d043ee247b16248..d0c1e280f18ef1559f8af073d3be2ee5c2abbe4f 100644 (file)
@@ -51,8 +51,6 @@ njs_function_native_frame(njs_vm_t *vm, njs_function_t *function,
     njs_value_t         *value, *bound;
     njs_native_frame_t  *frame;
 
-    nargs--;
-
     reserve = nxt_max(reserve, function->continuation_size);
 
     size = NJS_NATIVE_FRAME_SIZE + reserve
@@ -159,7 +157,7 @@ njs_function_apply(njs_vm_t *vm, njs_function_t *function, njs_value_t *args,
                                  sizeof(njs_value_t)),
 
         ret = njs_function_native_frame(vm, function, &args[0], &args[1],
-                                        nargs, reserve, 0);
+                                        nargs - 1, reserve, 0);
         if (ret != NJS_OK) {
             return ret;
         }
@@ -195,7 +193,7 @@ njs_function_frame(njs_vm_t *vm, njs_function_t *function, njs_value_t *this,
     njs_frame_t         *frame;
     njs_native_frame_t  *native_frame;
 
-    max_args = nxt_max(nargs, function->u.lambda->nargs) - 1;
+    max_args = nxt_max(nargs, function->u.lambda->nargs);
 
     size = NJS_FRAME_SIZE
            + (function->args_offset + max_args) * sizeof(njs_value_t)
@@ -207,7 +205,7 @@ njs_function_frame(njs_vm_t *vm, njs_function_t *function, njs_value_t *this,
     }
 
     native_frame->function = function;
-    native_frame->nargs = function->args_offset + nargs - 1;
+    native_frame->nargs = nargs;
     native_frame->ctor = ctor;
 
     value = (njs_value_t *) ((u_char *) native_frame + NJS_FRAME_SIZE);
@@ -323,14 +321,13 @@ njs_function_prototype_call(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
         return NXT_ERROR;
     }
 
-    this = &args[1];
-    nargs--;
-
-    if (nargs == 0) {
-        this = (njs_value_t *) &njs_value_void;
+    if (nargs > 1) {
+        this = &args[1];
+        nargs -= 2;
 
     } else {
-        nargs--;
+        this = (njs_value_t *) &njs_value_void;
+        nargs = 0;
     }
 
     function = args[0].data.u.function;
@@ -338,7 +335,7 @@ njs_function_prototype_call(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
     if (function->native) {
 
         ret = njs_function_native_frame(vm, function, this, &args[2],
-                                        nargs + 1, 0, 0);
+                                        nargs, 0, 0);
         if (nxt_slow_path(ret != NJS_OK)) {
             return ret;
         }
@@ -397,7 +394,7 @@ njs_function_prototype_apply(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
 
     if (function->native) {
         ret = njs_function_native_frame(vm, function, this, args,
-                                        nargs + 1, 0, 0);
+                                        nargs, 0, 0);
         if (nxt_slow_path(ret != NXT_OK)) {
             return ret;
         }
index 288c26f2470589e80cf038b33a1afc08d11a89a4..cca94b65f4a1a65012f8491574b4405487a9bfaa 100644 (file)
@@ -80,8 +80,7 @@ struct njs_native_frame_s {
     njs_exception_t                exception;
 
     uint32_t                       free_size;
-
-    uint16_t                       nargs;
+    uint32_t                       nargs;
 
     /* Function is called as constructor with "new" keyword. */
     uint8_t                        ctor;              /* 1 bit  */
index d67fe3f370f8f822dfa0d8f9d8221c601921ed4f..5d565d653733870356642a3f5d93ae0ffc66161f 100644 (file)
@@ -1979,7 +1979,7 @@ njs_generate_function_call(njs_vm_t *vm, njs_parser_t *parser,
 
     njs_generate_code(parser, njs_vmcode_function_frame_t, func);
     func->code.operation = njs_vmcode_function_frame;
-    func->code.operands = NJS_VMCODE_1OPERAND;
+    func->code.operands = NJS_VMCODE_2OPERANDS;
     func->code.retval = NJS_VMCODE_NO_RETVAL;
     func->code.ctor = node->ctor;
     func->name = name->index;
@@ -1989,7 +1989,7 @@ njs_generate_function_call(njs_vm_t *vm, njs_parser_t *parser,
         return ret;
     }
 
-    nargs = 1;
+    nargs = 0;
 
     for (arg = node->right; arg != NULL; arg = arg->right) {
         nargs++;
@@ -2009,7 +2009,7 @@ njs_generate_function_call(njs_vm_t *vm, njs_parser_t *parser,
         }
     }
 
-    func->code.nargs = nargs;
+    func->nargs = nargs;
 
     retval = njs_generator_dest_index(vm, parser, node);
     if (nxt_slow_path(retval == NJS_INDEX_ERROR)) {
@@ -2022,7 +2022,6 @@ njs_generate_function_call(njs_vm_t *vm, njs_parser_t *parser,
     call->code.operation = njs_vmcode_function_call;
     call->code.operands = NJS_VMCODE_1OPERAND;
     call->code.retval = NJS_VMCODE_NO_RETVAL;
-    call->code.nargs = nargs;
     call->retval = retval;
 
     return NXT_OK;
@@ -2059,7 +2058,7 @@ njs_generate_method_call(njs_vm_t *vm, njs_parser_t *parser,
 
     njs_generate_code(parser, njs_vmcode_method_frame_t, method);
     method->code.operation = njs_vmcode_method_frame;
-    method->code.operands = NJS_VMCODE_2OPERANDS;
+    method->code.operands = NJS_VMCODE_3OPERANDS;
     method->code.retval = NJS_VMCODE_NO_RETVAL;
     method->code.ctor = node->ctor;
     method->object = prop->left->index;
@@ -2070,7 +2069,7 @@ njs_generate_method_call(njs_vm_t *vm, njs_parser_t *parser,
         return ret;
     }
 
-    nargs = 1;
+    nargs = 0;
 
     for (arg = node->right; arg != NULL; arg = arg->right) {
         nargs++;
@@ -2090,7 +2089,7 @@ njs_generate_method_call(njs_vm_t *vm, njs_parser_t *parser,
         }
     }
 
-    method->code.nargs = nargs;
+    method->nargs = nargs;
 
     retval = njs_generator_dest_index(vm, parser, node);
     if (nxt_slow_path(retval == NJS_INDEX_ERROR)) {
@@ -2103,7 +2102,6 @@ njs_generate_method_call(njs_vm_t *vm, njs_parser_t *parser,
     call->code.operation = njs_vmcode_function_call;
     call->code.operands = NJS_VMCODE_1OPERAND;
     call->code.retval = NJS_VMCODE_NO_RETVAL;
-    call->code.nargs = nargs;
     call->retval = retval;
 
     return NXT_OK;
index c7c61681057380792b48cca8a974238cec795a26..69c62e541f2c73f65a7d30992d6d586a60f7400e 100644 (file)
@@ -499,7 +499,7 @@ njs_parser_function_lambda(njs_vm_t *vm, njs_function_lambda_t *lambda,
         }
     }
 
-    lambda->nargs = njs_index_size(index) / sizeof(njs_value_t);
+    lambda->nargs = njs_index_size(index) / sizeof(njs_value_t) - 1;
 
     token = njs_parser_token(parser);
     if (nxt_slow_path(token <= NJS_TOKEN_ILLEGAL)) {
index 852cd24274a921d546245fa7479742c331550797..543328c94a0621a2dcaace9c0cc104c9602e9999 100644 (file)
@@ -173,7 +173,6 @@ njs_vmcode_interpreter(njs_vm_t *vm)
              *   njs_vmcode_if_false_jump(),
              *   njs_vmcode_validate(),
              *   njs_vmcode_function_frame(),
-             *   njs_vmcode_method_frame(),
              *   njs_vmcode_function_call(),
              *   njs_vmcode_return(),
              *   njs_vmcode_try_start(),
@@ -2084,16 +2083,14 @@ njs_vmcode_if_equal_jump(njs_vm_t *vm, njs_value_t *val1, njs_value_t *val2)
 
 
 njs_ret_t
-njs_vmcode_function_frame(njs_vm_t *vm, njs_value_t *invld, njs_value_t *name)
+njs_vmcode_function_frame(njs_vm_t *vm, njs_value_t *value, njs_value_t *nargs)
 {
     njs_ret_t                    ret;
-    njs_value_t                  val, *this, *value;
+    njs_value_t                  val, *this;
     njs_object_t                 *object;
     njs_function_t               *function;
     njs_vmcode_function_frame_t  *func;
 
-    value = njs_vmcode_operand(vm, name);
-
     if (nxt_fast_path(njs_is_function(value))) {
 
         func = (njs_vmcode_function_frame_t *) vm->current;
@@ -2102,7 +2099,7 @@ njs_vmcode_function_frame(njs_vm_t *vm, njs_value_t *invld, njs_value_t *name)
 
         if (function->native) {
             ret = njs_function_native_frame(vm, function, &njs_value_void,
-                                            NULL, func->code.nargs, 0,
+                                            NULL, (uintptr_t) nargs, 0,
                                             func->code.ctor);
 
             if (nxt_fast_path(ret == NXT_OK)) {
@@ -2128,7 +2125,7 @@ njs_vmcode_function_frame(njs_vm_t *vm, njs_value_t *invld, njs_value_t *name)
             this = (njs_value_t *) &njs_value_void;
         }
 
-        ret = njs_function_frame(vm, function, this, NULL, func->code.nargs,
+        ret = njs_function_frame(vm, function, this, NULL, (uintptr_t) nargs,
                                  func->code.ctor);
 
         if (nxt_fast_path(ret == NXT_OK)) {
@@ -2145,7 +2142,7 @@ njs_vmcode_function_frame(njs_vm_t *vm, njs_value_t *invld, njs_value_t *name)
 
 
 njs_ret_t
-njs_vmcode_method_frame(njs_vm_t *vm, njs_value_t *name, njs_value_t *object)
+njs_vmcode_method_frame(njs_vm_t *vm, njs_value_t *object, njs_value_t *name)
 {
     njs_ret_t                  ret;
     njs_value_t                this;
@@ -2155,8 +2152,6 @@ njs_vmcode_method_frame(njs_vm_t *vm, njs_value_t *name, njs_value_t *object)
     njs_property_query_t       pq;
     njs_vmcode_method_frame_t  *method;
 
-    object = njs_vmcode_operand(vm, object);
-
     pq.query = NJS_PROPERTY_QUERY_GET;
 
     switch (njs_property_query(vm, &pq, object, name)) {
@@ -2171,7 +2166,7 @@ njs_vmcode_method_frame(njs_vm_t *vm, njs_value_t *name, njs_value_t *object)
 
             if (!function->native) {
                 ret = njs_function_frame(vm, function, object, NULL,
-                                         method->code.nargs, method->code.ctor);
+                                         method->nargs, method->code.ctor);
 
                 if (nxt_fast_path(ret == NXT_OK)) {
                     return sizeof(njs_vmcode_method_frame_t);
@@ -2181,7 +2176,7 @@ njs_vmcode_method_frame(njs_vm_t *vm, njs_value_t *name, njs_value_t *object)
             }
 
             ret = njs_function_native_frame(vm, function, object, NULL,
-                                            method->code.nargs, 0,
+                                            method->nargs, 0,
                                             method->code.ctor);
 
             if (nxt_fast_path(ret == NXT_OK)) {
@@ -2207,7 +2202,7 @@ njs_vmcode_method_frame(njs_vm_t *vm, njs_value_t *name, njs_value_t *object)
                 this.data.u.data = vm->external[ext->object];
 
                 ret = njs_function_native_frame(vm, ext->function, &this, NULL,
-                                                method->code.nargs, 0,
+                                                method->nargs, 0,
                                                 method->code.ctor);
 
                 if (nxt_fast_path(ret == NXT_OK)) {
index f7c45a299a5c611e9a7390ba30296d9325780916..6bc9fbeddc1079d1a8b566cc7fca971d668f0323 100644 (file)
 
 /*
  * Negative return values handled by nJSVM interpreter as special events.
- * The values must be in range from -1 to -15, because -16 is minimal jump
+ * The values must be in range from -1 to -11, because -12 is minimal jump
  * offset on 32-bit platforms.
  *    -1 (NJS_ERROR/NXT_ERROR):  error or exception;
  *    -2 (NJS_AGAIN/NXT_AGAIN):  postpone nJSVM execution;
  *    -3:                        not used;
  *    -4 (NJS_STOP/NXT_DONE):    njs_vmcode_stop() has stopped execution,
  *                               execution has completed successfully;
- *    -5 .. -11:                 traps to convert objects to primitive values;
- *   -12 .. -15:                 not used.
+ *    -5 .. -11:                 traps to convert objects to primitive values.
  */
 
 #define NJS_STOP                 NXT_DONE
@@ -33,7 +32,7 @@
 #define NJS_TRAP_STRING_ARG      (-11)
 #define NJS_TRAP_BASE            NJS_TRAP_STRING_ARG
 
-#define NJS_PREEMPT              (-15)
+#define NJS_PREEMPT              (-11)
 
 /*
  * A user-defined function is prepared to run.  This code is never
@@ -402,13 +401,8 @@ typedef njs_ret_t (*njs_vmcode_operation_t)(njs_vm_t *vm, njs_value_t *value1,
 typedef struct {
     njs_vmcode_operation_t     operation;
     uint8_t                    operands;   /* 2 bits */
-    uint8_t                    retval;   /* 1 bit  */
-    uint8_t                    ctor;     /* 1 bit  */
-#if (NXT_64BIT)
-    uint32_t                   nargs;
-#else
-    uint16_t                   nargs;
-#endif
+    uint8_t                    retval;     /* 1 bit  */
+    uint8_t                    ctor;       /* 1 bit  */
 } njs_vmcode_t;
 
 
@@ -553,12 +547,14 @@ typedef struct {
 
 typedef struct {
     njs_vmcode_t               code;
+    njs_index_t                nargs;
     njs_index_t                name;
 } njs_vmcode_function_frame_t;
 
 
 typedef struct {
     njs_vmcode_t               code;
+    njs_index_t                nargs;
     njs_index_t                object;
     njs_index_t                method;
 } njs_vmcode_method_frame_t;
@@ -881,8 +877,8 @@ njs_ret_t njs_vmcode_if_false_jump(njs_vm_t *vm, njs_value_t *cond,
 njs_ret_t njs_vmcode_if_equal_jump(njs_vm_t *vm, njs_value_t *val1,
     njs_value_t *val2);
 
-njs_ret_t njs_vmcode_function_frame(njs_vm_t *vm, njs_value_t *invld,
-    njs_value_t *name);
+njs_ret_t njs_vmcode_function_frame(njs_vm_t *vm, njs_value_t *value,
+    njs_value_t *nargs);
 njs_ret_t njs_vmcode_method_frame(njs_vm_t *vm, njs_value_t *object,
     njs_value_t *method);
 njs_ret_t njs_vmcode_function_call(njs_vm_t *vm, njs_value_t *invld,