[njs] Added njs_set_int32() and njs_set_uint32() intrinsics.
Dmitry Volyntsev
xeioex at nginx.com
Fri Jul 19 20:28:16 UTC 2019
details: https://hg.nginx.org/njs/rev/8b977c78885f
branches:
changeset: 1062:8b977c78885f
user: Dmitry Volyntsev <xeioex at nginx.com>
date: Fri Jul 19 22:05:34 2019 +0300
description:
Added njs_set_int32() and njs_set_uint32() intrinsics.
diffstat:
njs/njs_value.h | 18 ++++++++++++++++++
njs/njs_vm.c | 14 +++++++-------
2 files changed, 25 insertions(+), 7 deletions(-)
diffs (94 lines):
diff -r 540f03725df2 -r 8b977c78885f njs/njs_value.h
--- a/njs/njs_value.h Tue Jul 16 22:44:16 2019 -0400
+++ b/njs/njs_value.h Fri Jul 19 22:05:34 2019 +0300
@@ -621,6 +621,24 @@ njs_set_number(njs_value_t *value, doubl
nxt_inline void
+njs_set_int32(njs_value_t *value, int32_t num)
+{
+ value->data.u.number = num;
+ value->type = NJS_NUMBER;
+ value->data.truth = (num != 0);
+}
+
+
+nxt_inline void
+njs_set_uint32(njs_value_t *value, uint32_t num)
+{
+ value->data.u.number = num;
+ value->type = NJS_NUMBER;
+ value->data.truth = (num != 0);
+}
+
+
+nxt_inline void
njs_set_data(njs_value_t *value, void *data)
{
value->data.u.data = data;
diff -r 540f03725df2 -r 8b977c78885f njs/njs_vm.c
--- a/njs/njs_vm.c Tue Jul 16 22:44:16 2019 -0400
+++ b/njs/njs_vm.c Fri Jul 19 22:05:34 2019 +0300
@@ -1375,7 +1375,7 @@ njs_vmcode_left_shift(njs_vm_t *vm, njs_
num1 = njs_number_to_int32(njs_number(val1));
num2 = njs_number_to_uint32(njs_number(val2));
- njs_set_number(&vm->retval, num1 << (num2 & 0x1f));
+ njs_set_int32(&vm->retval, num1 << (num2 & 0x1f));
return sizeof(njs_vmcode_3addr_t);
}
@@ -1409,7 +1409,7 @@ njs_vmcode_right_shift(njs_vm_t *vm, njs
num1 = njs_number_to_int32(njs_number(val1));
num2 = njs_number_to_uint32(njs_number(val2));
- njs_set_number(&vm->retval, num1 >> (num2 & 0x1f));
+ njs_set_int32(&vm->retval, num1 >> (num2 & 0x1f));
return sizeof(njs_vmcode_3addr_t);
}
@@ -1443,7 +1443,7 @@ njs_vmcode_unsigned_right_shift(njs_vm_t
num1 = njs_number_to_uint32(njs_number(val1));
num2 = njs_number_to_uint32(njs_number(val2));
- njs_set_number(&vm->retval, num1 >> (num2 & 0x1f));
+ njs_set_uint32(&vm->retval, num1 >> (num2 & 0x1f));
return sizeof(njs_vmcode_3addr_t);
}
@@ -1505,7 +1505,7 @@ njs_vmcode_bitwise_not(njs_vm_t *vm, njs
value = &numeric;
}
- njs_set_number(&vm->retval, ~njs_number_to_integer(njs_number(value)));
+ njs_set_int32(&vm->retval, ~njs_number_to_integer(njs_number(value)));
return sizeof(njs_vmcode_2addr_t);
}
@@ -1538,7 +1538,7 @@ njs_vmcode_bitwise_and(njs_vm_t *vm, njs
num1 = njs_number_to_integer(njs_number(val1));
num2 = njs_number_to_integer(njs_number(val2));
- njs_set_number(&vm->retval, num1 & num2);
+ njs_set_int32(&vm->retval, num1 & num2);
return sizeof(njs_vmcode_3addr_t);
}
@@ -1571,7 +1571,7 @@ njs_vmcode_bitwise_xor(njs_vm_t *vm, njs
num1 = njs_number_to_integer(njs_number(val1));
num2 = njs_number_to_integer(njs_number(val2));
- njs_set_number(&vm->retval, num1 ^ num2);
+ njs_set_int32(&vm->retval, num1 ^ num2);
return sizeof(njs_vmcode_3addr_t);
}
@@ -1604,7 +1604,7 @@ njs_vmcode_bitwise_or(njs_vm_t *vm, njs_
num1 = njs_number_to_integer(njs_number(val1));
num2 = njs_number_to_integer(njs_number(val2));
- njs_set_number(&vm->retval, num1 | num2);
+ njs_set_int32(&vm->retval, num1 | num2);
return sizeof(njs_vmcode_3addr_t);
}
More information about the nginx-devel
mailing list