forked from swiftlang/swift-experimental-string-processing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProtocols.swift
45 lines (32 loc) · 1.16 KB
/
Protocols.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// These currently only drive tracing/formatting, but could drive
// more
public protocol InstructionProtocol {
var operandPC: InstructionAddress? { get }
}
public protocol ProcessorProtocol {
associatedtype Input: Collection
associatedtype Instruction: InstructionProtocol
associatedtype SavePoint = ()
associatedtype Registers = ()
var cycleCount: Int { get }
var input: Input { get }
var currentPosition: Input.Index { get }
var currentPC: InstructionAddress { get }
var instructions: InstructionList<Instruction> { get }
var isAcceptState: Bool { get }
var isFailState: Bool { get }
// Provide to get call stack formatting, default empty
var callStack: Array<InstructionAddress> { get }
// Provide to get save point formatting, default empty
var savePoints: Array<SavePoint> { get }
// Provide to get register formatting, default empty
var registers: Registers { get }
}
extension ProcessorProtocol {
public func fetch() -> Instruction {
instructions[currentPC]
}
public var callStack: Array<InstructionAddress> { [] }
// public var savePoints: Array<SavePoint> { [] }
public var registers: Array<Registers> { [] }
}