[njs] Refactored njs_vmcode_interpreter() for performance.
Dmitry Volyntsev
xeioex at nginx.com
Fri Jul 26 17:49:19 UTC 2019
details: https://hg.nginx.org/njs/rev/6aa2e67eaafc
branches:
changeset: 1070:6aa2e67eaafc
user: Dmitry Volyntsev <xeioex at nginx.com>
date: Fri Jul 26 20:37:13 2019 +0300
description:
Refactored njs_vmcode_interpreter() for performance.
1) opcodes are rewritten using switch table.
2) often-used opcodes are prioritized and
inlined.
3) similar opcodes are combined into unified
handlers.
4) njs_vmcode_interpreter() return NJS_OK on
success. NJS_STOP return code is removed.
diffstat:
njs/njs_disassembler.c | 140 +-
njs/njs_function.c | 7 +-
njs/njs_function.h | 2 +-
njs/njs_generator.c | 100 +-
njs/njs_parser.c | 2 +-
njs/njs_parser_expression.c | 102 +-
njs/njs_parser_terminal.c | 2 +-
njs/njs_vm.c | 14 +-
njs/njs_vm.h | 21 +-
njs/njs_vmcode.c | 2057 +++++++++++++++++-------------------------
njs/njs_vmcode.h | 252 +---
njs/test/njs_unit_test.c | 11 +
12 files changed, 1139 insertions(+), 1571 deletions(-)
diffs (truncated from 3927 to 1000 lines):
diff -r 89082cb0bc84 -r 6aa2e67eaafc njs/njs_disassembler.c
--- a/njs/njs_disassembler.c Thu Jul 25 22:07:57 2019 +0300
+++ b/njs/njs_disassembler.c Fri Jul 26 20:37:13 2019 +0300
@@ -19,116 +19,116 @@ typedef struct {
static njs_code_name_t code_names[] = {
- { njs_vmcode_object, sizeof(njs_vmcode_object_t),
+ { NJS_VMCODE_OBJECT, sizeof(njs_vmcode_object_t),
nxt_string("OBJECT ") },
- { njs_vmcode_function, sizeof(njs_vmcode_function_t),
+ { NJS_VMCODE_FUNCTION, sizeof(njs_vmcode_function_t),
nxt_string("FUNCTION ") },
- { njs_vmcode_this, sizeof(njs_vmcode_this_t),
+ { NJS_VMCODE_THIS, sizeof(njs_vmcode_this_t),
nxt_string("THIS ") },
- { njs_vmcode_arguments, sizeof(njs_vmcode_arguments_t),
+ { NJS_VMCODE_ARGUMENTS, sizeof(njs_vmcode_arguments_t),
nxt_string("ARGUMENTS ") },
- { njs_vmcode_regexp, sizeof(njs_vmcode_regexp_t),
+ { NJS_VMCODE_REGEXP, sizeof(njs_vmcode_regexp_t),
nxt_string("REGEXP ") },
- { njs_vmcode_template_literal, sizeof(njs_vmcode_template_literal_t),
+ { NJS_VMCODE_TEMPLATE_LITERAL, sizeof(njs_vmcode_template_literal_t),
nxt_string("TEMPLATE LITERAL") },
- { njs_vmcode_object_copy, sizeof(njs_vmcode_object_copy_t),
+ { NJS_VMCODE_OBJECT_COPY, sizeof(njs_vmcode_object_copy_t),
nxt_string("OBJECT COPY ") },
- { njs_vmcode_property_get, sizeof(njs_vmcode_prop_get_t),
+ { NJS_VMCODE_PROPERTY_GET, sizeof(njs_vmcode_prop_get_t),
nxt_string("PROPERTY GET ") },
- { njs_vmcode_property_init, sizeof(njs_vmcode_prop_set_t),
+ { NJS_VMCODE_PROPERTY_INIT, sizeof(njs_vmcode_prop_set_t),
nxt_string("PROPERTY INIT ") },
- { njs_vmcode_property_set, sizeof(njs_vmcode_prop_set_t),
+ { NJS_VMCODE_PROPERTY_SET, sizeof(njs_vmcode_prop_set_t),
nxt_string("PROPERTY SET ") },
- { njs_vmcode_property_in, sizeof(njs_vmcode_3addr_t),
+ { NJS_VMCODE_PROPERTY_IN, sizeof(njs_vmcode_3addr_t),
nxt_string("PROPERTY IN ") },
- { njs_vmcode_property_delete, sizeof(njs_vmcode_3addr_t),
+ { NJS_VMCODE_PROPERTY_DELETE, sizeof(njs_vmcode_3addr_t),
nxt_string("PROPERTY DELETE ") },
- { njs_vmcode_instance_of, sizeof(njs_vmcode_instance_of_t),
+ { NJS_VMCODE_INSTANCE_OF, sizeof(njs_vmcode_instance_of_t),
nxt_string("INSTANCE OF ") },
- { njs_vmcode_function_call, sizeof(njs_vmcode_function_call_t),
+ { NJS_VMCODE_FUNCTION_CALL, sizeof(njs_vmcode_function_call_t),
nxt_string("FUNCTION CALL ") },
- { njs_vmcode_return, sizeof(njs_vmcode_return_t),
+ { NJS_VMCODE_RETURN, sizeof(njs_vmcode_return_t),
nxt_string("RETURN ") },
- { njs_vmcode_stop, sizeof(njs_vmcode_stop_t),
+ { NJS_VMCODE_STOP, sizeof(njs_vmcode_stop_t),
nxt_string("STOP ") },
- { njs_vmcode_increment, sizeof(njs_vmcode_3addr_t),
+ { NJS_VMCODE_INCREMENT, sizeof(njs_vmcode_3addr_t),
nxt_string("INC ") },
- { njs_vmcode_decrement, sizeof(njs_vmcode_3addr_t),
+ { NJS_VMCODE_DECREMENT, sizeof(njs_vmcode_3addr_t),
nxt_string("DEC ") },
- { njs_vmcode_post_increment, sizeof(njs_vmcode_3addr_t),
+ { NJS_VMCODE_POST_INCREMENT, sizeof(njs_vmcode_3addr_t),
nxt_string("POST INC ") },
- { njs_vmcode_post_decrement, sizeof(njs_vmcode_3addr_t),
+ { NJS_VMCODE_POST_DECREMENT, sizeof(njs_vmcode_3addr_t),
nxt_string("POST DEC ") },
- { njs_vmcode_delete, sizeof(njs_vmcode_2addr_t),
+ { NJS_VMCODE_DELETE, sizeof(njs_vmcode_2addr_t),
nxt_string("DELETE ") },
- { njs_vmcode_void, sizeof(njs_vmcode_2addr_t),
+ { NJS_VMCODE_VOID, sizeof(njs_vmcode_2addr_t),
nxt_string("VOID ") },
- { njs_vmcode_typeof, sizeof(njs_vmcode_2addr_t),
+ { NJS_VMCODE_TYPEOF, sizeof(njs_vmcode_2addr_t),
nxt_string("TYPEOF ") },
- { njs_vmcode_unary_plus, sizeof(njs_vmcode_2addr_t),
+ { NJS_VMCODE_UNARY_PLUS, sizeof(njs_vmcode_2addr_t),
nxt_string("PLUS ") },
- { njs_vmcode_unary_negation, sizeof(njs_vmcode_2addr_t),
+ { NJS_VMCODE_UNARY_NEGATION, sizeof(njs_vmcode_2addr_t),
nxt_string("NEGATION ") },
- { njs_vmcode_addition, sizeof(njs_vmcode_3addr_t),
+ { NJS_VMCODE_ADDITION, sizeof(njs_vmcode_3addr_t),
nxt_string("ADD ") },
- { njs_vmcode_substraction, sizeof(njs_vmcode_3addr_t),
+ { NJS_VMCODE_SUBSTRACTION, sizeof(njs_vmcode_3addr_t),
nxt_string("SUBSTRACT ") },
- { njs_vmcode_multiplication, sizeof(njs_vmcode_3addr_t),
+ { NJS_VMCODE_MULTIPLICATION, sizeof(njs_vmcode_3addr_t),
nxt_string("MULTIPLY ") },
- { njs_vmcode_exponentiation, sizeof(njs_vmcode_3addr_t),
+ { NJS_VMCODE_EXPONENTIATION, sizeof(njs_vmcode_3addr_t),
nxt_string("POWER ") },
- { njs_vmcode_division, sizeof(njs_vmcode_3addr_t),
+ { NJS_VMCODE_DIVISION, sizeof(njs_vmcode_3addr_t),
nxt_string("DIVIDE ") },
- { njs_vmcode_remainder, sizeof(njs_vmcode_3addr_t),
+ { NJS_VMCODE_REMAINDER, sizeof(njs_vmcode_3addr_t),
nxt_string("REMAINDER ") },
- { njs_vmcode_left_shift, sizeof(njs_vmcode_3addr_t),
+ { NJS_VMCODE_LEFT_SHIFT, sizeof(njs_vmcode_3addr_t),
nxt_string("LEFT SHIFT ") },
- { njs_vmcode_right_shift, sizeof(njs_vmcode_3addr_t),
+ { NJS_VMCODE_RIGHT_SHIFT, sizeof(njs_vmcode_3addr_t),
nxt_string("RIGHT SHIFT ") },
- { njs_vmcode_unsigned_right_shift, sizeof(njs_vmcode_3addr_t),
+ { NJS_VMCODE_UNSIGNED_RIGHT_SHIFT, sizeof(njs_vmcode_3addr_t),
nxt_string("USGN RIGHT SHIFT") },
- { njs_vmcode_logical_not, sizeof(njs_vmcode_2addr_t),
+ { NJS_VMCODE_LOGICAL_NOT, sizeof(njs_vmcode_2addr_t),
nxt_string("LOGICAL NOT ") },
- { njs_vmcode_bitwise_not, sizeof(njs_vmcode_2addr_t),
+ { NJS_VMCODE_BITWISE_NOT, sizeof(njs_vmcode_2addr_t),
nxt_string("BINARY NOT ") },
- { njs_vmcode_bitwise_and, sizeof(njs_vmcode_3addr_t),
+ { NJS_VMCODE_BITWISE_AND, sizeof(njs_vmcode_3addr_t),
nxt_string("BINARY AND ") },
- { njs_vmcode_bitwise_xor, sizeof(njs_vmcode_3addr_t),
+ { NJS_VMCODE_BITWISE_XOR, sizeof(njs_vmcode_3addr_t),
nxt_string("BINARY XOR ") },
- { njs_vmcode_bitwise_or, sizeof(njs_vmcode_3addr_t),
+ { NJS_VMCODE_BITWISE_OR, sizeof(njs_vmcode_3addr_t),
nxt_string("BINARY OR ") },
- { njs_vmcode_equal, sizeof(njs_vmcode_3addr_t),
+ { NJS_VMCODE_EQUAL, sizeof(njs_vmcode_3addr_t),
nxt_string("EQUAL ") },
- { njs_vmcode_not_equal, sizeof(njs_vmcode_3addr_t),
+ { NJS_VMCODE_NOT_EQUAL, sizeof(njs_vmcode_3addr_t),
nxt_string("NOT EQUAL ") },
- { njs_vmcode_less, sizeof(njs_vmcode_3addr_t),
+ { NJS_VMCODE_LESS, sizeof(njs_vmcode_3addr_t),
nxt_string("LESS ") },
- { njs_vmcode_less_or_equal, sizeof(njs_vmcode_3addr_t),
+ { NJS_VMCODE_LESS_OR_EQUAL, sizeof(njs_vmcode_3addr_t),
nxt_string("LESS OR EQUAL ") },
- { njs_vmcode_greater, sizeof(njs_vmcode_3addr_t),
+ { NJS_VMCODE_GREATER, sizeof(njs_vmcode_3addr_t),
nxt_string("GREATER ") },
- { njs_vmcode_greater_or_equal, sizeof(njs_vmcode_3addr_t),
+ { NJS_VMCODE_GREATER_OR_EQUAL, sizeof(njs_vmcode_3addr_t),
nxt_string("GREATER OR EQUAL") },
- { njs_vmcode_strict_equal, sizeof(njs_vmcode_3addr_t),
+ { NJS_VMCODE_STRICT_EQUAL, sizeof(njs_vmcode_3addr_t),
nxt_string("STRICT EQUAL ") },
- { njs_vmcode_strict_not_equal, sizeof(njs_vmcode_3addr_t),
+ { NJS_VMCODE_STRICT_NOT_EQUAL, sizeof(njs_vmcode_3addr_t),
nxt_string("STRICT NOT EQUAL") },
- { njs_vmcode_move, sizeof(njs_vmcode_move_t),
+ { NJS_VMCODE_MOVE, sizeof(njs_vmcode_move_t),
nxt_string("MOVE ") },
- { njs_vmcode_throw, sizeof(njs_vmcode_throw_t),
+ { NJS_VMCODE_THROW, sizeof(njs_vmcode_throw_t),
nxt_string("THROW ") },
};
@@ -140,8 +140,8 @@ njs_disassembler(njs_vm_t *vm)
nxt_uint_t n;
njs_vm_code_t *code;
- code = vm->code->start;
- n = vm->code->items;
+ code = vm->codes->start;
+ n = vm->codes->items;
while (n != 0) {
nxt_printf("%V:%V\n", &code->file, &code->name);
@@ -191,7 +191,7 @@ njs_disassemble(u_char *start, u_char *e
while (p < end) {
operation = *(njs_vmcode_operation_t *) p;
- if (operation == njs_vmcode_array) {
+ if (operation == NJS_VMCODE_ARRAY) {
array = (njs_vmcode_array_t *) p;
nxt_printf("%05uz ARRAY %04Xz %uz%s\n",
@@ -203,7 +203,7 @@ njs_disassemble(u_char *start, u_char *e
continue;
}
- if (operation == njs_vmcode_if_true_jump) {
+ if (operation == NJS_VMCODE_IF_TRUE_JUMP) {
cond_jump = (njs_vmcode_cond_jump_t *) p;
sign = (cond_jump->offset >= 0) ? "+" : "";
@@ -216,7 +216,7 @@ njs_disassemble(u_char *start, u_char *e
continue;
}
- if (operation == njs_vmcode_if_false_jump) {
+ if (operation == NJS_VMCODE_IF_FALSE_JUMP) {
cond_jump = (njs_vmcode_cond_jump_t *) p;
sign = (cond_jump->offset >= 0) ? "+" : "";
@@ -229,7 +229,7 @@ njs_disassemble(u_char *start, u_char *e
continue;
}
- if (operation == njs_vmcode_jump) {
+ if (operation == NJS_VMCODE_JUMP) {
jump = (njs_vmcode_jump_t *) p;
sign = (jump->offset >= 0) ? "+" : "";
@@ -241,7 +241,7 @@ njs_disassemble(u_char *start, u_char *e
continue;
}
- if (operation == njs_vmcode_if_equal_jump) {
+ if (operation == NJS_VMCODE_IF_EQUAL_JUMP) {
equal = (njs_vmcode_equal_jump_t *) p;
nxt_printf("%05uz JUMP IF EQUAL %04Xz %04Xz +%uz\n",
@@ -253,7 +253,7 @@ njs_disassemble(u_char *start, u_char *e
continue;
}
- if (operation == njs_vmcode_test_if_true) {
+ if (operation == NJS_VMCODE_TEST_IF_TRUE) {
test_jump = (njs_vmcode_test_jump_t *) p;
nxt_printf("%05uz TEST IF TRUE %04Xz %04Xz +%uz\n",
@@ -265,7 +265,7 @@ njs_disassemble(u_char *start, u_char *e
continue;
}
- if (operation == njs_vmcode_test_if_false) {
+ if (operation == NJS_VMCODE_TEST_IF_FALSE) {
test_jump = (njs_vmcode_test_jump_t *) p;
nxt_printf("%05uz TEST IF FALSE %04Xz %04Xz +%uz\n",
@@ -277,7 +277,7 @@ njs_disassemble(u_char *start, u_char *e
continue;
}
- if (operation == njs_vmcode_function_frame) {
+ if (operation == NJS_VMCODE_FUNCTION_FRAME) {
function = (njs_vmcode_function_frame_t *) p;
nxt_printf("%05uz FUNCTION FRAME %04Xz %uz%s\n",
@@ -289,7 +289,7 @@ njs_disassemble(u_char *start, u_char *e
continue;
}
- if (operation == njs_vmcode_method_frame) {
+ if (operation == NJS_VMCODE_METHOD_FRAME) {
method = (njs_vmcode_method_frame_t *) p;
nxt_printf("%05uz METHOD FRAME %04Xz %04Xz %uz%s\n",
@@ -301,7 +301,7 @@ njs_disassemble(u_char *start, u_char *e
continue;
}
- if (operation == njs_vmcode_property_foreach) {
+ if (operation == NJS_VMCODE_PROPERTY_FOREACH) {
prop_foreach = (njs_vmcode_prop_foreach_t *) p;
nxt_printf("%05uz PROPERTY FOREACH %04Xz %04Xz +%uz\n",
@@ -313,7 +313,7 @@ njs_disassemble(u_char *start, u_char *e
continue;
}
- if (operation == njs_vmcode_property_next) {
+ if (operation == NJS_VMCODE_PROPERTY_NEXT) {
prop_next = (njs_vmcode_prop_next_t *) p;
nxt_printf("%05uz PROPERTY NEXT %04Xz %04Xz %04Xz %uz\n",
@@ -326,7 +326,7 @@ njs_disassemble(u_char *start, u_char *e
continue;
}
- if (operation == njs_vmcode_try_start) {
+ if (operation == NJS_VMCODE_TRY_START) {
try_start = (njs_vmcode_try_start_t *) p;
nxt_printf("%05uz TRY START %04Xz %04Xz +%uz\n",
@@ -339,7 +339,7 @@ njs_disassemble(u_char *start, u_char *e
continue;
}
- if (operation == njs_vmcode_try_break) {
+ if (operation == NJS_VMCODE_TRY_BREAK) {
try_tramp = (njs_vmcode_try_trampoline_t *) p;
nxt_printf("%05uz TRY BREAK %04Xz %uz\n",
@@ -351,7 +351,7 @@ njs_disassemble(u_char *start, u_char *e
continue;
}
- if (operation == njs_vmcode_try_continue) {
+ if (operation == NJS_VMCODE_TRY_CONTINUE) {
try_tramp = (njs_vmcode_try_trampoline_t *) p;
nxt_printf("%05uz TRY CONTINUE %04Xz %uz\n",
@@ -363,7 +363,7 @@ njs_disassemble(u_char *start, u_char *e
continue;
}
- if (operation == njs_vmcode_try_return) {
+ if (operation == NJS_VMCODE_TRY_RETURN) {
try_return = (njs_vmcode_try_return_t *) p;
nxt_printf("%05uz TRY RETURN %04Xz %04Xz +%uz\n",
@@ -376,7 +376,7 @@ njs_disassemble(u_char *start, u_char *e
continue;
}
- if (operation == njs_vmcode_catch) {
+ if (operation == NJS_VMCODE_CATCH) {
catch = (njs_vmcode_catch_t *) p;
nxt_printf("%05uz CATCH %04Xz +%uz\n",
@@ -388,7 +388,7 @@ njs_disassemble(u_char *start, u_char *e
continue;
}
- if (operation == njs_vmcode_try_end) {
+ if (operation == NJS_VMCODE_TRY_END) {
try_end = (njs_vmcode_try_end_t *) p;
nxt_printf("%05uz TRY END +%uz\n",
@@ -399,7 +399,7 @@ njs_disassemble(u_char *start, u_char *e
continue;
}
- if (operation == njs_vmcode_finally) {
+ if (operation == NJS_VMCODE_FINALLY) {
finally = (njs_vmcode_finally_t *) p;
nxt_printf("%05uz TRY FINALLY %04Xz %04Xz +%uz +%uz\n",
@@ -413,7 +413,7 @@ njs_disassemble(u_char *start, u_char *e
continue;
}
- if (operation == njs_vmcode_reference_error) {
+ if (operation == NJS_VMCODE_REFERENCE_ERROR) {
nxt_printf("%05uz REFERENCE ERROR\n", p - start);
p += sizeof(njs_vmcode_reference_error_t);
diff -r 89082cb0bc84 -r 6aa2e67eaafc njs/njs_function.c
--- a/njs/njs_function.c Thu Jul 25 22:07:57 2019 +0300
+++ b/njs/njs_function.c Fri Jul 26 20:37:13 2019 +0300
@@ -500,10 +500,7 @@ njs_function_lambda_call(njs_vm_t *vm)
frame = (njs_frame_t *) vm->top_frame;
function = frame->native.function;
- frame->return_address = vm->current;
-
lambda = function->u.lambda;
- vm->current = lambda->start;
#if (NXT_DEBUG)
vm->scopes[NJS_SCOPE_CALLEE_ARGUMENTS] = NULL;
@@ -571,9 +568,11 @@ njs_function_lambda_call(njs_vm_t *vm)
}
}
+ frame->native.call = 1;
+
vm->active_frame = frame;
- return njs_vmcode_run(vm);
+ return njs_vmcode_interpreter(vm, lambda->start);
}
diff -r 89082cb0bc84 -r 6aa2e67eaafc njs/njs_function.h
--- a/njs/njs_function.h Thu Jul 25 22:07:57 2019 +0300
+++ b/njs/njs_function.h Fri Jul 26 20:37:13 2019 +0300
@@ -90,7 +90,7 @@ struct njs_native_frame_s {
/* Skip the Function.call() and Function.apply() methods frames. */
uint8_t skip; /* 1 bit */
- uint8_t call; /* 1 bit */
+ uint8_t call; /* 1 bit */
};
diff -r 89082cb0bc84 -r 6aa2e67eaafc njs/njs_generator.c
--- a/njs/njs_generator.c Thu Jul 25 22:07:57 2019 +0300
+++ b/njs/njs_generator.c Fri Jul 26 20:37:13 2019 +0300
@@ -198,7 +198,7 @@ static nxt_int_t njs_generate_function_d
#define njs_generate_code_jump(generator, _code, _offset) \
do { \
njs_generate_code(generator, njs_vmcode_jump_t, _code, \
- njs_vmcode_jump, 0, 0); \
+ NJS_VMCODE_JUMP, 0, 0); \
_code->offset = _offset; \
} while (0)
@@ -206,7 +206,7 @@ static nxt_int_t njs_generate_function_d
#define njs_generate_code_move(generator, _code, _dst, _src) \
do { \
njs_generate_code(generator, njs_vmcode_move_t, _code, \
- njs_vmcode_move, 2, 1); \
+ NJS_VMCODE_MOVE, 2, 1); \
_code->dst = _dst; \
_code->src = _src; \
} while (0)
@@ -562,7 +562,7 @@ njs_generate_name(njs_vm_t *vm, njs_gene
}
njs_generate_code(generator, njs_vmcode_object_copy_t, copy,
- njs_vmcode_object_copy, 2, 1);
+ NJS_VMCODE_OBJECT_COPY, 2, 1);
copy->retval = node->index;
copy->object = var->index;
@@ -591,7 +591,7 @@ njs_generate_builtin_object(njs_vm_t *vm
}
njs_generate_code(generator, njs_vmcode_object_copy_t, copy,
- njs_vmcode_object_copy, 2, 1);
+ NJS_VMCODE_OBJECT_COPY, 2, 1);
copy->retval = node->index;
copy->object = index;
@@ -680,7 +680,7 @@ njs_generate_if_statement(njs_vm_t *vm,
}
njs_generate_code(generator, njs_vmcode_cond_jump_t, cond_jump,
- njs_vmcode_if_false_jump, 2, 0);
+ NJS_VMCODE_IF_FALSE_JUMP, 2, 0);
cond_jump->cond = node->left->index;
ret = njs_generate_node_index_release(vm, generator, node->left);
@@ -755,7 +755,7 @@ njs_generate_cond_expression(njs_vm_t *v
}
njs_generate_code(generator, njs_vmcode_cond_jump_t, cond_jump,
- njs_vmcode_if_false_jump, 2, 0);
+ NJS_VMCODE_IF_FALSE_JUMP, 2, 0);
cond_jump_offset = njs_code_offset(generator, cond_jump);
cond_jump->cond = node->left->index;
@@ -875,7 +875,7 @@ njs_generate_switch_statement(njs_vm_t *
}
njs_generate_code(generator, njs_vmcode_equal_jump_t, equal,
- njs_vmcode_if_equal_jump, 3, 0);
+ NJS_VMCODE_IF_EQUAL_JUMP, 3, 0);
equal->offset = offsetof(njs_vmcode_equal_jump_t, offset);
equal->value1 = index;
equal->value2 = node->left->index;
@@ -998,7 +998,7 @@ njs_generate_while_statement(njs_vm_t *v
}
njs_generate_code(generator, njs_vmcode_cond_jump_t, cond_jump,
- njs_vmcode_if_true_jump, 2, 0);
+ NJS_VMCODE_IF_TRUE_JUMP, 2, 0);
cond_jump->offset = loop_offset - njs_code_offset(generator, cond_jump);
cond_jump->cond = condition->index;
@@ -1044,7 +1044,7 @@ njs_generate_do_while_statement(njs_vm_t
}
njs_generate_code(generator, njs_vmcode_cond_jump_t, cond_jump,
- njs_vmcode_if_true_jump, 2, 0);
+ NJS_VMCODE_IF_TRUE_JUMP, 2, 0);
cond_jump->offset = loop_offset - njs_code_offset(generator, cond_jump);
cond_jump->cond = condition->index;
@@ -1138,7 +1138,7 @@ njs_generate_for_statement(njs_vm_t *vm,
}
njs_generate_code(generator, njs_vmcode_cond_jump_t, cond_jump,
- njs_vmcode_if_true_jump, 2, 0);
+ NJS_VMCODE_IF_TRUE_JUMP, 2, 0);
cond_jump->offset = loop_offset - njs_code_offset(generator, cond_jump);
cond_jump->cond = condition->index;
@@ -1183,7 +1183,7 @@ njs_generate_for_in_statement(njs_vm_t *
}
njs_generate_code(generator, njs_vmcode_prop_foreach_t, prop_foreach,
- njs_vmcode_property_foreach, 2, 1);
+ NJS_VMCODE_PROPERTY_FOREACH, 2, 1);
prop_offset = njs_code_offset(generator, prop_foreach);
prop_foreach->object = foreach->right->index;
@@ -1215,7 +1215,7 @@ njs_generate_for_in_statement(njs_vm_t *
}
njs_generate_code(generator, njs_vmcode_prop_next_t, prop_next,
- njs_vmcode_property_next, 3, 0);
+ NJS_VMCODE_PROPERTY_NEXT, 3, 0);
prop_offset = njs_code_offset(generator, prop_next);
prop_next->retval = foreach->left->index;
prop_next->object = foreach->right->index;
@@ -1602,7 +1602,7 @@ njs_generate_stop_statement(njs_vm_t *vm
if (nxt_fast_path(ret == NXT_OK)) {
njs_generate_code(generator, njs_vmcode_stop_t, stop,
- njs_vmcode_stop, 1, 0);
+ NJS_VMCODE_STOP, 1, 0);
index = NJS_INDEX_NONE;
node = node->right;
@@ -1736,10 +1736,10 @@ njs_generate_assignment(njs_vm_t *vm, nj
if (lvalue->token == NJS_TOKEN_PROPERTY_INIT) {
njs_generate_code(generator, njs_vmcode_prop_set_t, prop_set,
- njs_vmcode_property_init, 3, 0);
+ NJS_VMCODE_PROPERTY_INIT, 3, 0);
} else {
njs_generate_code(generator, njs_vmcode_prop_set_t, prop_set,
- njs_vmcode_property_set, 3, 0);
+ NJS_VMCODE_PROPERTY_SET, 3, 0);
}
prop_set->value = expr->index;
@@ -1781,7 +1781,7 @@ njs_generate_operation_assignment(njs_vm
/* Preserve variable value if it may be changed by expression. */
njs_generate_code(generator, njs_vmcode_move_t, move,
- njs_vmcode_move, 2, 1);
+ NJS_VMCODE_MOVE, 2, 1);
move->src = lvalue->index;
index = njs_generate_temp_index_get(vm, generator, expr);
@@ -1841,7 +1841,7 @@ njs_generate_operation_assignment(njs_vm
}
njs_generate_code(generator, njs_vmcode_prop_get_t, prop_get,
- njs_vmcode_property_get, 3, 1);
+ NJS_VMCODE_PROPERTY_GET, 3, 1);
prop_get->value = index;
prop_get->object = object->index;
prop_get->property = property->index;
@@ -1860,7 +1860,7 @@ njs_generate_operation_assignment(njs_vm
code->src2 = expr->index;
njs_generate_code(generator, njs_vmcode_prop_set_t, prop_set,
- njs_vmcode_property_set, 3, 0);
+ NJS_VMCODE_PROPERTY_SET, 3, 0);
prop_set->value = node->index;
prop_set->object = object->index;
prop_set->property = property->index;
@@ -1886,7 +1886,7 @@ njs_generate_object(njs_vm_t *vm, njs_ge
}
njs_generate_code(generator, njs_vmcode_object_t, object,
- njs_vmcode_object, 1, 1);
+ NJS_VMCODE_OBJECT, 1, 1);
object->retval = node->index;
/* Initialize object. */
@@ -1906,7 +1906,7 @@ njs_generate_array(njs_vm_t *vm, njs_gen
}
njs_generate_code(generator, njs_vmcode_array_t, array,
- njs_vmcode_array, 1, 1);
+ NJS_VMCODE_ARRAY, 1, 1);
array->code.ctor = node->ctor;
array->retval = node->index;
array->length = node->u.length;
@@ -1946,7 +1946,7 @@ njs_generate_function(njs_vm_t *vm, njs_
}
njs_generate_code(generator, njs_vmcode_function_t, function,
- njs_vmcode_function, 1, 1);
+ NJS_VMCODE_FUNCTION, 1, 1);
function->lambda = lambda;
node->index = njs_generate_object_dest_index(vm, generator, node);
@@ -1972,7 +1972,7 @@ njs_generate_regexp(njs_vm_t *vm, njs_ge
}
njs_generate_code(generator, njs_vmcode_regexp_t, regexp,
- njs_vmcode_regexp, 1, 1);
+ NJS_VMCODE_REGEXP, 1, 1);
regexp->retval = node->index;
regexp->pattern = node->u.value.data.u.data;
@@ -1993,7 +1993,7 @@ njs_generate_template_literal(njs_vm_t *
}
njs_generate_code(generator, njs_vmcode_template_literal_t, code,
- njs_vmcode_template_literal, 1, 1);
+ NJS_VMCODE_TEMPLATE_LITERAL, 1, 1);
code->retval = node->left->index;
node->index = node->left->index;
@@ -2073,7 +2073,7 @@ njs_generate_3addr_operation(njs_vm_t *v
if (nxt_slow_path(njs_parser_has_side_effect(right))) {
njs_generate_code(generator, njs_vmcode_move_t, move,
- njs_vmcode_move, 2, 1);
+ NJS_VMCODE_MOVE, 2, 1);
move->src = left->index;
index = njs_generate_node_temp_index_get(vm, generator, left);
@@ -2273,7 +2273,7 @@ found:
}
njs_generate_code(generator, njs_vmcode_prop_get_t, prop_get,
- njs_vmcode_property_get, 3, 1);
+ NJS_VMCODE_PROPERTY_GET, 3, 1);
prop_get->value = index;
prop_get->object = lvalue->left->index;
prop_get->property = lvalue->right->index;
@@ -2285,7 +2285,7 @@ found:
code->src2 = index;
njs_generate_code(generator, njs_vmcode_prop_set_t, prop_set,
- njs_vmcode_property_set, 3, 0);
+ NJS_VMCODE_PROPERTY_SET, 3, 0);
prop_set->value = index;
prop_set->object = lvalue->left->index;
prop_set->property = lvalue->right->index;
@@ -2430,15 +2430,15 @@ njs_generate_scope(njs_vm_t *vm, njs_gen
*value++ = njs_value_undefined;
}
- if (vm->code == NULL) {
- vm->code = nxt_array_create(4, sizeof(njs_vm_code_t),
+ if (vm->codes == NULL) {
+ vm->codes = nxt_array_create(4, sizeof(njs_vm_code_t),
&njs_array_mem_proto, vm->mem_pool);
- if (nxt_slow_path(vm->code == NULL)) {
+ if (nxt_slow_path(vm->codes == NULL)) {
return NXT_ERROR;
}
}
- code = nxt_array_add(vm->code, &njs_array_mem_proto, vm->mem_pool);
+ code = nxt_array_add(vm->codes, &njs_array_mem_proto, vm->mem_pool);
if (nxt_slow_path(code == NULL)) {
return NXT_ERROR;
}
@@ -2480,13 +2480,13 @@ njs_generate_lambda_variables(njs_vm_t *
if (var->this_object) {
njs_generate_code(generator, njs_vmcode_this_t, this,
- njs_vmcode_this, 1, 0);
+ NJS_VMCODE_THIS, 1, 0);
this->dst = var->index;
}
if (var->arguments_object) {
njs_generate_code(generator, njs_vmcode_arguments_t, arguments,
- njs_vmcode_arguments, 1, 0);
+ NJS_VMCODE_ARGUMENTS, 1, 0);
arguments->dst = var->index;
}
}
@@ -2524,7 +2524,7 @@ njs_generate_return_statement(njs_vm_t *
if (nxt_fast_path(immediate == NULL)) {
njs_generate_code(generator, njs_vmcode_return_t, code,
- njs_vmcode_return, 1, 0);
+ NJS_VMCODE_RETURN, 1, 0);
code->retval = index;
node->index = index;
@@ -2554,7 +2554,7 @@ njs_generate_return_statement(njs_vm_t *
}
njs_generate_code(generator, njs_vmcode_try_return_t, try_return,
- njs_vmcode_try_return, 2, 1);
+ NJS_VMCODE_TRY_RETURN, 2, 1);
try_return->retval = index;
try_return->save = top->index;
try_return->offset = offsetof(njs_vmcode_try_return_t, offset);
@@ -2603,7 +2603,7 @@ njs_generate_function_call(njs_vm_t *vm,
}
njs_generate_code(generator, njs_vmcode_function_frame_t, func,
- njs_vmcode_function_frame, 2, 0);
+ NJS_VMCODE_FUNCTION_FRAME, 2, 0);
func_offset = njs_code_offset(generator, func);
func->code.ctor = node->ctor;
func->name = name->index;
@@ -2647,7 +2647,7 @@ njs_generate_method_call(njs_vm_t *vm, n
}
njs_generate_code(generator, njs_vmcode_method_frame_t, method,
- njs_vmcode_method_frame, 3, 0);
+ NJS_VMCODE_METHOD_FRAME, 3, 0);
method_offset = njs_code_offset(generator, method);
method->code.ctor = node->ctor;
method->object = prop->left->index;
@@ -2706,7 +2706,7 @@ njs_generate_call(njs_vm_t *vm, njs_gene
node->index = retval;
njs_generate_code(generator, njs_vmcode_function_call_t, call,
- njs_vmcode_function_call, 1, 0);
+ NJS_VMCODE_FUNCTION_CALL, 1, 0);
call->retval = retval;
return nargs;
@@ -2716,7 +2716,7 @@ njs_generate_call(njs_vm_t *vm, njs_gene
#define njs_generate_code_catch(generator, _code, _exception) \
do { \
njs_generate_code(generator, njs_vmcode_catch_t, _code, \
- njs_vmcode_catch, 2, 0); \
+ NJS_VMCODE_CATCH, 2, 0); \
_code->offset = sizeof(njs_vmcode_catch_t); \
_code->exception = _exception; \
} while (0)
@@ -2725,7 +2725,7 @@ njs_generate_call(njs_vm_t *vm, njs_gene
#define njs_generate_code_finally(generator, _code, _retval, _exit) \
do { \
njs_generate_code(generator, njs_vmcode_finally_t, _code, \
- njs_vmcode_finally, 2, 0); \
+ NJS_VMCODE_FINALLY, 2, 0); \
_code->retval = _retval; \
_code->exit_value = _exit; \
_code->continue_offset = offsetof(njs_vmcode_finally_t, \
@@ -2755,7 +2755,7 @@ njs_generate_try_statement(njs_vm_t *vm,
njs_vmcode_try_trampoline_t *try_break, *try_continue;
njs_generate_code(generator, njs_vmcode_try_start_t, try_start,
- njs_vmcode_try_start, 2, 0);
+ NJS_VMCODE_TRY_START, 2, 0);
try_offset = njs_code_offset(generator, try_start);
exception_index = njs_generate_temp_index_get(vm, generator, node);
@@ -2795,7 +2795,7 @@ njs_generate_try_statement(njs_vm_t *vm,
try_cont_label = undef_label;
njs_generate_code(generator, njs_vmcode_try_end_t, try_end,
- njs_vmcode_try_end, 0, 0);
+ NJS_VMCODE_TRY_END, 0, 0);
try_end_offset = njs_code_offset(generator, try_end);
if (try_block->exit != NULL) {
@@ -2804,7 +2804,7 @@ njs_generate_try_statement(njs_vm_t *vm,
njs_generate_patch_block(vm, generator, try_block->exit);
njs_generate_code(generator, njs_vmcode_try_trampoline_t, try_break,
- njs_vmcode_try_break, 2, 0);
+ NJS_VMCODE_TRY_BREAK, 2, 0);
try_break->exit_value = exit_index;
try_break->offset = -sizeof(njs_vmcode_try_end_t);
@@ -2819,7 +2819,7 @@ njs_generate_try_statement(njs_vm_t *vm,
njs_generate_patch_block(vm, generator, try_block->continuation);
njs_generate_code(generator, njs_vmcode_try_trampoline_t, try_continue,
- njs_vmcode_try_continue, 2, 0);
+ NJS_VMCODE_TRY_CONTINUE, 2, 0);
try_continue->exit_value = exit_index;
try_continue->offset = -sizeof(njs_vmcode_try_end_t);
@@ -2924,7 +2924,7 @@ njs_generate_try_statement(njs_vm_t *vm,
}
njs_generate_code(generator, njs_vmcode_try_end_t, catch_end,
- njs_vmcode_try_end, 0, 0);
+ NJS_VMCODE_TRY_END, 0, 0);
catch_end_offset = njs_code_offset(generator, catch_end);
if (catch_block->exit != NULL) {
@@ -2933,7 +2933,7 @@ njs_generate_try_statement(njs_vm_t *vm,
njs_generate_patch_block(vm, generator, catch_block->exit);
njs_generate_code(generator, njs_vmcode_try_trampoline_t,
- try_break, njs_vmcode_try_break, 2, 0);
+ try_break, NJS_VMCODE_TRY_BREAK, 2, 0);
try_break->exit_value = exit_index;
@@ -2950,7 +2950,7 @@ njs_generate_try_statement(njs_vm_t *vm,
catch_block->continuation);
njs_generate_code(generator, njs_vmcode_try_trampoline_t,
- try_continue, njs_vmcode_try_continue, 2, 0);
+ try_continue, NJS_VMCODE_TRY_CONTINUE, 2, 0);
try_continue->exit_value = exit_index;
@@ -3064,7 +3064,7 @@ njs_generate_throw_statement(njs_vm_t *v
if (nxt_fast_path(ret == NXT_OK)) {
njs_generate_code(generator, njs_vmcode_throw_t, throw,
- njs_vmcode_throw, 1, 0);
+ NJS_VMCODE_THROW, 1, 0);
node->index = node->right->index;
throw->retval = node->index;
@@ -3102,7 +3102,7 @@ njs_generate_import_statement(njs_vm_t *
module = (njs_module_t *) expr->index;
njs_generate_code(generator, njs_vmcode_object_copy_t, copy,
- njs_vmcode_object_copy, 2, 1);
+ NJS_VMCODE_OBJECT_COPY, 2, 1);
copy->retval = index;
copy->object = module->index;
@@ -3126,7 +3126,7 @@ njs_generate_export_statement(njs_vm_t *
}
njs_generate_code(generator, njs_vmcode_return_t, code,
- njs_vmcode_return, 1, 0);
+ NJS_VMCODE_RETURN, 1, 0);
code->retval = obj->index;
node->index = obj->index;
@@ -3297,7 +3297,7 @@ njs_generate_reference_error(njs_vm_t *v
}
njs_generate_code(generator, njs_vmcode_reference_error_t, ref_err,
- njs_vmcode_reference_error, 0, 0);
+ NJS_VMCODE_REFERENCE_ERROR, 0, 0);
ref_err->token_line = node->token_line;
diff -r 89082cb0bc84 -r 6aa2e67eaafc njs/njs_parser.c
--- a/njs/njs_parser.c Thu Jul 25 22:07:57 2019 +0300
+++ b/njs/njs_parser.c Fri Jul 26 20:37:13 2019 +0300
@@ -1097,7 +1097,7 @@ njs_parser_var_statement(njs_vm_t *vm, n
return NJS_TOKEN_ERROR;
}
- assign->u.operation = njs_vmcode_move;
+ assign->u.operation = NJS_VMCODE_MOVE;
assign->left = name;
assign->right = expr;
diff -r 89082cb0bc84 -r 6aa2e67eaafc njs/njs_parser_expression.c
--- a/njs/njs_parser_expression.c Thu Jul 25 22:07:57 2019 +0300
+++ b/njs/njs_parser_expression.c Fri Jul 26 20:37:13 2019 +0300
@@ -74,9 +74,9 @@ static const njs_parser_expression_t
njs_parser_exponential_expression,
NULL,
3, {
- { NJS_TOKEN_MULTIPLICATION, njs_vmcode_multiplication },
- { NJS_TOKEN_DIVISION, njs_vmcode_division },
- { NJS_TOKEN_REMAINDER, njs_vmcode_remainder },
+ { NJS_TOKEN_MULTIPLICATION, NJS_VMCODE_MULTIPLICATION },
+ { NJS_TOKEN_DIVISION, NJS_VMCODE_DIVISION },
+ { NJS_TOKEN_REMAINDER, NJS_VMCODE_REMAINDER },
}
};
@@ -87,8 +87,8 @@ static const njs_parser_expression_t
njs_parser_binary_expression,
&njs_parser_factor_expression,
2, {
- { NJS_TOKEN_ADDITION, njs_vmcode_addition },
- { NJS_TOKEN_SUBSTRACTION, njs_vmcode_substraction },
+ { NJS_TOKEN_ADDITION, NJS_VMCODE_ADDITION },
+ { NJS_TOKEN_SUBSTRACTION, NJS_VMCODE_SUBSTRACTION },
}
};
@@ -99,9 +99,9 @@ static const njs_parser_expression_t
njs_parser_binary_expression,
&njs_parser_addition_expression,
3, {
- { NJS_TOKEN_LEFT_SHIFT, njs_vmcode_left_shift },
- { NJS_TOKEN_RIGHT_SHIFT, njs_vmcode_right_shift },
- { NJS_TOKEN_UNSIGNED_RIGHT_SHIFT, njs_vmcode_unsigned_right_shift },
+ { NJS_TOKEN_LEFT_SHIFT, NJS_VMCODE_LEFT_SHIFT },
+ { NJS_TOKEN_RIGHT_SHIFT, NJS_VMCODE_RIGHT_SHIFT },
+ { NJS_TOKEN_UNSIGNED_RIGHT_SHIFT, NJS_VMCODE_UNSIGNED_RIGHT_SHIFT },
}
};
@@ -112,12 +112,12 @@ static const njs_parser_expression_t
njs_parser_binary_expression,
&njs_parser_bitwise_shift_expression,
6, {
- { NJS_TOKEN_LESS, njs_vmcode_less },
- { NJS_TOKEN_LESS_OR_EQUAL, njs_vmcode_less_or_equal },
- { NJS_TOKEN_GREATER, njs_vmcode_greater },
- { NJS_TOKEN_GREATER_OR_EQUAL, njs_vmcode_greater_or_equal },
- { NJS_TOKEN_IN, njs_vmcode_property_in },
- { NJS_TOKEN_INSTANCEOF, njs_vmcode_instance_of },
+ { NJS_TOKEN_LESS, NJS_VMCODE_LESS },
+ { NJS_TOKEN_LESS_OR_EQUAL, NJS_VMCODE_LESS_OR_EQUAL },
+ { NJS_TOKEN_GREATER, NJS_VMCODE_GREATER },
+ { NJS_TOKEN_GREATER_OR_EQUAL, NJS_VMCODE_GREATER_OR_EQUAL },
+ { NJS_TOKEN_IN, NJS_VMCODE_PROPERTY_IN },
+ { NJS_TOKEN_INSTANCEOF, NJS_VMCODE_INSTANCE_OF },
}
};
@@ -128,10 +128,10 @@ static const njs_parser_expression_t
njs_parser_binary_expression,
&njs_parser_relational_expression,
4, {
- { NJS_TOKEN_EQUAL, njs_vmcode_equal },
- { NJS_TOKEN_NOT_EQUAL, njs_vmcode_not_equal },
- { NJS_TOKEN_STRICT_EQUAL, njs_vmcode_strict_equal },
- { NJS_TOKEN_STRICT_NOT_EQUAL, njs_vmcode_strict_not_equal },
+ { NJS_TOKEN_EQUAL, NJS_VMCODE_EQUAL },
+ { NJS_TOKEN_NOT_EQUAL, NJS_VMCODE_NOT_EQUAL },
+ { NJS_TOKEN_STRICT_EQUAL, NJS_VMCODE_STRICT_EQUAL },
+ { NJS_TOKEN_STRICT_NOT_EQUAL, NJS_VMCODE_STRICT_NOT_EQUAL },
}
};
@@ -142,7 +142,7 @@ static const njs_parser_expression_t
njs_parser_binary_expression,
&njs_parser_equality_expression,
1, {
- { NJS_TOKEN_BITWISE_AND, njs_vmcode_bitwise_and },
+ { NJS_TOKEN_BITWISE_AND, NJS_VMCODE_BITWISE_AND },
}
};
@@ -153,7 +153,7 @@ static const njs_parser_expression_t
njs_parser_binary_expression,
&njs_parser_bitwise_and_expression,
1, {
- { NJS_TOKEN_BITWISE_XOR, njs_vmcode_bitwise_xor },
+ { NJS_TOKEN_BITWISE_XOR, NJS_VMCODE_BITWISE_XOR },
}
};
@@ -164,7 +164,7 @@ static const njs_parser_expression_t
njs_parser_binary_expression,
&njs_parser_bitwise_xor_expression,
1, {
- { NJS_TOKEN_BITWISE_OR, njs_vmcode_bitwise_or },
+ { NJS_TOKEN_BITWISE_OR, NJS_VMCODE_BITWISE_OR },
}
};
@@ -175,7 +175,7 @@ static const njs_parser_expression_t
njs_parser_binary_expression,
&njs_parser_bitwise_or_expression,
1, {
- { NJS_TOKEN_LOGICAL_AND, njs_vmcode_test_if_false },
+ { NJS_TOKEN_LOGICAL_AND, NJS_VMCODE_TEST_IF_FALSE },
}
};
@@ -186,7 +186,7 @@ static const njs_parser_expression_t
njs_parser_binary_expression,
&njs_parser_logical_and_expression,
1, {
- { NJS_TOKEN_LOGICAL_OR, njs_vmcode_test_if_true },
+ { NJS_TOKEN_LOGICAL_OR, NJS_VMCODE_TEST_IF_TRUE },
}
};
@@ -197,7 +197,7 @@ static const njs_parser_expression_t
njs_parser_any_expression,
NULL,
1, {
- { NJS_TOKEN_COMMA, NULL },
+ { NJS_TOKEN_COMMA, NJS_VMCODE_NOP },
}
};
@@ -235,67 +235,67 @@ njs_parser_assignment_expression(njs_vm_
case NJS_TOKEN_ASSIGNMENT:
nxt_thread_log_debug("JS: =");
- operation = njs_vmcode_move;
+ operation = NJS_VMCODE_MOVE;
break;
case NJS_TOKEN_ADDITION_ASSIGNMENT:
nxt_thread_log_debug("JS: +=");
- operation = njs_vmcode_addition;
+ operation = NJS_VMCODE_ADDITION;
break;
case NJS_TOKEN_SUBSTRACTION_ASSIGNMENT:
nxt_thread_log_debug("JS: -=");
- operation = njs_vmcode_substraction;
+ operation = NJS_VMCODE_SUBSTRACTION;
break;
case NJS_TOKEN_MULTIPLICATION_ASSIGNMENT:
nxt_thread_log_debug("JS: *=");
- operation = njs_vmcode_multiplication;
+ operation = NJS_VMCODE_MULTIPLICATION;
break;
case NJS_TOKEN_EXPONENTIATION_ASSIGNMENT:
nxt_thread_log_debug("JS: **=");
- operation = njs_vmcode_exponentiation;
+ operation = NJS_VMCODE_EXPONENTIATION;
break;
case NJS_TOKEN_DIVISION_ASSIGNMENT:
nxt_thread_log_debug("JS: /=");
- operation = njs_vmcode_division;
+ operation = NJS_VMCODE_DIVISION;
break;
case NJS_TOKEN_REMAINDER_ASSIGNMENT:
nxt_thread_log_debug("JS: %=");
More information about the nginx-devel
mailing list