]> git.kaiwu.me - njs.git/commitdiff
Getting rid of excessive NJS_LEVEL_TEMP.
authorDmitry Volyntsev <xeioex@nginx.com>
Wed, 18 May 2022 07:01:05 +0000 (00:01 -0700)
committerDmitry Volyntsev <xeioex@nginx.com>
Wed, 18 May 2022 07:01:05 +0000 (00:01 -0700)
src/njs_async.c
src/njs_function.c
src/njs_function.h
src/njs_generator.c
src/njs_parser.c
src/njs_parser.h
src/njs_scope.c
src/njs_vm.c
src/njs_vm.h

index e4dd74863e3fbc3695b2a82a5265c5816eed528d..e018bd8b643da682b9f6d0ccf8d2999ae759cf93 100644 (file)
@@ -59,7 +59,7 @@ njs_await_fulfilled(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
     njs_index_t unused)
 {
     njs_int_t           ret;
-    njs_value_t         **cur_local, **cur_closures, **cur_temp, *value;
+    njs_value_t         **cur_local, **cur_closures, *value;
     njs_frame_t         *frame, *async_frame;
     njs_async_ctx_t     *ctx;
     njs_native_frame_t  *top, *async;
@@ -77,13 +77,11 @@ njs_await_fulfilled(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
 
     cur_local = vm->levels[NJS_LEVEL_LOCAL];
     cur_closures = vm->levels[NJS_LEVEL_CLOSURE];
-    cur_temp = vm->levels[NJS_LEVEL_TEMP];
     top = vm->top_frame;
     frame = vm->active_frame;
 
     vm->levels[NJS_LEVEL_LOCAL] = async->local;
     vm->levels[NJS_LEVEL_CLOSURE] = njs_function_closures(async->function);
-    vm->levels[NJS_LEVEL_TEMP] = async->temp;
 
     vm->top_frame = async;
     vm->active_frame = async_frame;
@@ -97,7 +95,6 @@ njs_await_fulfilled(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
 
     vm->levels[NJS_LEVEL_LOCAL] = cur_local;
     vm->levels[NJS_LEVEL_CLOSURE] = cur_closures;
-    vm->levels[NJS_LEVEL_TEMP] = cur_temp;
 
     vm->top_frame = top;
     vm->active_frame = frame;
index 78857e01e50fa93dd7194ca326e56b8d0c1c6e89..a89476d0b0543780bbed13cace24f6f2a2cc91ed 100644 (file)
@@ -424,8 +424,8 @@ njs_function_lambda_frame(njs_vm_t *vm, njs_function_t *function,
     njs_bool_t ctor)
 {
     size_t                 n, frame_size;
-    uint32_t               args_count, value_count, value_size, temp_size;
-    njs_value_t            *value, *bound, **new, **temp;
+    uint32_t               args_count, value_count, value_size;
+    njs_value_t            *value, *bound, **new;
     njs_frame_t            *frame;
     njs_function_t         *target;
     njs_native_frame_t     *native_frame;
@@ -458,10 +458,8 @@ njs_function_lambda_frame(njs_vm_t *vm, njs_function_t *function,
     value_count = args_count + njs_max(args_count, lambda->nlocal);
 
     value_size = value_count * sizeof(njs_value_t *);
-    temp_size = lambda->temp * sizeof(njs_value_t *);
 
-    frame_size = value_size + temp_size
-                        + ((value_count + lambda->temp) * sizeof(njs_value_t));
+    frame_size = value_size + (value_count * sizeof(njs_value_t));
 
     native_frame = njs_function_frame_alloc(vm, NJS_FRAME_SIZE + frame_size);
     if (njs_slow_path(native_frame == NULL)) {
@@ -471,9 +469,9 @@ njs_function_lambda_frame(njs_vm_t *vm, njs_function_t *function,
     /* Local */
 
     new = (njs_value_t **) ((u_char *) native_frame + NJS_FRAME_SIZE);
-    value = (njs_value_t *) ((u_char *) new + value_size + temp_size);
+    value = (njs_value_t *) ((u_char *) new + value_size);
 
-    n = value_count + lambda->temp;
+    n = value_count;
 
     while (n != 0) {
         n--;
@@ -481,15 +479,9 @@ njs_function_lambda_frame(njs_vm_t *vm, njs_function_t *function,
         njs_set_invalid(new[n]);
     }
 
-    /* Temp */
-
-    temp = (njs_value_t **) ((u_char *) native_frame + NJS_FRAME_SIZE
-                                                     + value_size);
-
     native_frame->arguments = value;
     native_frame->arguments_offset = value + (function->args_offset - 1);
     native_frame->local = new + args_count;
-    native_frame->temp = temp;
     native_frame->function = target;
     native_frame->nargs = nargs;
     native_frame->ctor = ctor;
@@ -614,7 +606,7 @@ njs_function_lambda_call(njs_vm_t *vm, void *promise_cap, void *async_ctx)
     njs_int_t              ret;
     njs_frame_t            *frame;
     njs_value_t            *args, **local, *value;
-    njs_value_t            **cur_local, **cur_closures, **cur_temp;
+    njs_value_t            **cur_local, **cur_closures;
     njs_function_t         *function;
     njs_declaration_t      *declr;
     njs_function_lambda_t  *lambda;
@@ -650,13 +642,11 @@ njs_function_lambda_call(njs_vm_t *vm, void *promise_cap, void *async_ctx)
 
     cur_local = vm->levels[NJS_LEVEL_LOCAL];
     cur_closures = vm->levels[NJS_LEVEL_CLOSURE];
-    cur_temp = vm->levels[NJS_LEVEL_TEMP];
 
     /* Replace current level. */
 
     vm->levels[NJS_LEVEL_LOCAL] = vm->top_frame->local;
     vm->levels[NJS_LEVEL_CLOSURE] = njs_function_closures(function);
-    vm->levels[NJS_LEVEL_TEMP] = frame->native.temp;
 
     if (lambda->rest_parameters) {
         ret = njs_function_rest_parameters_init(vm, &frame->native);
@@ -705,7 +695,6 @@ njs_function_lambda_call(njs_vm_t *vm, void *promise_cap, void *async_ctx)
     /* Restore current level. */
     vm->levels[NJS_LEVEL_LOCAL] = cur_local;
     vm->levels[NJS_LEVEL_CLOSURE] = cur_closures;
-    vm->levels[NJS_LEVEL_TEMP] = cur_temp;
 
     return ret;
 }
@@ -805,9 +794,10 @@ njs_function_frame_free(njs_vm_t *vm, njs_native_frame_t *native)
 njs_int_t
 njs_function_frame_save(njs_vm_t *vm, njs_frame_t *frame, u_char *pc)
 {
-    size_t              value_count, n;
+    size_t              args_count, value_count, n;
     njs_value_t         *start, *end, *p, **new, *value, **local;
     njs_function_t      *function;
+    njs_function_lambda_t  *lambda;
     njs_native_frame_t  *active, *native;
 
     *frame = *vm->active_frame;
@@ -820,19 +810,18 @@ njs_function_frame_save(njs_vm_t *vm, njs_frame_t *frame, u_char *pc)
     native->free_size = 0;
 
     active = &vm->active_frame->native;
-    value_count = njs_function_frame_value_count(active);
-
     function = active->function;
+    lambda = function->u.lambda;
 
-    new = (njs_value_t **) ((u_char *) native + NJS_FRAME_SIZE);
-    value = (njs_value_t *) (new + value_count
-                             + function->u.lambda->temp);
+    args_count = function->args_offset + njs_max(native->nargs, lambda->nargs);
+    value_count = args_count + njs_max(args_count, lambda->nlocal);
 
+    new = (njs_value_t **) ((u_char *) native + NJS_FRAME_SIZE);
+    value = (njs_value_t *) (new + value_count);
 
     native->arguments = value;
     native->arguments_offset = value + (function->args_offset - 1);
     native->local = new + njs_function_frame_args_count(active);
-    native->temp = new + value_count;
     native->pc = pc;
 
     start = njs_function_frame_values(active, &end);
index 59150fdd5c94ec08871615e9f034daaf010e9273..ee9a03124bb17c0bd04aa4e8e399f981bb2b4f7e 100644 (file)
@@ -12,7 +12,6 @@ struct njs_function_lambda_s {
     njs_index_t                    *closures;
     uint32_t                       nclosures;
     uint32_t                       nlocal;
-    uint32_t                       temp;
 
     njs_declaration_t              *declarations;
     uint32_t                       ndeclarations;
@@ -50,7 +49,6 @@ struct njs_native_frame_s {
     njs_object_t                   *arguments_object;
     njs_value_t                    *arguments_offset;
     njs_value_t                    **local;
-    njs_value_t                    **temp;
 
     uint32_t                       size;
     uint32_t                       free_size;
@@ -229,17 +227,6 @@ njs_function_frame_args_count(njs_native_frame_t *frame)
 }
 
 
-njs_inline size_t
-njs_function_frame_value_count(njs_native_frame_t *frame)
-{
-    uintptr_t  start;
-
-    start = (uintptr_t) ((u_char *) frame + NJS_FRAME_SIZE);
-
-    return ((uintptr_t) frame->temp - start) / sizeof(njs_value_t *);
-}
-
-
 njs_inline njs_value_t *
 njs_function_frame_values(njs_native_frame_t *frame, njs_value_t **end)
 {
index de58a47e119aeeb517ad8ad89d385b857df164c1..db108929f9eb55cb293f5b5ce8d0f2e4dcd96cb8 100644 (file)
@@ -3698,7 +3698,6 @@ njs_generate_function_scope(njs_vm_t *vm, njs_generator_t *prev,
     lambda->closures = generator.closures->start;
     lambda->nclosures = generator.closures->items;
     lambda->nlocal = node->scope->items;
-    lambda->temp = node->scope->temp;
 
     arr = node->scope->declarations;
     lambda->declarations = (arr != NULL) ? arr->start : NULL;
@@ -4916,7 +4915,7 @@ njs_generate_temp_index_get(njs_vm_t *vm, njs_generator_t *generator,
         return NJS_ERROR;
     }
 
-    return njs_scope_index(scope->type, scope->temp++, NJS_LEVEL_TEMP,
+    return njs_scope_index(scope->type, scope->items++, NJS_LEVEL_LOCAL,
                            NJS_VARIABLE_VAR);
 }
 
index f4c805aa4ee83942c04d7e8dc81526be31de860d..92a05a428a1d14e0241edfadbbdf1dd9d48bbe88 100644 (file)
@@ -562,7 +562,6 @@ njs_parser(njs_vm_t *vm, njs_parser_t *parser)
         }
 
     } else {
-        parser->scope->temp = 0;
         parser->scope->top = NULL;
         parser->node = NULL;
         parser->ret = NJS_OK;
@@ -1357,6 +1356,8 @@ njs_parser_template_literal(njs_parser_t *parser, njs_lexer_token_t *token,
             return NJS_ERROR;
         }
 
+        node->temporary = 1;
+
         template->right = node;
         temp->right = node;
 
@@ -1370,6 +1371,7 @@ njs_parser_template_literal(njs_parser_t *parser, njs_lexer_token_t *token,
         temp->right = template;
     }
 
+    temp->temporary = 1;
     temp->left = template;
     temp->index = index;
 
index d4d188de8068e1c87fbf151de054e766a2d13175..2d343260d217acfaef2fd46d7abf1d166096be4d 100644 (file)
@@ -20,7 +20,6 @@ struct njs_parser_scope_s {
     njs_arr_t                       *closures;
     njs_arr_t                       *declarations;
 
-    uint32_t                        temp;
     uint32_t                        items;
 
     njs_scope_t                     type:8;
index 5e3e3754b585a29cdac120a5ec33c3ea526314e8..c475750aa4c96804acf4bcbe6340c0aac213c73c 100644 (file)
@@ -20,7 +20,7 @@ njs_scope_temp_index(njs_parser_scope_t *scope)
         return NJS_INDEX_ERROR;
     }
 
-    return njs_scope_index(NJS_SCOPE_GLOBAL, scope->temp++, NJS_LEVEL_TEMP,
+    return njs_scope_index(scope->type, scope->items++, NJS_LEVEL_LOCAL,
                            NJS_VARIABLE_VAR);
 }
 
index dadec63cdb4e1b4c586e0d4fe7b6f48c0f1d95e6..2c0099fa13d8d51014ba3a24d1336df1acf4b062 100644 (file)
@@ -226,17 +226,6 @@ njs_vm_compile(njs_vm_t *vm, u_char **start, u_char *end)
     vm->variables_hash = &scope->variables;
     vm->global_items = scope->items;
 
-    vm->levels[NJS_LEVEL_TEMP] = NULL;
-
-    if (scope->temp != 0) {
-        new = njs_scope_make(vm, scope->temp);
-        if (njs_slow_path(new == NULL)) {
-            return ret;
-        }
-
-        vm->levels[NJS_LEVEL_TEMP] = new;
-    }
-
     if (vm->options.disassemble) {
         njs_disassembler(vm);
     }
@@ -305,7 +294,6 @@ njs_vm_compile_module(njs_vm_t *vm, njs_str_t *name, u_char **start,
 
     lambda->start = generator.code_start;
     lambda->nlocal = scope->items;
-    lambda->temp = scope->temp;
 
     arr = scope->declarations;
     lambda->declarations = (arr != NULL) ? arr->start : NULL;
index f07bf0b31ee57a08f0df8b524dbbd26461a2cd35..64cc74f0e9c8594ac57b9185cbd2953a313deb09 100644 (file)
@@ -122,7 +122,6 @@ typedef enum {
     NJS_LEVEL_CLOSURE,
     NJS_LEVEL_GLOBAL,
     NJS_LEVEL_STATIC,
-    NJS_LEVEL_TEMP,
     NJS_LEVEL_MAX
 } njs_level_type_t;