From: Igor Sysoev Date: Mon, 25 Jan 2016 12:15:00 +0000 (+0300) Subject: nJSVM current instruction pointer is updated now in X-Git-Tag: 0.1.0~79 X-Git-Url: http://www.kaiwu.me/postgresql/commit/?a=commitdiff_plain;h=2603dc886685584217b060499c104fcffb1beca3;p=njs.git nJSVM current instruction pointer is updated now in njs_function_call(). --- diff --git a/njs/njs_array.c b/njs/njs_array.c index 9b4e6f65..8425c3e3 100644 --- a/njs/njs_array.c +++ b/njs/njs_array.c @@ -732,8 +732,8 @@ njs_array_prototype_for_each(njs_vm_t *vm, njs_param_t *param) n = njs_array_next(array->start, ++n, next->length); next->index = n; - if (n > 0) { - vm->current -= sizeof(njs_vmcode_function_call_t); + if (n < 0) { + vm->current += sizeof(njs_vmcode_function_call_t); } nargs = param->nargs; @@ -810,8 +810,6 @@ njs_array_prototype_some(njs_vm_t *vm, njs_param_t *param) func = (nargs != 0) ? &args[0] : (njs_value_t *) &njs_value_void; - vm->current -= sizeof(njs_vmcode_function_call_t); - return njs_function_apply(vm, func, &p); } @@ -876,8 +874,6 @@ njs_array_prototype_every(njs_vm_t *vm, njs_param_t *param) func = (nargs != 0) ? &args[0] : (njs_value_t *) &njs_value_void; - vm->current -= sizeof(njs_vmcode_function_call_t); - return njs_function_apply(vm, func, &p); } diff --git a/njs/njs_function.c b/njs/njs_function.c index 59912702..8eacc35a 100644 --- a/njs/njs_function.c +++ b/njs/njs_function.c @@ -139,7 +139,7 @@ njs_function_apply(njs_vm_t *vm, njs_value_t *value, njs_param_t *param) if (nxt_fast_path(ret == NXT_OK)) { vm->retval = njs_value_void; - return njs_function_call(vm, param->retval); + return njs_function_call(vm, param->retval, 0); } } @@ -207,7 +207,7 @@ njs_function_frame(njs_vm_t *vm, njs_function_t *function, njs_param_t *param, nxt_noinline njs_ret_t -njs_function_call(njs_vm_t *vm, njs_index_t retval) +njs_function_call(njs_vm_t *vm, njs_index_t retval, size_t advance) { njs_frame_t *frame; njs_function_t *function; @@ -217,7 +217,7 @@ njs_function_call(njs_vm_t *vm, njs_index_t retval) frame->retval = retval; function = frame->native.u.function; - frame->native.u.return_address = vm->current; + frame->native.u.return_address = vm->current + advance; vm->current = function->u.lambda->u.start; frame->prev_arguments = vm->scopes[NJS_SCOPE_ARGUMENTS]; @@ -312,7 +312,8 @@ njs_function_prototype_call(njs_vm_t *vm, njs_param_t *param) call = (njs_vmcode_function_call_t *) vm->current; - return njs_function_call(vm, call->retval); + return njs_function_call(vm, call->retval, + sizeof(njs_vmcode_function_call_t)); } @@ -378,7 +379,8 @@ njs_function_prototype_apply(njs_vm_t *vm, njs_param_t *param) code = (njs_vmcode_function_call_t *) vm->current; - return njs_function_call(vm, code->retval); + return njs_function_call(vm, code->retval, + sizeof(njs_vmcode_function_call_t)); } return NXT_ERROR; diff --git a/njs/njs_function.h b/njs/njs_function.h index 7fa31ad5..3dc32e6c 100644 --- a/njs/njs_function.h +++ b/njs/njs_function.h @@ -123,7 +123,7 @@ njs_value_t *njs_function_native_frame(njs_vm_t *vm, njs_function_t *function, njs_vmcode_t *code); njs_ret_t njs_function_frame(njs_vm_t *vm, njs_function_t *function, njs_param_t *param, nxt_bool_t ctor); -njs_ret_t njs_function_call(njs_vm_t *vm, njs_index_t retval); +njs_ret_t njs_function_call(njs_vm_t *vm, njs_index_t retval, size_t advance); extern const njs_object_init_t njs_function_constructor_init; extern const njs_object_init_t njs_function_prototype_init; diff --git a/njs/njs_vm.c b/njs/njs_vm.c index 3db49495..10efda32 100644 --- a/njs/njs_vm.c +++ b/njs/njs_vm.c @@ -2230,16 +2230,14 @@ njs_vmcode_function_call(njs_vm_t *vm, njs_value_t *invld, njs_value_t *retval) njs_native_frame_t *frame, *previous, *skip; njs_vmcode_function_call_t *call; - call = (njs_vmcode_function_call_t *) vm->current; - /* Update code pointer here to store it as return address in call frame. */ - vm->current += sizeof(njs_vmcode_function_call_t); - if (!vm->frame->u.function->native) { - (void) njs_function_call(vm, (njs_index_t) retval); + (void) njs_function_call(vm, (njs_index_t) retval, + sizeof(njs_vmcode_function_call_t)); return 0; } param.retval = (njs_index_t) retval; + call = (njs_vmcode_function_call_t *) vm->current; param.nargs = call->code.nargs - 1; args = vm->scopes[NJS_SCOPE_CALLEE_ARGUMENTS]; param.args = args; @@ -2287,12 +2285,19 @@ njs_vmcode_function_call(njs_vm_t *vm, njs_value_t *invld, njs_value_t *retval) */ *retval = vm->retval; + ret = sizeof(njs_vmcode_function_call_t); + } else if (ret == NJS_APPLIED) { /* A user-defined method has been prepared to run. */ ret = 0; } else if (ret == NXT_AGAIN) { + /* + * Revert nJSVM current address, execution will + * continue on the same function after resumption. + */ vm->frame->reentrant = 1; + vm->current -= sizeof(njs_vmcode_function_call_t); } return ret;