[njs] The njs_vm_continuation() macro.
Igor Sysoev
igor at sysoev.ru
Tue Mar 28 16:24:56 UTC 2017
details: http://hg.nginx.org/njs/rev/705129b55888
branches:
changeset: 318:705129b55888
user: Igor Sysoev <igor at sysoev.ru>
date: Tue Mar 21 16:35:22 2017 +0300
description:
The njs_vm_continuation() macro.
diffstat:
njs/njs_array.c | 42 +++++++++++++++++++++---------------------
njs/njs_date.c | 2 +-
njs/njs_function.c | 6 +++---
njs/njs_function.h | 5 ++++-
njs/njs_string.c | 6 +++---
njs/njs_vm.c | 4 ++--
6 files changed, 34 insertions(+), 31 deletions(-)
diffs (302 lines):
diff -r 6887b2d46f87 -r 705129b55888 njs/njs_array.c
--- a/njs/njs_array.c Tue Mar 21 16:14:16 2017 +0300
+++ b/njs/njs_array.c Tue Mar 21 16:35:22 2017 +0300
@@ -701,7 +701,7 @@ njs_array_prototype_to_string(njs_vm_t *
njs_continuation_t *cont;
nxt_lvlhsh_query_t lhq;
- cont = (njs_continuation_t *) njs_continuation(vm->frame);
+ cont = njs_vm_continuation(vm);
cont->function = njs_array_prototype_to_string_continuation;
if (njs_is_object(&args[0])) {
@@ -751,7 +751,7 @@ njs_array_prototype_join(njs_vm_t *vm, n
goto empty;
}
- join = (njs_array_join_t *) njs_continuation(vm->frame);
+ join = njs_vm_continuation(vm);
join->values = NULL;
join->max = 0;
max = 0;
@@ -774,7 +774,7 @@ njs_array_prototype_join(njs_vm_t *vm, n
return NXT_ERROR;
}
- join = (njs_array_join_t *) njs_continuation(vm->frame);
+ join = njs_vm_continuation(vm);
join->cont.function = njs_array_prototype_join_continuation;
join->values = values;
join->max = max;
@@ -820,7 +820,7 @@ njs_array_prototype_join_continuation(nj
njs_array_join_t *join;
njs_string_prop_t separator, string;
- join = (njs_array_join_t *) njs_continuation(vm->frame);
+ join = njs_vm_continuation(vm);
values = join->values;
max = join->max;
@@ -1177,7 +1177,7 @@ njs_array_prototype_for_each(njs_vm_t *v
return ret;
}
- iter = njs_continuation(vm->frame);
+ iter = njs_vm_continuation(vm);
iter->u.cont.function = njs_array_prototype_for_each_continuation;
return njs_array_prototype_for_each_continuation(vm, args, nargs, unused);
@@ -1190,7 +1190,7 @@ njs_array_prototype_for_each_continuatio
{
njs_array_iter_t *iter;
- iter = njs_continuation(vm->frame);
+ iter = njs_vm_continuation(vm);
if (iter->next_index >= args[0].data.u.array->length) {
vm->retval = njs_value_void;
@@ -1213,7 +1213,7 @@ njs_array_prototype_some(njs_vm_t *vm, n
return ret;
}
- iter = njs_continuation(vm->frame);
+ iter = njs_vm_continuation(vm);
iter->u.cont.function = njs_array_prototype_some_continuation;
iter->retval.data.truth = 0;
@@ -1228,7 +1228,7 @@ njs_array_prototype_some_continuation(nj
njs_array_iter_t *iter;
const njs_value_t *retval;
- iter = njs_continuation(vm->frame);
+ iter = njs_vm_continuation(vm);
if (njs_is_true(&iter->retval)) {
retval = &njs_value_true;
@@ -1258,7 +1258,7 @@ njs_array_prototype_every(njs_vm_t *vm,
return ret;
}
- iter = njs_continuation(vm->frame);
+ iter = njs_vm_continuation(vm);
iter->u.cont.function = njs_array_prototype_every_continuation;
iter->retval.data.truth = 1;
@@ -1273,7 +1273,7 @@ njs_array_prototype_every_continuation(n
njs_array_iter_t *iter;
const njs_value_t *retval;
- iter = njs_continuation(vm->frame);
+ iter = njs_vm_continuation(vm);
if (!njs_is_true(&iter->retval)) {
retval = &njs_value_false;
@@ -1366,7 +1366,7 @@ njs_array_prototype_filter(njs_vm_t *vm,
return ret;
}
- filter = njs_continuation(vm->frame);
+ filter = njs_vm_continuation(vm);
filter->iter.u.cont.function = njs_array_prototype_filter_continuation;
filter->iter.retval.data.truth = 0;
@@ -1387,7 +1387,7 @@ njs_array_prototype_filter_continuation(
njs_array_t *array;
njs_array_filter_t *filter;
- filter = njs_continuation(vm->frame);
+ filter = njs_vm_continuation(vm);
if (njs_is_true(&filter->iter.retval)) {
ret = njs_array_add(vm, filter->array, &filter->value);
@@ -1428,7 +1428,7 @@ njs_array_prototype_map(njs_vm_t *vm, nj
return ret;
}
- map = njs_continuation(vm->frame);
+ map = njs_vm_continuation(vm);
map->iter.u.cont.function = njs_array_prototype_map_continuation;
njs_set_invalid(&map->iter.retval);
@@ -1458,7 +1458,7 @@ njs_array_prototype_map_continuation(njs
{
njs_array_map_t *map;
- map = njs_continuation(vm->frame);
+ map = njs_vm_continuation(vm);
if (njs_is_valid(&map->iter.retval)) {
map->array->start[map->index] = map->iter.retval;
@@ -1492,7 +1492,7 @@ njs_array_prototype_reduce(njs_vm_t *vm,
return ret;
}
- iter = njs_continuation(vm->frame);
+ iter = njs_vm_continuation(vm);
iter->u.cont.function = njs_array_prototype_reduce_continuation;
if (nargs > 2) {
@@ -1525,7 +1525,7 @@ njs_array_prototype_reduce_continuation(
njs_value_t arguments[5];
njs_array_iter_t *iter;
- iter = njs_continuation(vm->frame);
+ iter = njs_vm_continuation(vm);
if (iter->next_index >= args[0].data.u.array->length) {
vm->retval = iter->retval;
@@ -1562,7 +1562,7 @@ njs_array_iterator_args(njs_vm_t *vm, nj
if (nargs > 1 && njs_is_array(&args[0]) && njs_is_function(&args[1])) {
array = args[0].data.u.array;
- iter = njs_continuation(vm->frame);
+ iter = njs_vm_continuation(vm);
iter->length = array->length;
iter->next_index = njs_array_iterator_next(array, 0, array->length);
@@ -1640,7 +1640,7 @@ njs_array_prototype_reduce_right(njs_vm_
goto type_error;
}
- iter = njs_continuation(vm->frame);
+ iter = njs_vm_continuation(vm);
iter->u.cont.function = njs_array_prototype_reduce_right_continuation;
array = args[0].data.u.array;
@@ -1680,7 +1680,7 @@ njs_array_prototype_reduce_right_continu
njs_value_t arguments[5];
njs_array_iter_t *iter;
- iter = njs_continuation(vm->frame);
+ iter = njs_vm_continuation(vm);
if ((int32_t) iter->next_index < 0) {
vm->retval = iter->retval;
@@ -1764,7 +1764,7 @@ njs_array_prototype_sort(njs_vm_t *vm, n
if (njs_is_array(&args[0]) && args[0].data.u.array->length > 1) {
- sort = njs_continuation(vm->frame);
+ sort = njs_vm_continuation(vm);
sort->u.cont.function = njs_array_prototype_sort_continuation;
sort->current = 0;
sort->retval = njs_value_zero;
@@ -1797,7 +1797,7 @@ njs_array_prototype_sort_continuation(nj
array = args[0].data.u.array;
start = array->start;
- sort = njs_continuation(vm->frame);
+ sort = njs_vm_continuation(vm);
if (njs_is_number(&sort->retval)) {
diff -r 6887b2d46f87 -r 705129b55888 njs/njs_date.c
--- a/njs/njs_date.c Tue Mar 21 16:14:16 2017 +0300
+++ b/njs/njs_date.c Tue Mar 21 16:35:22 2017 +0300
@@ -1866,7 +1866,7 @@ njs_date_prototype_to_json(njs_vm_t *vm,
njs_continuation_t *cont;
nxt_lvlhsh_query_t lhq;
- cont = (njs_continuation_t *) njs_continuation(vm->frame);
+ cont = njs_vm_continuation(vm);
cont->function = njs_date_prototype_to_json_continuation;
if (njs_is_object(&args[0])) {
diff -r 6887b2d46f87 -r 705129b55888 njs/njs_function.c
--- a/njs/njs_function.c Tue Mar 21 16:14:16 2017 +0300
+++ b/njs/njs_function.c Tue Mar 21 16:35:22 2017 +0300
@@ -106,7 +106,7 @@ njs_function_native_frame(njs_vm_t *vm,
frame->nargs = function->args_offset + nargs;
frame->ctor = ctor;
- value = (njs_value_t *) ((u_char *) njs_continuation(frame) + reserve);
+ value = (njs_value_t *) (njs_continuation(frame) + reserve);
bound = function->bound;
@@ -265,7 +265,7 @@ njs_function_apply(njs_vm_t *vm, njs_fun
return ret;
}
- cont = njs_continuation(vm->frame);
+ cont = njs_vm_continuation(vm);
cont->function = function->u.native;
cont->args_types = function->args_types;
@@ -500,7 +500,7 @@ njs_function_activate(njs_vm_t *vm, njs_
/* Skip the "call/apply" method frame. */
vm->frame->previous->skip = 1;
- cont = njs_continuation(vm->frame);
+ cont = njs_vm_continuation(vm);
cont->function = function->u.native;
cont->args_types = function->args_types;
diff -r 6887b2d46f87 -r 705129b55888 njs/njs_function.h
--- a/njs/njs_function.h Tue Mar 21 16:14:16 2017 +0300
+++ b/njs/njs_function.h Tue Mar 21 16:35:22 2017 +0300
@@ -56,8 +56,11 @@ typedef struct {
} njs_continuation_t;
+#define njs_vm_continuation(vm) \
+ (void *) njs_continuation((vm)->frame)
+
#define njs_continuation(frame) \
- (void *) ((u_char *) frame + NJS_NATIVE_FRAME_SIZE)
+ ((u_char *) frame + NJS_NATIVE_FRAME_SIZE)
#define njs_continuation_size(size) \
nxt_align_size(sizeof(size), sizeof(njs_value_t))
diff -r 6887b2d46f87 -r 705129b55888 njs/njs_string.c
--- a/njs/njs_string.c Tue Mar 21 16:14:16 2017 +0300
+++ b/njs/njs_string.c Tue Mar 21 16:35:22 2017 +0300
@@ -2274,7 +2274,7 @@ njs_string_prototype_replace(njs_vm_t *v
goto original;
}
- r = njs_continuation(vm->frame);
+ r = njs_vm_continuation(vm);
r->utf8 = NJS_STRING_BYTE;
r->type = NJS_REGEXP_BYTE;
@@ -2521,7 +2521,7 @@ njs_string_replace_regexp_continuation(n
{
njs_string_replace_t *r;
- r = njs_continuation(vm->frame);
+ r = njs_vm_continuation(vm);
if (njs_is_string(&r->retval)) {
njs_string_replacement_copy(&r->part[1], &r->retval);
@@ -2640,7 +2640,7 @@ njs_string_replace_search_continuation(n
{
njs_string_replace_t *r;
- r = njs_continuation(vm->frame);
+ r = njs_vm_continuation(vm);
if (njs_is_string(&r->retval)) {
njs_string_replacement_copy(&r->part[1], &r->retval);
diff -r 6887b2d46f87 -r 705129b55888 njs/njs_vm.c
--- a/njs/njs_vm.c Tue Mar 21 16:14:16 2017 +0300
+++ b/njs/njs_vm.c Tue Mar 21 16:35:22 2017 +0300
@@ -2343,7 +2343,7 @@ njs_vmcode_function_call(njs_vm_t *vm, n
}
if (function->continuation_size != 0) {
- cont = njs_continuation(vm->frame);
+ cont = njs_vm_continuation(vm);
cont->function = function->u.native;
cont->args_types = function->args_types;
@@ -2594,8 +2594,8 @@ njs_vmcode_continuation(njs_vm_t *vm, nj
njs_native_frame_t *frame;
njs_continuation_t *cont;
+ cont = njs_vm_continuation(vm);
frame = vm->frame;
- cont = njs_continuation(frame);
args = frame->arguments - frame->function->args_offset;
if (cont->args_types != NULL) {
More information about the nginx-devel
mailing list