patch 8.2.5003: cannot do bitwise shifts
Problem: Cannot do bitwise shifts.
Solution: Add the >> and << operators. (Yegappan Lakshmanan, closes #8457)
diff --git a/src/vim9execute.c b/src/vim9execute.c
index b191dc9..b4fd9d5 100644
--- a/src/vim9execute.c
+++ b/src/vim9execute.c
@@ -4055,6 +4055,17 @@
varnumber_T res = 0;
int div_zero = FALSE;
+ if (iptr->isn_arg.op.op_type == EXPR_LSHIFT
+ || iptr->isn_arg.op.op_type == EXPR_RSHIFT)
+ {
+ if (arg2 < 0)
+ {
+ SOURCING_LNUM = iptr->isn_lnum;
+ emsg(_(e_bitshift_ops_must_be_postive));
+ goto on_error;
+ }
+ }
+
switch (iptr->isn_arg.op.op_type)
{
case EXPR_MULT: res = arg1 * arg2; break;
@@ -4077,6 +4088,21 @@
case EXPR_GEQUAL: res = arg1 >= arg2; break;
case EXPR_SMALLER: res = arg1 < arg2; break;
case EXPR_SEQUAL: res = arg1 <= arg2; break;
+ case EXPR_LSHIFT: if (arg2 > MAX_LSHIFT_BITS)
+ res = 0;
+ else
+ res = arg1 << arg2;
+ break;
+ case EXPR_RSHIFT: if (arg2 > MAX_LSHIFT_BITS)
+ res = 0;
+ else
+ {
+ res = arg1 >> arg2;
+ // clear the topmost sign bit
+ res &= ~((uvarnumber_T)1
+ << MAX_LSHIFT_BITS);
+ }
+ break;
default: break;
}
@@ -6016,6 +6042,8 @@
case EXPR_REM: what = "%"; break;
case EXPR_SUB: what = "-"; break;
case EXPR_ADD: what = "+"; break;
+ case EXPR_LSHIFT: what = "<<"; break;
+ case EXPR_RSHIFT: what = ">>"; break;
default: what = "???"; break;
}
switch (iptr->isn_type)