Skip to content

Commit 1b4c9ed

Browse files
author
runrevali
committed
[[ StdMlc ]] Fix some errors in mlc files
1 parent 7ef3373 commit 1b4c9ed

File tree

11 files changed

+117
-65
lines changed

11 files changed

+117
-65
lines changed

libscript/src/arithmetic.mlc

Lines changed: 65 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ public foreign handler MCArithmeticExecAddNumberToNumber(in Value as number, ino
88
public foreign handler MCArithmeticExecSubtractIntegerFromInteger(in Value as int, inout Target as int) as undefined binds to "<builtin>"
99
public foreign handler MCArithmeticExecSubtractRealFromReal(in Value as real, inout Target as real) as undefined binds to "<builtin>"
1010
public foreign handler MCArithmeticExecSubtractNumberFromNumber(in Value as number, inout Target as number) as undefined binds to "<builtin>"
11-
public foreign handler MCArithmeticExecMultiplyIntegerByInteger(in Value as int, inout Target as int) as undefined binds to "<builtin>"
12-
public foreign handler MCArithmeticExecMultiplyRealByReal(in Value as double, inout Target as double) as undefined binds to "<builtin>"
13-
public foreign handler MCArithmeticExecMultiplyNumberByNumber(in Value as number, inout Target as number) as undefined binds to "<builtin>"
14-
public foreign handler MCArithmeticExecDivideIntegerByInteger(in Value as int, inout Target as int) as undefined binds to "<builtin>"
15-
public foreign handler MCArithmeticExecDivideRealByReal(in Value as double, inout Target as double) as undefined binds to "<builtin>"
16-
public foreign handler MCArithmeticExecDivideNumberByNumber(in Value as number, inout Target as number) as undefined binds to "<builtin>"
11+
public foreign handler MCArithmeticExecMultiplyIntegerByInteger(inout Target as int, in Value as int) as undefined binds to "<builtin>"
12+
public foreign handler MCArithmeticExecMultiplyRealByReal(inout Target as double, in Value as double) as undefined binds to "<builtin>"
13+
public foreign handler MCArithmeticExecMultiplyNumberByNumber(inout Target as number, in Value as number) as undefined binds to "<builtin>"
14+
public foreign handler MCArithmeticExecDivideIntegerByInteger(inout Target as int, in Value as int) as undefined binds to "<builtin>"
15+
public foreign handler MCArithmeticExecDivideRealByReal(inout Target as double, in Value as double) as undefined binds to "<builtin>"
16+
public foreign handler MCArithmeticExecDivideNumberByNumber(inout Target as number, in Value as number) as undefined binds to "<builtin>"
1717

1818
public foreign handler MCArithmeticEvalPlusInteger(in Operand as int, out Value as int) as undefined binds to "<builtin>"
1919
public foreign handler MCArithmeticEvalPlusReal(in Operand as double, out Value as double) as undefined binds to "<builtin>"
@@ -64,6 +64,15 @@ Summary: Adds <Value> to <Target>.
6464
Target: An expression that evaluates to a numeric container.
6565
Value: An expression that evaluates to a number.
6666

67+
Example:
68+
variable tVar as int
69+
put 2 into tVar
70+
add 10 to tVar -- tVar contains 12
71+
72+
Description:
73+
Adds the number <Value> to <Target>.
74+
75+
>Note: It is a syntax error if <Target> does not evaluate to a variable.
6776
*/
6877

6978
syntax AddNumberTo is statement
@@ -77,9 +86,19 @@ end syntax
7786

7887
/*
7988
Summary: Subtracts <Value> from <Target>.
80-
Target: An expression that evaluates to a numeric container.
89+
Target: An expression that evaluates to a numeric variable.
8190
Value: An expression that evaluates to a number.
8291

92+
Example:
93+
variable tVar as real
94+
put 10 into tVar
95+
subtract 2.5 from tVar -- tVar contains 7.5
96+
97+
Description:
98+
Subtracts the number <Value> from <Target>.
99+
100+
>Note: It is a syntax error if <Target> does not evaluate to a variable.
101+
83102
*/
84103

85104
syntax SubtractNumberFrom is statement
@@ -92,32 +111,53 @@ end syntax
92111

93112
/*
94113
Summary: Multiplies <Target> by <Value>.
95-
Target: An expression that evaluates to a numeric container.
114+
Target: An expression that evaluates to a numeric variable.
96115
Value: An expression that evaluates to a number.
97116

117+
Example:
118+
variable tVar as int
119+
put 2 into tVar
120+
multiply tVar by 2 -- tVar contains 4
121+
122+
Description:
123+
Multiplies the number <Target> by <Value>.
124+
125+
>Note: It is a syntax error if <Target> does not evaluate to a variable.
98126
*/
99127

100128
syntax MultiplyNumberBy is statement
101-
"multiply" <Value: Expression> "by" <Target: Expression>
129+
"multiply" <Target: Expression> "by" <Value: Expression>
102130
begin
103-
MCArithmeticExecMultiplyIntegerByInteger(Value, Target)
104-
MCArithmeticExecMultiplyRealByReal(Value, Target)
105-
MCArithmeticExecMultiplyNumberByNumber(Value, Target)
131+
MCArithmeticExecMultiplyIntegerByInteger(Target, Value)
132+
MCArithmeticExecMultiplyRealByReal(Target, Value)
133+
MCArithmeticExecMultiplyNumberByNumber(Target, Value)
106134
end syntax
107135

108136
/*
109137
Summary: Divides <Target> by <Value>.
110-
Target: An expression that evaluates to a numeric container.
138+
Target: An expression that evaluates to a numeric variable.
111139
Value: An expression that evaluates to a number.
112140

141+
Example:
142+
variable tVar
143+
put 3 into tVar
144+
divide tVar by 2 -- tVar contains 1.5
145+
146+
Description:
147+
Divides the number <Target> by <Value>.
148+
149+
150+
151+
>Note: It is a syntax error if <Target> does not evaluate to a variable.
152+
113153
*/
114154

115155
syntax DivideNumberBy is statement
116-
"divide" <Value: Expression> "by" <Target: Expression>
156+
"divide" <Target: Expression> "by" <Value: Expression>
117157
begin
118-
MCArithmeticExecDivideIntegerByInteger(Value, Target)
119-
MCArithmeticExecDivideRealByReal(Value, Target)
120-
MCArithmeticExecDivideNumberByNumber(Value, Target)
158+
MCArithmeticExecDivideIntegerByInteger(Target, Value)
159+
MCArithmeticExecDivideRealByReal(Target, Value)
160+
MCArithmeticExecDivideNumberByNumber(Target, Value)
121161
end syntax
122162

123163
--
@@ -318,10 +358,17 @@ output: True if <Left> is equal to <Right>, and false otherwise.
318358
*/
319359

320360

321-
syntax IsEqualTo is neutral binary operator with precedence 3
361+
syntax IsEqualTo is neutral binary operator with precedence 4
322362
<Left: Expression> "=" <Right: Expression>
323363
begin
324364
MCArithmeticEvalEqualToInteger(Left, Right, output)
325365
end syntax
326366

367+
368+
syntax IsNumber is neutral binary operator with precedence 5
369+
<Left: Expression> "is" <Right: Expression>
370+
begin
371+
MCArithmeticEvalEqualToInteger(Left, Right, output)
372+
end syntax
373+
327374
end module

libscript/src/binary.mlc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ output: Returns true if the result of evaluating <Left> is the same as that
7979

8080
*/
8181

82-
syntax IsEqualTo is neutral binary operator with precedence 1
82+
syntax IsEqualTo is neutral binary operator with precedence 5
8383
<Left: Expression> "is" <Right: Expression>
8484
begin
8585
MCBinaryEvalIsEqualTo(Left, Right, output)
@@ -95,7 +95,7 @@ output: Returns false if the result of evaluating <Left> is the same as that
9595

9696
*/
9797

98-
syntax IsNotEqualTo is neutral binary operator with precedence 1
98+
syntax IsNotEqualTo is neutral binary operator with precedence 5
9999
<Left: Expression> "is" "not" <Right: Expression>
100100
begin
101101
MCBinaryEvalIsNotEqualTo(Left, Right, output)

libscript/src/byte.mlc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ output: Returns the number of bytes between the first byte of <Targe
5959
*/
6060

6161
syntax ByteOffset is prefix operator with precedence 1
62-
"the" ["first" <IsLast=false> | "last" <IsLast=true>] "offset" "of" "bytes" <Needle: Expression> "in" <Target: Expression>
62+
"the" ( "first" <IsLast=false> | "last" <IsLast=true> | <IsLast=false> ) "offset" "of" "bytes" <Needle: Expression> "in" <Target: Expression>
6363
begin
6464
EvalOffsetOfBytes(IsLast, Needle, Target, output)
6565
end syntax
@@ -77,7 +77,7 @@ output: Returns the number of bytes between the first byte of <Targe
7777
*/
7878

7979
syntax ByteOffsetAfter is prefix operator with precedence 1
80-
"the" ["first" <IsLast=false> | "last" <IsLast=true>] "offset" "of" "bytes" <Needle: Expression> "after" <After: Expression> "in" <Target: Expression>
80+
"the" ( "first" <IsLast=false> | "last" <IsLast=true> | <IsLast=false> ) "offset" "of" "bytes" <Needle: Expression> "after" <After: Expression> "in" <Target: Expression>
8181
begin
8282
EvalOffsetOfBytesAfter(IsLast, Needle, After, Target, output)
8383
end syntax
@@ -96,7 +96,7 @@ output: Returns the number of bytes between the first byte of <Targe
9696
*/
9797

9898
syntax ByteOffsetBefore is prefix operator with precedence 1
99-
"the" ["first" <IsFirst=true> | "last" <IsFirst=false>] "offset" "of" "bytes" <Needle: Expression> "before" <Before: Expression> "in" <Target: Expression>
99+
"the" ( "first" <IsFirst=true> | "last" <IsFirst=false> | <IsFirst=false> ) "offset" "of" "bytes" <Needle: Expression> "before" <Before: Expression> "in" <Target: Expression>
100100
begin
101101
EvalOffsetOfBytesBefore(IsFirst, Needle, Before, Target, output)
102102
end syntax

libscript/src/char.mlc

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ public foreign handler MCCharEvalOffsetOfChars(in IsLast as bool, in Needle as s
1616
public foreign handler MCCharEvalOffsetOfCharsBefore(in IsLast as bool, in Needle as string, in Before as index, in Target as string, out Offset as index) as undefined binds to "<builtin>"
1717
public foreign handler MCCharEvalOffsetOfCharsAfter(in IsFirst as bool, in Needle as string, in After as index, in Target as string, out Offset as index) as undefined binds to "<builtin>"
1818

19+
public foreign handler MCCharEvalNewlineCharacter(out Value as string) as undefined binds to "<builtin>"
20+
1921
--
2022

2123
/*
@@ -123,7 +125,7 @@ output: Returns the number of chars between the first char of <Targe
123125
*/
124126

125127
syntax CharOffset is prefix operator with precedence 1
126-
"the" ["first" <IsLast=false> | "last" <IsLast=true>] "offset" "of" ["chars"] <Needle: Expression> "in" <Target: Expression>
128+
"the" ( "first" <IsLast=false> | "last" <IsLast=true> | <IsLast=false> ) "offset" "of" ["chars"] <Needle: Expression> "in" <Target: Expression>
127129
begin
128130
MCCharEvalOffsetOfChars(IsLast, Needle, Target, output)
129131
end syntax
@@ -160,7 +162,7 @@ output: Returns the number of chars between the first char of <Targe
160162
*/
161163

162164
syntax CharOffsetBefore is prefix operator with precedence 1
163-
"the" ["first" <IsFirst=true> | "last" <IsFirst=false>] "offset" "of" ["chars"] <Needle: Expression> "before" <Before: Expression> "in" <Target: Expression>
165+
"the" ( "first" <IsFirst=true> | "last" <IsFirst=false> | <IsFirst=false> ) "offset" "of" ["chars"] <Needle: Expression> "before" <Before: Expression> "in" <Target: Expression>
164166
begin
165167
MCCharEvalOffsetOfCharsBefore(IsFirst, Needle, Before, Target, output)
166168
end syntax
@@ -212,4 +214,10 @@ end syntax
212214

213215
--
214216

217+
syntax NewLineCharacter is expression
218+
"newline"
219+
begin
220+
MCCharEvalNewlineCharacter(output)
221+
end syntax
222+
215223
end module

libscript/src/list.mlc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ output: Returns true if the elements of <Needle> occur as a subsequence
118118
and false otherwise.
119119
*/
120120

121-
syntax ContainsElements is neutral binary operator with precedence 1
121+
syntax ContainsElements is neutral binary operator with precedence 2
122122
<Target: Expression> "contains" <Needle: Expression>
123123
begin
124124
MCListEvalContainsElements(Target, Needle, output)

libscript/src/module-arithmetic.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ extern "C" void MCArithmeticExecSubtractNumberFromNumber(MCNumberRef p_number, M
7979
MCNumberCreateWithReal(t_target, x_target);
8080
}
8181

82-
extern "C" void MCArithmeticExecMultiplyIntegerByInteger(integer_t p_number, integer_t& x_target)
82+
extern "C" void MCArithmeticExecMultiplyIntegerByInteger(integer_t& x_target, integer_t p_number)
8383
{
8484
if (p_number > 0 && INTEGER_MAX / p_number < x_target)
8585
// overflow
@@ -91,12 +91,12 @@ extern "C" void MCArithmeticExecMultiplyIntegerByInteger(integer_t p_number, int
9191
x_target *= p_number;
9292
}
9393

94-
extern "C" void MCArithmeticExecMultiplyRealByReal(double p_number, double& x_target)
94+
extern "C" void MCArithmeticExecMultiplyRealByReal(double& x_target, double p_number)
9595
{
9696
x_target *= p_number;
9797
}
9898

99-
extern "C" void MCArithmeticExecMultiplyNumberByNumber(MCNumberRef p_number, MCNumberRef& x_target)
99+
extern "C" void MCArithmeticExecMultiplyNumberByNumber(MCNumberRef& x_target, MCNumberRef p_number)
100100
{
101101
double t_target, t_number;
102102
t_target = MCNumberFetchAsReal(x_target);
@@ -110,20 +110,20 @@ extern "C" void MCArithmeticExecMultiplyNumberByNumber(MCNumberRef p_number, MCN
110110
MCNumberCreateWithReal(t_target, x_target);
111111
}
112112

113-
extern "C" void MCArithmeticExecDivideIntegerByInteger(integer_t p_number, integer_t& x_target)
113+
extern "C" void MCArithmeticExecDivideIntegerByInteger(integer_t& x_target, integer_t p_number)
114114
{
115115
x_target /= p_number;
116116
}
117117

118-
extern "C" void MCArithmeticExecDivideRealByReal(double p_number, double& x_target)
118+
extern "C" void MCArithmeticExecDivideRealByReal(double& x_target, double p_number)
119119
{
120120
if (p_number > 0 && p_number < 1 && MAXFLOAT * p_number < x_target)
121121
// overflow
122122
return;
123123
x_target /= p_number;
124124
}
125125

126-
extern "C" void MCArithmeticExecDivideNumberByNumber(MCNumberRef p_number, MCNumberRef& x_target)
126+
extern "C" void MCArithmeticExecDivideNumberByNumber(MCNumberRef& x_target, MCNumberRef p_number)
127127
{
128128
double t_target, t_number;
129129
t_target = MCNumberFetchAsReal(x_target);

libscript/src/module-char.cpp

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,15 @@ extern "C" void MCCharEvalNumberOfCharsIn(MCStringRef p_target, index_t& r_outpu
2323
r_output = MCStringGetLength(p_target);
2424
}
2525

26-
#if 0
27-
void MCCharEvalIsAmongTheCharsOf(MCHandlerContext& ctxt, MCStringRef p_needle, MCStringRef p_target, bool& r_output)
26+
void MCCharEvalIsAmongTheCharsOf(MCStringRef p_needle, MCStringRef p_target, bool& r_output)
2827
{
2928
// Error if there is more than one char in needle.
3029
if (MCStringGetLength(p_needle) == 1)
3130
return;
3231

3332
uindex_t t_dummy;
34-
r_output = MCStringFirstIndexOfChar(p_target, MCStringGetCodepointAtIndex(p_needle, 0), 0, ctxt . GetStringComparisonOptions(), t_dummy);
33+
r_output = MCStringFirstIndexOfChar(p_target, MCStringGetCodepointAtIndex(p_needle, 0), 0, kMCStringOptionCompareExact, t_dummy);
3534
}
36-
#endif
3735

3836
extern "C" void MCCharFetchCharRangeOf(index_t p_start, index_t p_finish, MCStringRef p_target, MCStringRef& r_output)
3937
{
@@ -111,49 +109,52 @@ extern "C" void MCCharStoreBeforeCharOf(MCStringRef p_value, index_t p_index, MC
111109
MCValueAssign(x_target, *t_new_string);
112110
}
113111

114-
#if 0
115-
void MCCharEvalOffsetOfCharsInRange(MCHandlerContext ctxt, MCStringRef p_needle, MCStringRef p_target, bool p_is_last, MCRange p_range, uindex_t& r_output)
112+
extern "C" void MCCharEvalOffsetOfCharsInRange(MCStringRef p_needle, MCStringRef p_target, bool p_is_last, MCRange p_range, uindex_t& r_output)
116113
{
117114
uindex_t t_offset;
118115
t_offset = 0;
119116
if (!MCStringIsEmpty(p_needle))
120117
{
121118
if (p_is_last)
122-
MCStringLastIndexOfStringInRange(p_target, p_needle, p_range, ctxt . GetStringComparisonOptions(), t_offset);
119+
MCStringLastIndexOfStringInRange(p_target, p_needle, p_range, kMCStringOptionCompareExact, t_offset);
123120
else
124-
MCStringFirstIndexOfStringInRange(p_target, p_needle, p_range, ctxt . GetStringComparisonOptions(), t_offset);
121+
MCStringFirstIndexOfStringInRange(p_target, p_needle, p_range, kMCStringOptionCompareExact, t_offset);
125122

126123
// correct output index
127124
t_offset++;
128125
}
129126
r_output = t_offset;
130127
}
131128

132-
void MCCharEvalOffsetOfChars(MCHandlerContext ctxt, MCStringRef p_needle, MCStringRef p_target, bool p_is_last, uindex_t& r_output)
129+
extern "C" void MCCharEvalOffsetOfChars(MCStringRef p_needle, MCStringRef p_target, bool p_is_last, uindex_t& r_output)
133130
{
134-
MCCharEvalOffsetOfCharsInRange(ctxt, p_needle, MCRangeMake(0, UINDEX_MAX), p_target, p_is_last, r_output);
131+
MCCharEvalOffsetOfCharsInRange(p_needle, p_target, p_is_last, MCRangeMake(0, UINDEX_MAX), r_output);
135132
}
136133

137-
void MCCharEvalOffsetOfCharsAfter(MCHandlerContext ctxt, MCStringRef p_needle, uindex_t p_after, MCStringRef p_target, bool p_is_last, uindex_t& r_output)
134+
extern "C" void MCCharEvalOffsetOfCharsAfter(MCStringRef p_needle, uindex_t p_after, MCStringRef p_target, bool p_is_last, uindex_t& r_output)
138135
{
139-
MCCharEvalOffsetOfCharsInRange(ctxt, p_needle, MCRangeMake(p_after, UINDEX_MAX), p_target, p_is_last, r_output);
136+
MCCharEvalOffsetOfCharsInRange(p_needle, p_target, p_is_last, MCRangeMake(p_after, UINDEX_MAX), r_output);
140137
}
141138

142-
void MCCharEvalOffsetOfCharsBefore(MCStringRef p_needle, MCStringRef p_target, uindex_t p_before, bool p_is_first, uindex_t& r_output)
139+
extern "C" void MCCharEvalOffsetOfCharsBefore(MCStringRef p_needle, MCStringRef p_target, uindex_t p_before, bool p_is_first, uindex_t& r_output)
143140
{
144-
MCCharEvalOffsetOfCharsInRange(ctxt, p_needle, MCRangeMake(0, p_before), p_target, p_is_last, r_output);
141+
MCCharEvalOffsetOfCharsInRange(p_needle, p_target, !p_is_first, MCRangeMake(0, p_before), r_output);
145142
}
146143

147-
void MCCharEvalBeginsWith(MCHandlerContext& ctxt, MCStringRef p_source, MCStringRef p_prefix, bool& r_result)
144+
extern "C" void MCCharEvalBeginsWith(MCStringRef p_source, MCStringRef p_prefix, bool& r_result)
148145
{
149-
r_result = MCStringBeginsWith(p_source, p_prefix, ctxt . GetStringComparisonOptions());
146+
r_result = MCStringBeginsWith(p_source, p_prefix, kMCStringOptionCompareExact);
150147
}
151148

152-
void MCCharEvalEndsWith(MCHandlerContext& ctxt, MCStringRef p_source, MCStringRef p_suffix, bool& r_result)
149+
extern "C" void MCCharEvalEndsWith(MCStringRef p_source, MCStringRef p_suffix, bool& r_result)
153150
{
154-
r_result = MCStringBeginsWith(p_source, p_prefix, ctxt . GetStringComparisonOptions());
151+
r_result = MCStringEndsWith(p_source, p_suffix, kMCStringOptionCompareExact);
152+
}
153+
154+
extern "C" void MCCharEvalNewlineCharacter(MCStringRef& r_output)
155+
{
156+
MCStringFormat(r_output, "\n");
155157
}
156-
#endif
157158

158159
////////////////////////////////////////////////////////////////////////////////////////////////////
159160

libscript/src/module-list.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ extern "C" void MCListExecPushSingleElementOnto(MCValueRef p_value, bool p_is_fr
5454
// ctxt . Throw();
5555
}
5656

57-
extern "C" void MCListExecPopElementInto(MCProperListRef& x_source, bool p_is_front, MCValueRef& r_output)
57+
extern "C" void MCListExecPopElementInto(bool p_is_front, MCProperListRef& x_source, MCValueRef& r_output)
5858
{
5959
MCAutoProperListRef t_mutable_list;
6060
if (!MCProperListMutableCopy(x_source, &t_mutable_list))
@@ -91,7 +91,7 @@ extern "C" void MCListEvalIsAmongTheElementsOf(MCValueRef p_needle, MCProperList
9191
r_output = MCProperListFirstIndexOfElement(p_target, p_needle, 0, t_dummy);
9292
}
9393

94-
extern "C" void MCListEvalContains(MCProperListRef p_target, MCProperListRef p_needle, bool& r_output)
94+
extern "C" void MCListEvalContainsElements(MCProperListRef p_target, MCProperListRef p_needle, bool& r_output)
9595
{
9696
uindex_t t_dummy;
9797
r_output = MCProperListFirstIndexOfList(p_target, p_needle, 0, t_dummy);
@@ -127,7 +127,7 @@ extern "C" void MCListFetchElementRangeOf(index_t p_start, index_t p_finish, MCP
127127
{
128128
uindex_t t_start, t_count;
129129
MCChunkGetExtentsOfElementChunkByRange(p_target, p_start, p_finish, t_start, t_count);
130-
MCProperListCopySublist(p_target, MCRangeMake(p_start, p_finish - p_start + 1), r_output);
130+
MCProperListCopySublist(p_target, MCRangeMake(t_start, t_count), r_output);
131131
}
132132

133133
extern "C" void MCListStoreElementRangeOf(MCValueRef p_value, index_t p_start, index_t p_finish, MCProperListRef& x_target)

0 commit comments

Comments
 (0)