Skip to content

Commit 974dbbc

Browse files
author
runrevali
committed
[[ StdMlc ]] More fixes and tweaks to mlc files and implementation
1 parent 2609367 commit 974dbbc

File tree

8 files changed

+138
-28
lines changed

8 files changed

+138
-28
lines changed

libscript/libscript.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
4DDA20451A136FF4001B0CA2 /* script-builder.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4DDA20441A136FF4001B0CA2 /* script-builder.cpp */; };
6262
4DDA20701A139BC0001B0CA2 /* script-test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4DDA206F1A139BC0001B0CA2 /* script-test.cpp */; };
6363
766113441A2F298E0042DE7F /* list.mlc in Sources */ = {isa = PBXBuildFile; fileRef = 4D79B6751A273BA000DD750C /* list.mlc */; };
64+
766113541A2F4F720042DE7F /* type-convert.mlc in Sources */ = {isa = PBXBuildFile; fileRef = 766113531A2F4F720042DE7F /* type-convert.mlc */; };
6465
/* End PBXBuildFile section */
6566

6667
/* Begin PBXBuildRule section */
@@ -199,6 +200,7 @@
199200
4DDA20441A136FF4001B0CA2 /* script-builder.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = "script-builder.cpp"; path = "src/script-builder.cpp"; sourceTree = "<group>"; };
200201
4DDA20661A139BA1001B0CA2 /* libscript-test */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = "libscript-test"; sourceTree = BUILT_PRODUCTS_DIR; };
201202
4DDA206F1A139BC0001B0CA2 /* script-test.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = "script-test.cpp"; path = "src/script-test.cpp"; sourceTree = "<group>"; };
203+
766113531A2F4F720042DE7F /* type-convert.mlc */ = {isa = PBXFileReference; lastKnownFileType = text; name = "type-convert.mlc"; path = "src/type-convert.mlc"; sourceTree = "<group>"; };
202204
/* End PBXFileReference section */
203205

