Skip to content

Commit cd32531

Browse files
author
runrevali
committed
[[ StdMlc ]] Update bitwise docs, code and tests
1 parent bc6cc51 commit cd32531

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

libscript/src/bitwise.mlc

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
This module specifies the syntax definitions and bindings for bitwise operations on integers in modular LiveCode.
2+
This module specifies the bitwise operations on integers included in the standard library of modular LiveCode.
33
*/
44

55
module com.livecode.bitwise
@@ -26,7 +26,9 @@ Example:
2626

2727
Description:
2828
Each bit of <Left> bitwise and <Right> is 1 if and only if both the corresponding bit of the binary representation of <Left> and that of <Right> is 1. Otherwise it is 0.
29-
29+
30+
Tags: Bitwise operations
31+
3032
*/
3133

3234
syntax BitwiseAnd is left binary operator with precedence 2
@@ -50,6 +52,7 @@ Example:
5052
Description:
5153
Each bit of <Left> bitwise or <Right> is 0 if and only if both the corresponding bit of the binary representation of <Left> and that of <Right> is 0. Otherwise it is 1.
5254

55+
Tags: Bitwise operations
5356
*/
5457

5558
syntax BitwiseOr is left binary operator with precedence 4
@@ -72,6 +75,7 @@ Example:
7275
Description:
7376
Each bit of <Left> bitwise xor <Right> is 1 if and only if exactly one of the corresponding bits of the binary representation of <Left> and that of <Right> is 1. Otherwise it is 0.
7477

78+
Tags: Bitwise operations
7579
*/
7680

7781
syntax BitwiseXor is left binary operator with precedence 3
@@ -85,6 +89,15 @@ Summary: Performs a bitwise NOT operation on the binary representation of
8589

8690
Operand: An expression which evaluates to an integer.
8791
output: The integer whose binary representation is the result of the bitwise NOT operation.
92+
93+
Example:
94+
variable tVar as int
95+
put bitwise not -5 into tVar -- tVar contains 4
96+
97+
Description:
98+
Bitwise not returns the complement of <Operand> as a signed 32-bit integer, thus is equivalent to -(x + 1).
99+
100+
Tags: Bitwise operations
88101
*/
89102

90103
syntax BitwiseNot is prefix operator with precedence 1
@@ -108,6 +121,8 @@ Example:
108121

109122
Description:
110123
Shifting the bits of <Operand> by x is equivalent to multiplying by 2^x
124+
125+
Tags: Bitwise operations
111126
*/
112127

113128
syntax BitwiseShift is postfix operator with precedence 1

libscript/src/module-bitwise.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ extern "C" MC_DLLEXPORT void MCBitwiseEvalBitwiseXor(integer_t p_left, integer_t
3333

3434
extern "C" MC_DLLEXPORT void MCBitwiseEvalBitwiseNot(integer_t p_operand, integer_t& r_output)
3535
{
36-
r_output = ~p_operand;
36+
r_output = ~((int32_t)p_operand);
3737
}
3838

3939
extern "C" MC_DLLEXPORT void MCBitwiseEvalBitwiseShift(integer_t p_operand, integer_t p_shift, integer_t& r_output)

toolchain/lc-compile/test.mlc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,8 @@ public handler testBitwise(inout xResults as list)
319319
put 3 bitwise xor 6 into tVar
320320
testLog("Bitwise", "BitwiseXor", tVar is 5, xResults)
321321

322-
--put bitwise not 0 into tVar
322+
put bitwise not 5 into tVar
323+
testLog("Bitwise", "BitwiseNot", tVar is - 6, xResults)
323324

324325
put 7 shifted by 2 bitwise into tVar
325326
testLog("Bitwise", "BitwiseShift", tVar is 28, xResults)
@@ -406,7 +407,6 @@ public handler testChar(inout xResults as list)
406407
put "abcde" after char 5 of tString
407408

408409
testLog("Char", "AfterCharOf", tString is "abcdeabcdeabcde", xResults)
409-
410410

411411
testLog("Char", "BeginsWithEmpty", tString begins with "", xResults)
412412
testLog("Char", "BeginsWith", tString begins with "abcd", xResults)

0 commit comments

Comments
 (0)