@@ -17,7 +17,6 @@ extension MEProgram {
17
17
18
18
var elements = TypedSetVector < Input . Element , _ElementRegister > ( )
19
19
var sequences = TypedSetVector < [ Input . Element ] , _SequenceRegister > ( )
20
- var strings = TypedSetVector < String , _StringRegister > ( )
21
20
22
21
var consumeFunctions : [ ConsumeFunction ] = [ ]
23
22
var assertionFunctions : [ AssertionFunction ] = [ ]
@@ -29,9 +28,7 @@ extension MEProgram {
29
28
var addressFixups : [ ( InstructionAddress , AddressFixup ) ] = [ ]
30
29
31
30
// Registers
32
- var nextBoolRegister = BoolRegister ( 0 )
33
31
var nextIntRegister = IntRegister ( 0 )
34
- var nextPositionRegister = PositionRegister ( 0 )
35
32
var nextCaptureRegister = CaptureRegister ( 0 )
36
33
var nextValueRegister = ValueRegister ( 0 )
37
34
@@ -79,20 +76,6 @@ extension MEProgram.Builder {
79
76
. init( instructions. endIndex - 1 )
80
77
}
81
78
82
- mutating func buildNop( _ r: StringRegister ? = nil ) {
83
- instructions. append ( . init( . nop, . init( optionalString: r) ) )
84
- }
85
- mutating func buildNop( _ s: String ) {
86
- buildNop ( strings. store ( s) )
87
- }
88
-
89
- mutating func buildDecrement(
90
- _ i: IntRegister , nowZero: BoolRegister
91
- ) {
92
- instructions. append ( . init(
93
- . decrement, . init( bool: nowZero, int: i) ) )
94
- }
95
-
96
79
mutating func buildMoveImmediate(
97
80
_ value: UInt64 , into: IntRegister
98
81
) {
@@ -108,24 +91,10 @@ extension MEProgram.Builder {
108
91
buildMoveImmediate ( uint, into: into)
109
92
}
110
93
111
- mutating func buildMoveCurrentPosition(
112
- into: PositionRegister
113
- ) {
114
- instructions. append ( . init(
115
- . movePosition, . init( position: into) ) )
116
- }
117
-
118
94
mutating func buildBranch( to t: AddressToken ) {
119
95
instructions. append ( . init( . branch) )
120
96
fixup ( to: t)
121
97
}
122
- mutating func buildCondBranch(
123
- _ condition: BoolRegister , to t: AddressToken
124
- ) {
125
- instructions. append (
126
- . init( . condBranch, . init( bool: condition) ) )
127
- fixup ( to: t)
128
- }
129
98
130
99
mutating func buildCondBranch(
131
100
to t: AddressToken , ifZeroElseDecrement i: IntRegister
@@ -157,27 +126,9 @@ extension MEProgram.Builder {
157
126
instructions. append ( . init( . clearThrough) )
158
127
fixup ( to: t)
159
128
}
160
- mutating func buildRestore( ) {
161
- instructions. append ( . init( . restore) )
162
- }
163
129
mutating func buildFail( ) {
164
130
instructions. append ( . init( . fail) )
165
131
}
166
- mutating func buildCall( _ t: AddressToken ) {
167
- instructions. append ( . init( . call) )
168
- fixup ( to: t)
169
- }
170
- mutating func buildRet( ) {
171
- instructions. append ( . init( . ret) )
172
- }
173
-
174
- mutating func buildAbort( _ s: StringRegister ? = nil ) {
175
- instructions. append ( . init(
176
- . abort, . init( optionalString: s) ) )
177
- }
178
- mutating func buildAbort( _ s: String ) {
179
- buildAbort ( strings. store ( s) )
180
- }
181
132
182
133
mutating func buildAdvance( _ n: Distance ) {
183
134
instructions. append ( . init( . advance, . init( distance: n) ) )
@@ -196,14 +147,6 @@ extension MEProgram.Builder {
196
147
. init( sequence: sequences. store ( . init( s) ) ) ) )
197
148
}
198
149
199
- mutating func buildMatchSlice(
200
- lower: PositionRegister , upper: PositionRegister
201
- ) {
202
- instructions. append ( . init(
203
- . matchSlice,
204
- . init( pos: lower, pos2: upper) ) )
205
- }
206
-
207
150
mutating func buildConsume(
208
151
by p: @escaping MEProgram . ConsumeFunction
209
152
) {
@@ -218,21 +161,10 @@ extension MEProgram.Builder {
218
161
. assertBy, . init( assertion: makeAssertionFunction ( p) ) ) )
219
162
}
220
163
221
- mutating func buildAssert(
222
- _ e: Character , into cond: BoolRegister
223
- ) {
224
- instructions. append ( . init( . assertion, . init(
225
- element: elements. store ( e) , bool: cond) ) )
226
- }
227
-
228
164
mutating func buildAccept( ) {
229
165
instructions. append ( . init( . accept) )
230
166
}
231
167
232
- mutating func buildPrint( _ s: StringRegister ) {
233
- instructions. append ( . init( . print, . init( string: s) ) )
234
- }
235
-
236
168
mutating func buildBeginCapture(
237
169
_ cap: CaptureRegister
238
170
) {
@@ -315,13 +247,10 @@ extension MEProgram.Builder {
315
247
let payload : Instruction . Payload
316
248
317
249
switch inst. opcode {
318
- case . condBranch:
319
- payload = . init( addr: addr, bool: inst. payload. bool)
320
-
321
250
case . condBranchZeroElseDecrement:
322
251
payload = . init( addr: addr, int: inst. payload. int)
323
252
324
- case . branch, . save, . saveAddress, . call , . clearThrough:
253
+ case . branch, . save, . saveAddress, . clearThrough:
325
254
payload = . init( addr: addr)
326
255
327
256
case . splitSaving:
@@ -342,10 +271,7 @@ extension MEProgram.Builder {
342
271
var regInfo = MEProgram . RegisterInfo ( )
343
272
regInfo. elements = elements. count
344
273
regInfo. sequences = sequences. count
345
- regInfo. strings = strings. count
346
- regInfo. bools = nextBoolRegister. rawValue
347
274
regInfo. ints = nextIntRegister. rawValue
348
- regInfo. positions = nextPositionRegister. rawValue
349
275
regInfo. values = nextValueRegister. rawValue
350
276
regInfo. consumeFunctions = consumeFunctions. count
351
277
regInfo. assertionFunctions = assertionFunctions. count
@@ -357,7 +283,6 @@ extension MEProgram.Builder {
357
283
instructions: InstructionList ( instructions) ,
358
284
staticElements: elements. stored,
359
285
staticSequences: sequences. stored,
360
- staticStrings: strings. stored,
361
286
staticConsumeFunctions: consumeFunctions,
362
287
staticAssertionFunctions: assertionFunctions,
363
288
staticTransformFunctions: transformFunctions,
@@ -468,18 +393,10 @@ extension MEProgram.Builder {
468
393
return nextCaptureRegister
469
394
}
470
395
471
- mutating func makeBoolRegister( ) -> BoolRegister {
472
- defer { nextBoolRegister. rawValue += 1 }
473
- return nextBoolRegister
474
- }
475
396
mutating func makeIntRegister( ) -> IntRegister {
476
397
defer { nextIntRegister. rawValue += 1 }
477
398
return nextIntRegister
478
399
}
479
- mutating func makePositionRegister( ) -> PositionRegister {
480
- defer { nextPositionRegister. rawValue += 1 }
481
- return nextPositionRegister
482
- }
483
400
mutating func makeValueRegister( ) -> ValueRegister {
484
401
defer { nextValueRegister. rawValue += 1 }
485
402
return nextValueRegister
@@ -494,32 +411,6 @@ extension MEProgram.Builder {
494
411
return r
495
412
}
496
413
497
- // Allocate and initialize a register
498
- mutating func makePositionRegister(
499
- initializingWithCurrentPosition: ( )
500
- ) -> PositionRegister {
501
- let r = makePositionRegister ( )
502
- self . buildMoveCurrentPosition ( into: r)
503
- return r
504
- }
505
-
506
- // 'kill' or release allocated registers
507
- mutating func kill( _ r: IntRegister ) {
508
- // TODO: Release/reuse registers, for now nop makes
509
- // reading the code easier
510
- buildNop ( " kill \( r) " )
511
- }
512
- mutating func kill( _ r: BoolRegister ) {
513
- // TODO: Release/reuse registers, for now nop makes
514
- // reading the code easier
515
- buildNop ( " kill \( r) " )
516
- }
517
- mutating func kill( _ r: PositionRegister ) {
518
- // TODO: Release/reuse registers, for now nop makes
519
- // reading the code easier
520
- buildNop ( " kill \( r) " )
521
- }
522
-
523
414
// TODO: A register-mapping helper struct, which could release
524
415
// registers without monotonicity required
525
416
0 commit comments