@@ -18,21 +18,19 @@ struct SentinelValue: Hashable, CustomStringConvertible {
18
18
extension Processor {
19
19
/// Our register file
20
20
struct Registers {
21
- // currently, these are static readonly
21
+
22
+ // MARK: static / read-only, non-resettable
23
+
24
+ // Verbatim elements to compare against
22
25
var elements : [ Element ]
23
26
24
- // currently, these are static readonly
27
+ // Verbatim sequences to compare against
25
28
//
26
- // TODO: We want to be `String` instead of `[Character]`...
29
+ // TODO: Degenericize Processor and store Strings
27
30
var sequences : [ [ Element ] ] = [ ]
28
31
29
- // currently, hold output of assertions
30
- var bools : [ Bool ] // TODO: bitset
31
-
32
- // currently, these are static readonly
33
32
var consumeFunctions : [ MEProgram < Input > . ConsumeFunction ]
34
33
35
- // currently, these are static readonly
36
34
var assertionFunctions : [ MEProgram < Input > . AssertionFunction ]
37
35
38
36
// Captured-value constructors
@@ -44,69 +42,61 @@ extension Processor {
44
42
// currently, these are for comments and abort messages
45
43
var strings : [ String ]
46
44
45
+ // MARK: writeable, resettable
46
+
47
+ // currently, hold output of assertions
48
+ var bools : [ Bool ] // TODO: bitset
49
+
47
50
// currently, useful for range-based quantification
48
51
var ints : [ Int ]
49
52
50
- // unused
51
- var floats : [ Double ] = [ ]
52
-
53
53
// Currently, used for `movePosition` and `matchSlice`
54
54
var positions : [ Position ] = [ ]
55
55
56
56
var values : [ Any ]
57
+ }
58
+ }
57
59
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
108
83
}
109
84
}
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
+ }
110
100
}
111
101
112
102
extension Processor . Registers {
@@ -141,20 +131,26 @@ extension Processor.Registers {
141
131
142
132
self . ints = Array ( repeating: 0 , count: info. ints)
143
133
144
- self . floats = Array ( repeating: 0 , count: info. floats)
145
-
146
134
self . positions = Array ( repeating: sentinel, count: info. positions)
147
135
148
136
self . values = Array (
149
137
repeating: SentinelValue ( ) , count: info. values)
138
+ }
150
139
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
+ }
156
147
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
+ }
158
154
}
159
155
}
160
156
@@ -196,12 +192,7 @@ extension Processor.Registers: CustomStringConvertible {
196
192
\( formatRegisters ( " bools " , bools) ) \
197
193
\( formatRegisters ( " strings " , strings) ) \
198
194
\( formatRegisters ( " ints " , ints) ) \
199
- \( formatRegisters ( " floats " , floats) ) \
200
195
\( formatRegisters ( " positions " , positions) ) \
201
- \( formatRegisters ( " instructionAddresses " , instructionAddresses) ) \
202
- \( formatRegisters ( " classStackAddresses " , classStackAddresses) ) \
203
- \( formatRegisters ( " positionStackAddresses " , positionStackAddresses) ) \
204
- \( formatRegisters ( " savePointAddresses " , savePointAddresses) ) \
205
196
206
197
"""
207
198
}
0 commit comments