0
0
mirror of https://github.com/vim/vim.git synced 2025-09-25 03:54:15 -04:00

patch 8.2.5003: cannot do bitwise shifts

Problem:    Cannot do bitwise shifts.
Solution:   Add the >> and << operators. (Yegappan Lakshmanan, closes #8457)
This commit is contained in:
Yegappan Lakshmanan
2022-05-22 19:13:49 +01:00
committed by Bram Moolenaar
parent 9b2edfd3bf
commit a061f34191
11 changed files with 554 additions and 160 deletions

View File

@@ -4055,6 +4055,17 @@ exec_instructions(ectx_T *ectx)
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 @@ exec_instructions(ectx_T *ectx)
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 @@ list_instructions(char *pfx, isn_T *instr, int instr_count, ufunc_T *ufunc)
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)