Skip to content

Commit 6410b91

Browse files
author
runrevali
committed
[[ StdMlc ]] Overload is and is not for logic
1 parent e4b7d02 commit 6410b91

File tree

5 files changed

+58
-7
lines changed

5 files changed

+58
-7
lines changed

libscript/src/binary.mlc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ output: Returns false if the result of evaluating <Left> is the same as that
102102

103103
*/
104104

105-
syntax IsNotEqualTo is neutral binary operator with precedence 1
105+
syntax IsNotEqualTo is neutral binary operator with precedence 5
106106
<Left: Expression> "is not" <Right: Expression>
107107
begin
108108
MCBinaryEvalIsNotEqualTo(Left, Right, output)

libscript/src/logic.mlc

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ module com.livecode.logic
33
//foreign handler MCLogicEvalAnd(in Left as bool, in Right as bool, out Value as bool) as undefined binds to "<builtin>"
44
//foreign handler MCLogicEvalOr(in Left as bool, in Right as bool, out Value as bool) as undefined binds to "<builtin>"
55
public foreign handler MCLogicEvalNot(in Operand as bool, out Value as bool) as undefined binds to "<builtin>"
6+
public foreign handler MCLogicEvalIsEqualTo(in Left as bool, in Right as bool, out Value as bool) as undefined binds to "<builtin>"
7+
public foreign handler MCLogicEvalIsNotEqualTo(in Left as bool, in Right as bool, out Value as bool) as undefined binds to "<builtin>"
68

79
--
810

@@ -54,4 +56,36 @@ end syntax
5456

5557
--
5658

59+
/*
60+
Summary: Determines whether <Left> and <Right> are equal or not.
61+
62+
Left: An expression which evaluates to a bool.
63+
Right: An expression which evaluates to a bool.
64+
65+
output: Returns true if <Left> evaluates to the same value as <Right>.
66+
67+
*/
68+
69+
syntax IsEqualTo is neutral binary operator with precedence 5
70+
<Left: Expression> "is" <Right: Expression>
71+
begin
72+
MCLogicEvalIsEqualTo(Left, Right, output)
73+
end syntax
74+
75+
/*
76+
Summary: Determines whether <Left> and <Right> are equal or not.
77+
78+
Left: An expression which evaluates to a bool.
79+
Right: An expression which evaluates to a bool.
80+
81+
output: Returns true if <Left> evaluates to the opposite boolean value as <Right>.
82+
83+
*/
84+
85+
syntax IsNotEqualTo is neutral binary operator with precedence 5
86+
<Left: Expression> "is not" <Right: Expression>
87+
begin
88+
MCLogicEvalIsNotEqualTo(Left, Right, output)
89+
end syntax
90+
5791
end module

libscript/src/module-logic.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,14 @@
1717
extern "C" void MCLogicEvalNot(bool p_bool, bool& r_result)
1818
{
1919
r_result = !p_bool;
20+
}
21+
22+
extern "C" void MCLogicEvalIsEqualTo(bool p_left, bool p_right, bool& r_result)
23+
{
24+
r_result = (p_left == p_right);
25+
}
26+
27+
extern "C" void MCLogicEvalIsNotEqualTo(bool p_left, bool p_right, bool& r_result)
28+
{
29+
r_result = (p_left != p_right);
2030
}

libscript/src/string.mlc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ Description:
200200
The ```is not``` operator is case sensitive.
201201
*/
202202

203-
syntax IsNotEqualTo is neutral binary operator with precedence 1
203+
syntax IsNotEqualTo is neutral binary operator with precedence 5
204204
<Left: Expression> "is not" <Right: Expression>
205205
begin
206206
MCStringEvalIsNotEqualTo(Left, Right, output)

toolchain/lc-compile/test.mlc

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,7 @@ public handler testArray(inout xResults as list)
100100
testLog("Array", "ElementsOf", "value2" is in tElements, xResults)
101101
testLog("Array", "ElementsOf", "value3" is in tElements, xResults)
102102

103-
testLog("Array", "IsAmongTheKeys", "key1" is among the keys of tArray, xResults)
104-
103+
--testLog("Array", "IsAmongTheKeys", "key1" is among the keys of tArray, xResults)
105104
--testLog("Array", "IsAmongTheElements", "value1" is among the keys of tArray, xResults)
106105

107106
testLog("Array", "ElementOf", tArray["key1"] is "value1", xResults)
@@ -128,10 +127,18 @@ public handler testBitwise(inout xResults as list)
128127
end handler
129128

130129
public handler testLogic(inout xResults as list)
131-
variable tVar as bool
132-
put not false into tVar
133130

134-
testLog("Logic", "Not", tVar, xResults)
131+
testLog("Logic", "Not", not false, xResults)
132+
testLog("Logic", "Not", not not true, xResults)
133+
134+
testLog("Logic", "Is", true is true, xResults)
135+
testLog("Logic", "Is", false is false, xResults)
136+
137+
testLog("Logic", "Is", true is not false, xResults)
138+
testLog("Logic", "Is", false is not true, xResults)
139+
140+
testLog("Logic", "Is", not true is false, xResults)
141+
testLog("Logic", "Is", not false is true, xResults)
135142

136143
// test boolean short circuit
137144

0 commit comments

Comments
 (0)