@@ -18,21 +18,19 @@ struct SentinelValue: Hashable, CustomStringConvertible {
1818extension Processor {
1919 /// Our register file
2020 struct Registers {
21- // currently, these are static readonly
21+
22+ // MARK: static / read-only, non-resettable
23+
24+ // Verbatim elements to compare against
2225 var elements : [ Element ]
2326
24- // currently, these are static readonly
27+ // Verbatim sequences to compare against
2528 //
26- // TODO: We want to be `String` instead of `[Character]`...
29+ // TODO: Degenericize Processor and store Strings
2730 var sequences : [ [ Element ] ] = [ ]
2831
29- // currently, hold output of assertions
30- var bools : [ Bool ] // TODO: bitset
31-
32- // currently, these are static readonly
3332 var consumeFunctions : [ MEProgram < Input > . ConsumeFunction ]
3433
35- // currently, these are static readonly
3634 var assertionFunctions : [ MEProgram < Input > . AssertionFunction ]
3735
3836 // Captured-value constructors
@@ -44,69 +42,61 @@ extension Processor {
4442 // currently, these are for comments and abort messages
4543 var strings : [ String ]
4644
45+ // MARK: writeable, resettable
46+
47+ // currently, hold output of assertions
48+ var bools : [ Bool ] // TODO: bitset
49+
4750 // currently, useful for range-based quantification
4851 var ints : [ Int ]
4952
50- // unused
51- var floats : [ Double ] = [ ]
52-
5353 // Currently, used for `movePosition` and `matchSlice`
5454 var positions : [ Position ] = [ ]
5555
5656 var values : [ Any ]
57+ }
58+ }
5759
58- // unused
59- var instructionAddresses : [ InstructionAddress ] = [ ]
60-
61- // unused, any application?
62- var classStackAddresses : [ CallStackAddress ] = [ ]
63-
64- // unused, any application?
65- var positionStackAddresses : [ PositionStackAddress ] = [ ]
66-
67- // unused, any application?
68- var savePointAddresses : [ SavePointStackAddress ] = [ ]
69-
70- subscript( _ i: StringRegister ) -> String {
71- strings [ i. rawValue]
72- }
73- subscript( _ i: SequenceRegister ) -> [ Element ] {
74- sequences [ i. rawValue]
75- }
76- subscript( _ i: IntRegister ) -> Int {
77- get { ints [ i. rawValue] }
78- set { ints [ i. rawValue] = newValue }
79- }
80- subscript( _ i: BoolRegister ) -> Bool {
81- get { bools [ i. rawValue] }
82- set { bools [ i. rawValue] = newValue }
83- }
84- subscript( _ i: PositionRegister ) -> Position {
85- get { positions [ i. rawValue] }
86- set { positions [ i. rawValue] = newValue }
87- }
88- subscript( _ i: ValueRegister ) -> Any {
89- get { values [ i. rawValue] }
90- set {
91- values [ i. rawValue] = newValue
92- }
93- }
94- subscript( _ i: ElementRegister ) -> Element {
95- elements [ i. rawValue]
96- }
97- subscript( _ i: ConsumeFunctionRegister ) -> MEProgram < Input > . ConsumeFunction {
98- consumeFunctions [ i. rawValue]
99- }
100- subscript( _ i: AssertionFunctionRegister ) -> MEProgram < Input > . AssertionFunction {
101- assertionFunctions [ i. rawValue]
102- }
103- subscript( _ i: TransformRegister ) -> MEProgram < Input > . TransformFunction {
104- transformFunctions [ i. rawValue]
105- }
106- subscript( _ i: MatcherRegister ) -> MEProgram < Input > . MatcherFunction {
107- matcherFunctions [ i. rawValue]
60+ extension Processor . Registers {
61+ subscript( _ i: StringRegister ) -> String {
62+ strings [ i. rawValue]
63+ }
64+ subscript( _ i: SequenceRegister ) -> [ Input . Element ] {
65+ sequences [ i. rawValue]
66+ }
67+ subscript( _ i: IntRegister ) -> Int {
68+ get { ints [ i. rawValue] }
69+ set { ints [ i. rawValue] = newValue }
70+ }
71+ subscript( _ i: BoolRegister ) -> Bool {
72+ get { bools [ i. rawValue] }
73+ set { bools [ i. rawValue] = newValue }
74+ }
75+ subscript( _ i: PositionRegister ) -> Input . Index {
76+ get { positions [ i. rawValue] }
77+ set { positions [ i. rawValue] = newValue }
78+ }
79+ subscript( _ i: ValueRegister ) -> Any {
80+ get { values [ i. rawValue] }
81+ set {
82+ values [ i. rawValue] = newValue
10883 }
10984 }
85+ subscript( _ i: ElementRegister ) -> Input . Element {
86+ elements [ i. rawValue]
87+ }
88+ subscript( _ i: ConsumeFunctionRegister ) -> MEProgram < Input > . ConsumeFunction {
89+ consumeFunctions [ i. rawValue]
90+ }
91+ subscript( _ i: AssertionFunctionRegister ) -> MEProgram < Input > . AssertionFunction {
92+ assertionFunctions [ i. rawValue]
93+ }
94+ subscript( _ i: TransformRegister ) -> MEProgram < Input > . TransformFunction {
95+ transformFunctions [ i. rawValue]
96+ }
97+ subscript( _ i: MatcherRegister ) -> MEProgram < Input > . MatcherFunction {
98+ matcherFunctions [ i. rawValue]
99+ }
110100}
111101
112102extension Processor . Registers {
@@ -141,20 +131,26 @@ extension Processor.Registers {
141131
142132 self . ints = Array ( repeating: 0 , count: info. ints)
143133
144- self . floats = Array ( repeating: 0 , count: info. floats)
145-
146134 self . positions = Array ( repeating: sentinel, count: info. positions)
147135
148136 self . values = Array (
149137 repeating: SentinelValue ( ) , count: info. values)
138+ }
150139
151- self . instructionAddresses = Array ( repeating: 0 , count: info. instructionAddresses)
152-
153- self . classStackAddresses = Array ( repeating: 0 , count: info. classStackAddresses)
154-
155- self . positionStackAddresses = Array ( repeating: 0 , count: info. positionStackAddresses)
140+ mutating func reset( sentinel: Input . Index ) {
141+ self . bools. _setAll ( to: false )
142+ self . ints. _setAll ( to: 0 )
143+ self . positions. _setAll ( to: sentinel)
144+ self . values. _setAll ( to: SentinelValue ( ) )
145+ }
146+ }
156147
157- self . savePointAddresses = Array ( repeating: 0 , count: info. savePointAddresses)
148+ // TODO: Productize into general algorithm
149+ extension MutableCollection {
150+ mutating func _setAll( to e: Element ) {
151+ for idx in self . indices {
152+ self [ idx] = e
153+ }
158154 }
159155}
160156
@@ -196,12 +192,7 @@ extension Processor.Registers: CustomStringConvertible {
196192 \( formatRegisters ( " bools " , bools) ) \
197193 \( formatRegisters ( " strings " , strings) ) \
198194 \( formatRegisters ( " ints " , ints) ) \
199- \( formatRegisters ( " floats " , floats) ) \
200195 \( formatRegisters ( " positions " , positions) ) \
201- \( formatRegisters ( " instructionAddresses " , instructionAddresses) ) \
202- \( formatRegisters ( " classStackAddresses " , classStackAddresses) ) \
203- \( formatRegisters ( " positionStackAddresses " , positionStackAddresses) ) \
204- \( formatRegisters ( " savePointAddresses " , savePointAddresses) ) \
205196
206197 """
207198 }
0 commit comments