Skip to content

Commit dd21497

Browse files
author
runrevali
committed
[[ StdMlc ]] Add left/right option to bitwise shift syntax
1 parent 86487b0 commit dd21497

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

libscript/src/bitwise.mlc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public foreign handler MCBitwiseEvalBitwiseOr(in Left as int, in Right as int, o
99
public foreign handler MCBitwiseEvalBitwiseNot(in Operand as int, out Value as int) as undefined binds to "<builtin>"
1010
public foreign handler MCBitwiseEvalBitwiseXor(in Left as int, in Right as int, out Value as int) as undefined binds to "<builtin>"
1111

12-
public foreign handler MCBitwiseEvalBitwiseShift(in Target as int, in Shift as int, out Value as int) as undefined binds to "<builtin>"
12+
public foreign handler MCBitwiseEvalBitwiseShift(in Target as int, in IsRight as bool, in Shift as int, out Value as int) as undefined binds to "<builtin>"
1313

1414
--
1515

@@ -125,15 +125,15 @@ Example:
125125
put 7 shifted by 2 bitwise into tVar -- tVar contains 28
126126

127127
Description:
128-
Shifting the bits of <Operand> by x is equivalent to multiplying by 2^x
128+
Shifts the bits of <Operand> left or right. If neither direction is specified, then shifts left. Shifting the bits of <Operand> left by x is equivalent to multiplying by 2^x. Shifting by a negative value is equivalent to shifting by its absolute value in the opposite direction.
129129

130130
Tags: Bitwise operations
131131
*/
132132

133133
syntax BitwiseShift is postfix operator with precedence 1
134-
<Operand: Expression> "shifted" "by" <Shift: Expression> "bitwise"
134+
<Operand: Expression> "shifted" ("left" <IsRight=false> | "right" <IsRight=true> | <IsRight=false>) "by" <Shift: Expression> "bitwise"
135135
begin
136-
MCBitwiseEvalBitwiseShift(Operand, Shift, output)
136+
MCBitwiseEvalBitwiseShift(Operand, IsRight, Shift, output)
137137
end syntax
138138

139139
--

libscript/src/module-bitwise.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ extern "C" MC_DLLEXPORT void MCBitwiseEvalBitwiseNot(integer_t p_operand, intege
3636
r_output = ~((int32_t)p_operand);
3737
}
3838

39-
extern "C" MC_DLLEXPORT void MCBitwiseEvalBitwiseShift(integer_t p_operand, integer_t p_shift, integer_t& r_output)
39+
extern "C" MC_DLLEXPORT void MCBitwiseEvalBitwiseShift(integer_t p_operand, bool p_is_right, integer_t p_shift, integer_t& r_output)
4040
{
41-
if (p_shift < 0)
41+
if (p_shift < 0 != p_is_right)
4242
// truncate towards 0
4343
r_output = (integer_t)(p_operand >> abs(p_shift));
4444
else

0 commit comments

Comments
 (0)