Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit 65b5f33

Browse files
author
runrevali
committed
[[ StdMlc ]] Various fixes to mlc files and implementations
1 parent 6e3b256 commit 65b5f33

File tree

8 files changed

+238
-98
lines changed

8 files changed

+238
-98
lines changed

libscript/libscript.xcodeproj/project.pbxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
4D79B6E31A27405600DD750C /* type.mlc in Sources */ = {isa = PBXBuildFile; fileRef = 4D79B67E1A273BA000DD750C /* type.mlc */; };
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 */; };
63+
766113441A2F298E0042DE7F /* list.mlc in Sources */ = {isa = PBXBuildFile; fileRef = 4D79B6751A273BA000DD750C /* list.mlc */; };
6364
/* End PBXBuildFile section */
6465

6566
/* Begin PBXBuildRule section */
@@ -528,6 +529,7 @@
528529
isa = PBXSourcesBuildPhase;
529530
buildActionMask = 2147483647;
530531
files = (
532+
766113441A2F298E0042DE7F /* list.mlc in Sources */,
531533
4D79B6CF1A27405600DD750C /* arithmetic.mlc in Sources */,
532534
4D79B6D01A27405600DD750C /* binary.mlc in Sources */,
533535
4D79B6D11A27405600DD750C /* bitwise.mlc in Sources */,

libscript/src/char.mlc

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@ module com.livecode.char
22

33
public foreign handler MCCharFetchCharOf(in Index as index, in Target as string, out Value as string) as undefined binds to "<builtin>"
44
public foreign handler MCCharStoreCharOf(in Value as string, in Index as index, inout Target as string) as undefined binds to "<builtin>"
5-
public foreign handler FetchCharRangeOf(in Start as index, in Finish as index, in Target as data, out Value as string) as undefined binds to "<builtin>"
6-
public foreign handler StoreCharRangeOf(in Value as string, in Start as index, in Finish as index, inout Target as string) as undefined binds to "<builtin>"
5+
public foreign handler MCCharFetchCharRangeOf(in Start as index, in Finish as index, in Target as data, out Value as string) as undefined binds to "<builtin>"
6+
public foreign handler MCCharStoreCharRangeOf(in Value as string, in Start as index, in Finish as index, inout Target as string) as undefined binds to "<builtin>"
77

8-
public foreign handler EvalNumberOfCharsIn(in Target as string, out Count as index) as undefined binds to "<builtin>"
8+
public foreign handler MCCharEvalNumberOfCharsIn(in Target as string, out Count as index) as undefined binds to "<builtin>"
99

10-
public foreign handler EvalIsAmongTheCharsOf(in Needle as string, in Source as string, out Value as bool) as undefined binds to "<builtin>"
10+
public foreign handler MCCharEvalIsAmongTheCharsOf(in Needle as string, in Source as string, out Value as bool) as undefined binds to "<builtin>"
1111

12-
public foreign handler StoreBeforeCharOf(in Value as string, in Index as index, inout Target as string) as undefined binds to "<builtin>"
13-
public foreign handler StoreAfterCharOf(in Value as string, in Index as index, inout Target as string) as undefined binds to "<builtin>"
12+
public foreign handler MCCharStoreBeforeCharOf(in Value as string, in Index as index, inout Target as string) as undefined binds to "<builtin>"
13+
public foreign handler MCCharStoreAfterCharOf(in Value as string, in Index as index, inout Target as string) as undefined binds to "<builtin>"
1414

15-
public foreign handler EvalOffsetOfChars(in IsLast as bool, in Needle as string, in Target as string, out Offset as index) as undefined binds to "<builtin>"
16-
public foreign handler EvalOffsetOfCharsBefore(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>"
17-
public foreign handler EvalOffsetOfCharsAfter(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>"
15+
public foreign handler MCCharEvalOffsetOfChars(in IsLast as bool, in Needle as string, in Target as string, out Offset as index) as undefined binds to "<builtin>"
16+
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>"
17+
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

1919
--
2020

@@ -33,7 +33,7 @@ Example:
3333
syntax CountCharsOf is prefix operator with precedence 1
3434
"the" "number" "of" "chars" "in" <Target: Expression>
3535
begin
36-
EvalNumberOfCharsIn(Target, output)
36+
MCCharEvalNumberOfCharsIn(Target, output)
3737
end syntax
3838

3939
--
@@ -76,8 +76,8 @@ Example: get char 5 to 10 of tString // Evaluates chars 5 to 10
7676
syntax RangeCharOf is prefix operator with precedence 1
7777
"char" <Start: Expression> "to" <Finish: Expression> "of" <Target: Expression>
7878
begin
79-
FetchCharRangeOf(Start, Finish, Target, output)
80-
StoreCharRangeOf(input, Start, Finish, Target)
79+
MCCharFetchCharRangeOf(Start, Finish, Target, output)
80+
MCCharStoreCharRangeOf(input, Start, Finish, Target)
8181
end syntax
8282

8383
--
@@ -92,21 +92,21 @@ output: True if <Needle> is among the chars of <Target>, and false o
9292
syntax CharIsIn is neutral binary operator with precedence 1
9393
<Needle: Expression> "is" "in" <Source: Expression>
9494
begin
95-
EvalIsAmongTheCharsOf(Needle, Source, output)
95+
MCCharEvalIsAmongTheCharsOf(Needle, Source, output)
9696
end syntax
9797

9898
--
9999

100100
syntax BeforeCharOf is prefix operator with precedence 1
101101
"before" "char" <Index: Expression> "of" <Target: Expression>
102102
begin
103-
StoreBeforeCharOf(input, Index, Target)
103+
MCCharStoreBeforeCharOf(input, Index, Target)
104104
end syntax
105105

106106
syntax AfterCharOf is prefix operator with precedence 1
107107
"after" "char" <Index: Expression> "of" <Target: Expression>
108108
begin
109-
StoreAfterCharOf(input, Index, Target)
109+
MCCharStoreAfterCharOf(input, Index, Target)
110110
end syntax
111111

112112
--
@@ -125,7 +125,7 @@ output: Returns the number of chars between the first char of <Targe
125125
syntax CharOffset is prefix operator with precedence 1
126126
"the" ["first" <IsLast=false> | "last" <IsLast=true>] "offset" "of" ["chars"] <Needle: Expression> "in" <Target: Expression>
127127
begin
128-
EvalOffsetOfChars(IsLast, Needle, Target, output)
128+
MCCharEvalOffsetOfChars(IsLast, Needle, Target, output)
129129
end syntax
130130

131131
/*
@@ -141,9 +141,9 @@ output: Returns the number of chars between the first char of <Targe
141141
*/
142142

143143
syntax CharOffsetAfter is prefix operator with precedence 1
144-
"the" ["first" <IsLast=false> | "last" <IsLast=true>] "offset" "of" ["chars"] <Needle: Expression> "after" <After: Expression> "in" <Target: Expression>
144+
"the" ( "first" <IsLast=false> | "last" <IsLast=true> | <IsLast=false> ) "offset" "of" ["chars"] <Needle: Expression> "after" <After: Expression> "in" <Target: Expression>
145145
begin
146-
EvalOffsetOfCharsAfter(IsLast, Needle, After, Target, output)
146+
MCCharEvalOffsetOfCharsAfter(IsLast, Needle, After, Target, output)
147147
end syntax
148148

149149
/*
@@ -162,7 +162,7 @@ output: Returns the number of chars between the first char of <Targe
162162
syntax CharOffsetBefore is prefix operator with precedence 1
163163
"the" ["first" <IsFirst=true> | "last" <IsFirst=false>] "offset" "of" ["chars"] <Needle: Expression> "before" <Before: Expression> "in" <Target: Expression>
164164
begin
165-
EvalOffsetOfCharsBefore(IsFirst, Needle, Before, Target, output)
165+
MCCharEvalOffsetOfCharsBefore(IsFirst, Needle, Before, Target, output)
166166
end syntax
167167

168168

@@ -176,7 +176,7 @@ output: True if the chars of <Needle> occur as a subsequence of the
176176
syntax ContainsChars is neutral binary operator with precedence 1
177177
<Target: Expression> "contains" <Needle: Expression>
178178
begin
179-
EvalIsAmongTheCharsOf(Target, Needle, output)
179+
MCCharEvalIsAmongTheCharsOf(Target, Needle, output)
180180
end syntax
181181

182182
--

libscript/src/list.mlc

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,30 @@
11
module com.livecode.list
22

3-
foreign handler MCListEvalHeadOf(in Target as list, out Value as any) as undefined binds to "<builtin>"
4-
foreign handler MCListEvalTailOf(in Target as list, out Value as any) as undefined binds to "<builtin>"
3+
public foreign handler MCListEvalHeadOf(in Target as list, out Value as any) as undefined binds to "<builtin>"
4+
public foreign handler MCListEvalTailOf(in Target as list, out Value as any) as undefined binds to "<builtin>"
55

6-
foreign handler MCListExecPushElementOnto(in Value as any, in IsFront as bool, inout Target as list) as undefined binds to "<builtin>"
7-
foreign handler MCListExecPopElementInto(inout Source as list, in IsFront as bool, out Target as any) as undefined binds to "<builtin>"
6+
public foreign handler MCListExecPushSingleElementOnto(in Value as any, in IsFront as bool, inout Target as list) as undefined binds to "<builtin>"
7+
public foreign handler MCListExecPopElementInto(in IsFront as bool, inout Source as list, out Target as any) as undefined binds to "<builtin>"
88

9-
foreign handler MCListEvalNumberOfElementsIn(in Target as list, out Count as index) as undefined binds to "<builtin>"
9+
public foreign handler MCListEvalNumberOfElementsIn(in Target as list, out Count as index) as undefined binds to "<builtin>"
1010

11-
foreign handler MCListEvalIsAmongTheElementsOf(in Needle as any, in Target as list, out Result as bool) as undefined binds to "<builtin>"
12-
foreign handler MCListEvalContainsElements(in Target as list, in Needle as list, out Result as bool) as undefined binds to "<builtin>"
11+
public foreign handler MCListEvalIsAmongTheElementsOf(in Needle as any, in Target as list, out Result as bool) as undefined binds to "<builtin>"
12+
public foreign handler MCListEvalContainsElements(in Target as list, in Needle as list, out Result as bool) as undefined binds to "<builtin>"
1313

14-
foreign handler MCListFetchElementOf(in Index as index, in Target as list, out Value as any) as undefined binds to "<builtin>"
15-
foreign handler MCListStoreElementOf(in Value as any, in Index as index, inout Target as list) as undefined binds to "<builtin>"
16-
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-
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 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>"
1818

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

22-
foreign handler MCListSpliceIntoElementRangeOf(in Source as list, in Start as index, in Finish as index, inout Target as list) as undefined binds to "<builtin>"
23-
foreign handler MCListSpliceIntoElementOf(in Source as list, in Index as index, inout Target as list) as undefined binds to "<builtin>"
24-
foreign handler MCListSpliceBeforeElementOf(in Source as list, in Index as index, inout Target as list) as undefined binds to "<builtin>"
25-
foreign handler MCListSpliceAfterElementOf(in Source as list, in Index as index, inout Target as list) as undefined binds to "<builtin>"
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>"
23+
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>"
2628

2729
--
2830

@@ -59,9 +61,9 @@ Target: An expression which evaluates to a list.
5961
*/
6062

6163
syntax PushOntoList is statement
62-
"push" <Value: Expression> "onto" [ "front" "of" <IsFront=true> | "back" "of" <IsFront=false> ] <Target:Expression>
64+
"push" <Value: Expression> "onto" ( "front" "of" <IsFront=true> | "back" "of" <IsFront=false> | <IsFront=false> ) <Target:Expression>
6365
begin
64-
MCListExecPushElementOnto(Value, IsFront, Target)
66+
MCListExecPushSingleElementOnto(Value, IsFront, Target)
6567
end syntax
6668

6769
/*
@@ -72,9 +74,9 @@ Target: An expression which evaluates to a container.
7274
*/
7375

7476
syntax PopList is statement
75-
"pop" [ "front" "of" <IsFront=true> | "back" "of" <IsFront=false> ] <Source: Expression> "into" <Target: Expression>
77+
"pop" ( "front" "of" <IsFront=true> | "back" "of" <IsFront=false> | <IsFront=false> ) <Source: Expression> "into" <Target: Expression>
7678
begin
77-
MCListExecPopElementInto(Source, IsFront, Target)
79+
MCListExecPopElementInto(IsFront, Source, Target)
7880
end syntax
7981

8082
--
@@ -151,11 +153,15 @@ output: Either locates the element container at the given index for
151153
as the source of another operation.
152154
*/
153155

156+
--public handler MCListFetchElementOfReversed(in pTarget as list, in pIndex as int, out rElement) as undefined
157+
--MCListFetchElementOf(pIndex, pTarget, rElement)
158+
--end handler
159+
154160
syntax SingletonArrElementOf is postfix operator with precedence 1
155161
<Target: Expression> "[" <Index: Expression> "]"
156162
begin
157-
MCListFetchElementOf(Index, Target, output)
158-
MCListStoreElementOf(input, Index, Target)
163+
MCListFetchIndexOf(Target, Index, output)
164+
--MCListStoreElementOf(input, Index, Target)
159165
end syntax
160166

161167
/*

libscript/src/module-byte.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,11 @@ extern "C" void MCByteStoreByteRangeOf(MCDataRef p_value, index_t p_start, index
115115
if (!MCDataReplace(*t_data, MCRangeMake(t_start, t_count), p_value))
116116
return;
117117

118-
MCValueRelease(x_target);
119-
if (!MCDataCopy(*t_data, x_target))
118+
MCAutoDataRef t_new_data;
119+
if (!MCDataCopy(*t_data, &t_new_data))
120120
return;
121+
122+
MCValueAssign(x_target, *t_new_data);
121123
}
122124

123125
extern "C" void MCByteFetchByteOf(index_t p_index, MCDataRef p_target, MCDataRef& r_output)
@@ -134,17 +136,20 @@ extern "C" void MCByteStoreAfterByteOf(MCDataRef p_value, index_t p_index, MCDat
134136
{
135137
uindex_t t_start, t_count;
136138
MCChunkGetExtentsOfByteChunkByExpression(x_target, p_index, t_start, t_count);
139+
t_start += t_count;
137140

138141
MCAutoDataRef t_data;
139142
if (!MCDataMutableCopy(x_target, &t_data))
140143
return;
141144

142-
if (!MCDataInsert(*t_data, t_start + t_count, p_value))
145+
if (!MCDataInsert(*t_data, t_start, p_value))
143146
return;
144147

145-
MCValueRelease(x_target);
146-
if (!MCDataCopy(*t_data, x_target))
148+
MCAutoDataRef t_new_data;
149+
if (!MCDataCopy(*t_data, &t_new_data))
147150
return;
151+
152+
MCValueAssign(x_target, *t_new_data);
148153
}
149154

150155
extern "C" void MCByteStoreBeforeByteOf(MCDataRef p_value, index_t p_index, MCDataRef& x_target)
@@ -159,9 +164,11 @@ extern "C" void MCByteStoreBeforeByteOf(MCDataRef p_value, index_t p_index, MCDa
159164
if (!MCDataInsert(*t_data, t_start, p_value))
160165
return;
161166

162-
MCValueRelease(x_target);
163-
if (!MCDataCopy(*t_data, x_target))
167+
MCAutoDataRef t_new_data;
168+
if (!MCDataCopy(*t_data, &t_new_data))
164169
return;
170+
171+
MCValueAssign(x_target, *t_new_data);
165172
}
166173

167174
////////////////////////////////////////////////////////////////////////////////////////////////////

libscript/src/module-char.cpp

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,18 @@ extern "C" void MCCharStoreCharRangeOf(MCStringRef p_value, index_t p_start, ind
4848
uindex_t t_start, t_count;
4949
MCChunkGetExtentsOfCodepointChunkByRange(x_target, p_start, p_finish, t_start, t_count);
5050

51-
MCAutoStringRef t_data;
52-
if (!MCStringMutableCopy(x_target, &t_data))
51+
MCAutoStringRef t_string;
52+
if (!MCStringMutableCopy(x_target, &t_string))
5353
return;
5454

55-
if (!MCStringReplace(*t_data, MCRangeMake(t_start, t_count), p_value))
55+
if (!MCStringReplace(*t_string, MCRangeMake(t_start, t_count), p_value))
5656
return;
5757

58-
MCValueRelease(x_target);
59-
if (!MCStringCopy(*t_data, x_target))
58+
MCAutoStringRef t_new_string;
59+
if (!MCStringCopy(*t_string, &t_new_string))
6060
return;
61+
62+
MCValueAssign(x_target, *t_new_string);
6163
}
6264

6365
extern "C" void MCCharFetchCharOf(index_t p_index, MCStringRef p_target, MCStringRef& r_output)
@@ -74,34 +76,39 @@ extern "C" void MCCharStoreAfterCharOf(MCStringRef p_value, index_t p_index, MCS
7476
{
7577
uindex_t t_start, t_count;
7678
MCChunkGetExtentsOfCodepointChunkByRange(x_target, p_index, p_index, t_start, t_count);
79+
t_start += t_count;
7780

78-
MCAutoStringRef t_data;
79-
if (!MCStringMutableCopy(x_target, &t_data))
81+
MCAutoStringRef t_string;
82+
if (!MCStringMutableCopy(x_target, &t_string))
8083
return;
8184

82-
if (!MCStringInsert(*t_data, t_start + t_count, p_value))
85+
if (!MCStringInsert(*t_string, t_start, p_value))
8386
return;
8487

85-
MCValueRelease(x_target);
86-
if (!MCStringCopy(*t_data, x_target))
88+
MCAutoStringRef t_new_string;
89+
if (!MCStringCopy(*t_string, &t_new_string))
8790
return;
91+
92+
MCValueAssign(x_target, *t_new_string);
8893
}
8994

9095
extern "C" void MCCharStoreBeforeCharOf(MCStringRef p_value, index_t p_index, MCStringRef& x_target)
9196
{
9297
uindex_t t_start, t_count;
9398
MCChunkGetExtentsOfCodepointChunkByRange(x_target, p_index, p_index, t_start, t_count);
9499

95-
MCAutoStringRef t_data;
96-
if (!MCStringMutableCopy(x_target, &t_data))
100+
MCAutoStringRef t_string;
101+
if (!MCStringMutableCopy(x_target, &t_string))
97102
return;
98103

99-
if (!MCStringInsert(*t_data, t_start, p_value))
104+
if (!MCStringInsert(*t_string, t_start, p_value))
100105
return;
101106

102-
MCValueRelease(x_target);
103-
if (!MCStringCopy(*t_data, x_target))
107+
MCAutoStringRef t_new_string;
108+
if (!MCStringCopy(*t_string, &t_new_string))
104109
return;
110+
111+
MCValueAssign(x_target, *t_new_string);
105112
}
106113

107114
#if 0

0 commit comments

Comments
 (0)