@@ -6,35 +6,42 @@ enum Executor<Output> {
66 _ program: MEProgram ,
77 _ input: String ,
88 subjectBounds: Range < String . Index > ,
9- searchBounds: Range < String . Index >
9+ searchBounds: Range < String . Index > ,
10+ context: Debugger . Context
1011 ) throws -> Regex < Output > . Match ? {
1112 try Executor . _run (
1213 program,
1314 input,
1415 subjectBounds: subjectBounds,
1516 searchBounds: searchBounds,
16- mode: . partialFromFront)
17+ mode: . partialFromFront,
18+ context: context
19+ )
1720 }
1821
1922 static func wholeMatch(
2023 _ program: MEProgram ,
2124 _ input: String ,
2225 subjectBounds: Range < String . Index > ,
23- searchBounds: Range < String . Index >
26+ searchBounds: Range < String . Index > ,
27+ context: Debugger . Context
2428 ) throws -> Regex < Output > . Match ? {
2529 try Executor . _run (
2630 program,
2731 input,
2832 subjectBounds: subjectBounds,
2933 searchBounds: searchBounds,
30- mode: . wholeString)
34+ mode: . wholeString,
35+ context: context
36+ )
3137 }
3238
3339 static func firstMatch(
3440 _ program: MEProgram ,
3541 _ input: String ,
3642 subjectBounds: Range < String . Index > ,
37- searchBounds: Range < String . Index >
43+ searchBounds: Range < String . Index > ,
44+ context: Debugger . Context
3845 ) throws -> Regex < Output > . Match ? {
3946 var cpu = Processor (
4047 program: program,
@@ -45,19 +52,22 @@ enum Executor<Output> {
4552 )
4653 return try Executor . _firstMatch (
4754 program,
48- using: & cpu)
55+ using: & cpu,
56+ context: context
57+ )
4958 }
5059
5160 static func _firstMatch(
5261 _ program: MEProgram ,
53- using cpu: inout Processor
62+ using cpu: inout Processor ,
63+ context: Debugger . Context
5464 ) throws -> Regex < Output > . Match ? {
5565 let isGraphemeSemantic = program. initialOptions. semanticLevel == . graphemeCluster
5666
5767 var low = cpu. searchBounds. lowerBound
5868 let high = cpu. searchBounds. upperBound
5969 while true {
60- if let m = try Executor . _run ( program, & cpu) {
70+ if let m = try Executor . _run ( program, & cpu, context ) {
6171 return m
6272 }
6373 // Fast-path for start-anchored regex
@@ -84,24 +94,26 @@ extension Executor {
8494 _ input: String ,
8595 subjectBounds: Range < String . Index > ,
8696 searchBounds: Range < String . Index > ,
87- mode: MatchMode
97+ mode: MatchMode ,
98+ context: Debugger . Context
8899 ) throws -> Regex < Output > . Match ? {
89100 var cpu = Processor (
90101 program: program,
91102 input: input,
92103 subjectBounds: subjectBounds,
93104 searchBounds: searchBounds,
94105 matchMode: mode)
95- return try _run ( program, & cpu)
106+ return try _run ( program, & cpu, context )
96107 }
97108
98109 static func _run(
99110 _ program: MEProgram ,
100- _ cpu: inout Processor
111+ _ cpu: inout Processor ,
112+ _ context: Debugger . Context
101113 ) throws -> Regex < Output > . Match ? {
102114 let startPosition = cpu. currentPosition
103- Debugger . Context . shared . start = startPosition. utf16Offset ( in: cpu. input)
104- guard let endIdx = try cpu. run ( ) else {
115+ context . start = startPosition. utf16Offset ( in: cpu. input)
116+ guard let endIdx = try cpu. run ( context ) else {
105117 return nil
106118 }
107119 let range = startPosition..< endIdx
@@ -113,7 +125,7 @@ extension Executor {
113125 } }
114126
115127extension Processor {
116- fileprivate mutating func run( ) throws -> Input . Index ? {
128+ fileprivate mutating func run( _ context : Debugger . Context ) throws -> Input . Index ? {
117129 if self . state == . fail {
118130 if let e = failureReason {
119131 throw e
@@ -122,7 +134,6 @@ extension Processor {
122134 }
123135 assert ( isReset ( ) )
124136 while true {
125- let context = Debugger . Context. shared
126137 context. programCounter = controller. pc. rawValue
127138
128139 switch self . state {
0 commit comments