204206
/* Begin PBXFrameworksBuildPhase section */
@@ -241,6 +243,7 @@
241243
4D322F0D19DD945E008476D3 = {
242244
isa = PBXGroup;
243245
children = (
246+
766113531A2F4F720042DE7F /* type-convert.mlc */,
244247
4D44E3661A139F590073FFA2 /* CoreFoundation.framework */,
245248
4D44E3471A139C070073FFA2 /* Configurations */,
246249
4D05714B19E321C00080F97B /* References */,
@@ -529,6 +532,7 @@
529532
isa = PBXSourcesBuildPhase;
530533
buildActionMask = 2147483647;
531534
files = (
535+
766113541A2F4F720042DE7F /* type-convert.mlc in Sources */,
532536
766113441A2F298E0042DE7F /* list.mlc in Sources */,
533537
4D79B6CF1A27405600DD750C /* arithmetic.mlc in Sources */,
534538
4D79B6D01A27405600DD750C /* binary.mlc in Sources */,

libscript/src/arithmetic.mlc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ public foreign handler MCArithmeticEvalIntegerIsLessThanOrEqualToInteger(in Left
5555
public foreign handler MCArithmeticEvalRealIsLessThanOrEqualToReal(in Left as double, in Right as double, out Value as bool) as undefined binds to "<builtin>"
5656
public foreign handler MCArithmeticEvalNumberIsLessThanOrEqualToNumber(in Left as number, in Right as number, out Value as bool) as undefined binds to "<builtin>"
5757

58+
59+
public foreign handler MCArithmeticEvalEqualToInteger(in Left as int, in Right as int, out Value as bool) as undefined binds to "<builtin>"
5860
--
5961

6062
/*
@@ -308,4 +310,18 @@ end syntax
308310

309311
--
310312

313+
/*
314+
Summary: Equal to relation.
315+
Left: An expression that evaluates to a number.
316+
Right: An expression that evaluates to a number.
317+
output: True if <Left> is equal to <Right>, and false otherwise.
318+
*/
319+
320+
321+
syntax IsEqualTo is neutral binary operator with precedence 3
322+
<Left: Expression> "=" <Right: Expression>
323+
begin
324+
MCArithmeticEvalEqualToInteger(Left, Right, output)
325+
end syntax
326+
311327
end module

libscript/src/list.mlc

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,21 @@ public foreign handler MCListEvalNumberOfElementsIn(in Target as list, out Count
1111
public foreign handler MCListEvalIsAmongTheElementsOf(in Needle as any, in Target as list, out Result as bool) as undefined binds to "<builtin>"
1212
public foreign handler MCListEvalContainsElements(in Target as list, in Needle as list, out Result as bool) as undefined binds to "<builtin>"
1313

14-
public foreign handler MCListFetchElementOf(in Index as index, in Target as list, out Value as any) as undefined binds to "<builtin>"
15-
public foreign handler MCListStoreElementOf(in Value as any, in Index as index, inout Target as list) as undefined binds to "<builtin>"
16-
public foreign handler MCListFetchElementRangeOf(in Start as index, in Finish as index, in Target as list, out Value as list) as undefined binds to "<builtin>"
17-
public foreign handler MCListStoreElementRangeOf(in Value as any, in Start as index, in Finish as index, inout Target as list) as undefined binds to "<builtin>"
14+
public foreign handler MCListFetchElementOf(in Index as int, in Target as list, out Value as any) as undefined binds to "<builtin>"
15+
public foreign handler MCListStoreElementOf(in Value as any, in Index as int, inout Target as list) as undefined binds to "<builtin>"
16+
public foreign handler MCListFetchElementRangeOf(in Start as int, in Finish as int, in Target as list, out Value as list) as undefined binds to "<builtin>"
17+
public foreign handler MCListStoreElementRangeOf(in Value as any, in Start as int, in Finish as int, inout Target as list) as undefined binds to "<builtin>"
1818

19-
public foreign handler MCListFetchIndexOf(in Target as list, in Index as index, out Value as any) as undefined binds to "<builtin>"
19+
public foreign handler MCListFetchIndexOf(in Target as list, in Index as int, out Value as any) as undefined binds to "<builtin>"
20+
public foreign handler MCListStoreIndexOf(in Value as any, inout Target as list, in Index as int) as undefined binds to "<builtin>"
2021

21-
public foreign handler MCListStoreBeforeElementOf(in Value as any, in Index as index, inout Target as list) as undefined binds to "<builtin>"
22-
public foreign handler MCListStoreAfterElementOf(in Value as any, in Index as index, inout Target as list) as undefined binds to "<builtin>"
22+
public foreign handler MCListStoreBeforeElementOf(in Value as any, in Index as int, inout Target as list) as undefined binds to "<builtin>"
23+
public foreign handler MCListStoreAfterElementOf(in Value as any, in Index as int, inout Target as list) as undefined binds to "<builtin>"
2324

24-
public foreign handler MCListSpliceIntoElementRangeOf(in Source as list, in Start as index, in Finish as index, inout Target as list) as undefined binds to "<builtin>"
25-
public foreign handler MCListSpliceIntoElementOf(in Source as list, in Index as index, inout Target as list) as undefined binds to "<builtin>"
26-
public foreign handler MCListSpliceBeforeElementOf(in Source as list, in Index as index, inout Target as list) as undefined binds to "<builtin>"
27-
public foreign handler MCListSpliceAfterElementOf(in Source as list, in Index as index, inout Target as list) as undefined binds to "<builtin>"
25+
public foreign handler MCListSpliceIntoElementRangeOf(in Source as list, in Start as int, in Finish as int, inout Target as list) as undefined binds to "<builtin>"
26+
public foreign handler MCListSpliceIntoElementOf(in Source as list, in Index as int, inout Target as list) as undefined binds to "<builtin>"
27+
public foreign handler MCListSpliceBeforeElementOf(in Source as list, in Index as int, inout Target as list) as undefined binds to "<builtin>"
28+
public foreign handler MCListSpliceAfterElementOf(in Source as list, in Index as int, inout Target as list) as undefined binds to "<builtin>"
2829

2930
--
3031

@@ -161,7 +162,7 @@ syntax SingletonArrElementOf is postfix operator with precedence 1
161162
<Target: Expression> "[" <Index: Expression> "]"
162163
begin
163164
MCListFetchIndexOf(Target, Index, output)
164-
--MCListStoreElementOf(input, Index, Target)
165+
MCListStoreIndexOf(input, Target, Index)
165166
end syntax
166167

167168
/*

libscript/src/module-arithmetic.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,3 +417,8 @@ extern "C" void MCArithmeticEvalMinusNumber(MCNumberRef p_operand, MCNumberRef&
417417
else
418418
MCNumberCreateWithInteger(-MCNumberFetchAsReal(p_operand), r_output);
419419
}
420+
421+
extern "C" void MCArithmeticEvalEqualToInteger(integer_t p_left, integer_t p_right, bool& r_output)
422+
{
423+
r_output = p_left == p_right;
424+
}

libscript/src/module-list.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ extern "C" void MCListStoreElementOf(MCValueRef p_value, index_t p_index, MCProp
112112
MCAutoProperListRef t_mutable_list;
113113
if (!MCProperListMutableCopy(x_target, &t_mutable_list))
114114
return;
115-
115+
116+
MCProperListRemoveElements(*t_mutable_list, t_start, t_count);
116117
MCProperListInsertElement(*t_mutable_list, p_value, t_start);
117118

118119
MCAutoProperListRef t_immutable;
@@ -150,9 +151,12 @@ extern "C" void MCListStoreElementRangeOf(MCValueRef p_value, index_t p_start, i
150151

151152
extern "C" void MCListFetchIndexOf(MCProperListRef p_target, index_t p_index, MCValueRef& r_output)
152153
{
153-
uindex_t t_start, t_count;
154-
MCChunkGetExtentsOfElementChunkByExpression(p_target, p_index, t_start, t_count);
155-
r_output = MCValueRetain(MCProperListFetchElementAtIndex(p_target, t_start));
154+
MCListFetchElementOf(p_index, p_target, r_output);
155+
}
156+
157+
extern "C" void MCListStoreIndexOf(MCValueRef p_value, MCProperListRef& x_target, index_t p_index)
158+
{
159+
MCListStoreElementOf(p_value, p_index, x_target);
156160
}
157161

158162
extern "C" void MCListStoreAfterElementOf(MCValueRef p_value, index_t p_index, MCProperListRef& x_target)

libscript/src/module-sort.cpp

Lines changed: 88 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,48 +96,128 @@ static compare_t MCSortCompareDateTime(void *context, MCValueRef p_left, MCValue
9696

9797
extern "C" void MCSortExecSortListAscendingText(MCProperListRef& x_target)
9898
{
99+
MCAutoProperListRef t_mutable_list;
100+
if (!MCProperListMutableCopy(x_target, &t_mutable_list))
101+
return;
102+
99103
// For now, just compare caseless.
100104
MCStringOptions t_option;
101105
t_option = kMCStringOptionCompareCaseless;
102-
MCProperListStableSort(x_target, false, MCSortCompareText, &t_option);
106+
MCProperListStableSort(*t_mutable_list, false, MCSortCompareText, &t_option);
107+
108+
MCAutoProperListRef t_sorted_list;
109+
if (!MCProperListCopy(*t_mutable_list, &t_sorted_list))
110+
return;
111+
112+
MCValueAssign(x_target, *t_sorted_list);
103113
}
104114

105115
extern "C" void MCSortExecSortListDescendingText(MCProperListRef& x_target)
106116
{
117+
MCAutoProperListRef t_mutable_list;
118+
if (!MCProperListMutableCopy(x_target, &t_mutable_list))
119+
return;
120+
107121
// For now, just compare caseless.
108122
MCStringOptions t_option;
109123
t_option = kMCStringOptionCompareCaseless;
110-
MCProperListStableSort(x_target, true, MCSortCompareText, &t_option);
124+
MCProperListStableSort(*t_mutable_list, true, MCSortCompareText, &t_option);
125+
126+
MCAutoProperListRef t_sorted_list;
127+
if (!MCProperListCopy(*t_mutable_list, &t_sorted_list))
128+
return;
129+
130+
MCValueAssign(x_target, *t_sorted_list);
111131
}
112132

113133
extern "C" void MCSortExecSortListAscendingBinary(MCProperListRef& x_target)
114134
{
115-
MCProperListStableSort(x_target, false, MCSortCompareBinary, nil);
135+
MCAutoProperListRef t_mutable_list;
136+
if (!MCProperListMutableCopy(x_target, &t_mutable_list))
137+
return;
138+
139+
MCProperListStableSort(*t_mutable_list, false, MCSortCompareBinary, nil);
140+
141+
MCAutoProperListRef t_sorted_list;
142+
if (!MCProperListCopy(*t_mutable_list, &t_sorted_list))
143+
return;
144+
145+
MCValueAssign(x_target, *t_sorted_list);
116146
}
117147

118148
extern "C" void MCSortExecSortListDescendingBinary(MCProperListRef& x_target)
119149
{
120-
MCProperListStableSort(x_target, true, MCSortCompareBinary, nil);
150+
MCAutoProperListRef t_mutable_list;
151+
if (!MCProperListMutableCopy(x_target, &t_mutable_list))
152+
return;
153+
154+
MCProperListStableSort(*t_mutable_list, true, MCSortCompareBinary, nil);
155+
156+
MCAutoProperListRef t_sorted_list;
157+
if (!MCProperListCopy(*t_mutable_list, &t_sorted_list))
158+
return;
159+
160+
MCValueAssign(x_target, *t_sorted_list);
121161
}
122162

123163
extern "C" void MCSortExecSortListAscendingNumeric(MCProperListRef& x_target)
124164
{
125-
MCProperListStableSort(x_target, false, MCSortCompareNumeric, nil);
165+
MCAutoProperListRef t_mutable_list;
166+
if (!MCProperListMutableCopy(x_target, &t_mutable_list))
167+
return;
168+
169+
MCProperListStableSort(*t_mutable_list, false, MCSortCompareNumeric, nil);
170+
171+
MCAutoProperListRef t_sorted_list;
172+
if (!MCProperListCopy(*t_mutable_list, &t_sorted_list))
173+
return;
174+
175+
MCValueAssign(x_target, *t_sorted_list);
126176
}
127177

128178
extern "C" void MCSortExecSortListDescendingNumeric(MCProperListRef& x_target)
129179
{
130-
MCProperListStableSort(x_target, true, MCSortCompareNumeric, nil);
180+
MCAutoProperListRef t_mutable_list;
181+
if (!MCProperListMutableCopy(x_target, &t_mutable_list))
182+
return;
183+
184+
MCProperListStableSort(*t_mutable_list, true, MCSortCompareNumeric, nil);
185+
186+
MCAutoProperListRef t_sorted_list;
187+
if (!MCProperListCopy(*t_mutable_list, &t_sorted_list))
188+
return;
189+
190+
MCValueAssign(x_target, *t_sorted_list);
131191
}
132192

133193
void MCSortExecSortListAscendingDateTime(MCProperListRef& x_target)
134194
{
135-
MCProperListStableSort(x_target, false, MCSortCompareDateTime, nil);
195+
MCAutoProperListRef t_mutable_list;
196+
if (!MCProperListMutableCopy(x_target, &t_mutable_list))
197+
return;
198+
199+
MCProperListStableSort(*t_mutable_list, false, MCSortCompareDateTime, nil);
200+
201+
MCAutoProperListRef t_sorted_list;
202+
if (!MCProperListCopy(*t_mutable_list, &t_sorted_list))
203+
return;
204+
205+
MCValueAssign(x_target, *t_sorted_list);
136206
}
137207

138208
void MCSortExecSortListDescendingDateTime(MCProperListRef& x_target)
139209
{
140-
MCProperListStableSort(x_target, true, MCSortCompareDateTime, nil);
210+
MCAutoProperListRef t_mutable_list;
211+
if (!MCProperListMutableCopy(x_target, &t_mutable_list))
212+
return;
213+
214+
MCProperListStableSort(*t_mutable_list, true, MCSortCompareDateTime, nil);
215+
216+
MCAutoProperListRef t_sorted_list;
217+
if (!MCProperListCopy(*t_mutable_list, &t_sorted_list))
218+
return;
219+
220+
MCValueAssign(x_target, *t_sorted_list);
141221
}
142222

143223
/*

libscript/src/module-type_convert.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ static bool MCProperListCombine(void *context, MCValueRef p_value)
2222
return MCListAppend(t_list, p_value);
2323
}
2424

25-
extern "C" void MCTypeConvertExecSplitByDelimiter(MCStringRef p_target, MCStringRef p_delimiter, MCProperListRef& r_output)
25+
extern "C" void MCTypeConvertExecSplitStringByDelimiter(MCStringRef p_target, MCStringRef p_delimiter, MCProperListRef& r_output)
2626
{
2727
if (!MCStringSplitByDelimiter(p_target, p_delimiter, kMCStringOptionCompareCaseless, r_output))
2828
return;
2929
}
3030

31-
extern "C" void MCTypeConvertExecCombineWithDelimiter(MCProperListRef p_target, MCStringRef p_delimiter, MCStringRef& r_output)
31+
extern "C" void MCTypeConvertExecCombineListWithDelimiter(MCProperListRef p_target, MCStringRef p_delimiter, MCStringRef& r_output)
3232
{
3333
MCListRef t_list;
3434
MCListCreateMutable(p_delimiter, t_list);

libscript/src/type-convert.mlc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This module specifies the syntax for the complex type conversion operations avai
44

55
module com.livecode.typeconvert
66

7-
public foreign handler MCTypeConvertExecStringSplitByDelimiter(in Target as string, in Delimiter as string, out Value as list) as undefined binds to "<builtin>"
7+
public foreign handler MCTypeConvertExecSplitStringByDelimiter(in Target as string, in Delimiter as string, out Value as list) as undefined binds to "<builtin>"
88
public foreign handler MCTypeConvertExecCombineListWithDelimiter(in Target as list, in Delimiter as string, out Value as string) as undefined binds to "<builtin>"
99

1010
--
@@ -25,7 +25,7 @@ Example:
2525
syntax StringSplitBy is statement
2626
"split" <Target: Expression> "by" <Delimiter : Expression> "into" <Value: Expression>
2727
begin
28-
MCTypeConvertExecStringSplitByDelimiter(Target, Delimiter, Value)
28+
MCTypeConvertExecSplitStringByDelimiter(Target, Delimiter, Value)
2929
end syntax
3030

3131
/*

0 commit comments

Comments
 (0)