Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DRAFT] [BROKEN] Make Processor ~Copyable #681

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sources/_StringProcessing/Engine/Processor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ struct Controller {
}
}

struct Processor {
struct Processor: ~Copyable {
typealias Input = String
typealias Element = Input.Element

Expand Down
2 changes: 1 addition & 1 deletion Sources/_StringProcessing/Engine/Tracing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


// TODO: Remove this protocol (and/or reuse it for something like a FastProcessor)
extension Processor: TracedProcessor {
extension Processor /*: TracedProcessor*/ {
var cycleCount: Int { metrics.cycleCount }
var isTracingEnabled: Bool { metrics.isTracingEnabled }

Expand Down
52 changes: 26 additions & 26 deletions Sources/_StringProcessing/Utility/Protocols.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,30 @@ protocol InstructionProtocol {
var operandPC: InstructionAddress? { get }
}

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 }
}
//protocol ProcessorProtocol: ~Copyable {
// 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 }
//}

74 changes: 37 additions & 37 deletions Sources/_StringProcessing/Utility/Traced.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,40 +12,40 @@

// TODO: Place shared formatting and trace infrastructure here

protocol Traced {
var isTracingEnabled: Bool { get }
}

protocol TracedProcessor: ProcessorProtocol, Traced {
// Empty defaulted
func formatCallStack() -> String // empty default
func formatSavePoints() -> String // empty default
func formatRegisters() -> String // empty default

// Non-empty defaulted
func formatTrace() -> String
func formatInput() -> String
func formatInstructionWindow(windowSize: Int) -> String
}
//protocol Traced {
// var isTracingEnabled: Bool { get }
//}
//
//protocol TracedProcessor: ProcessorProtocol, Traced {
// // Empty defaulted
// func formatCallStack() -> String // empty default
// func formatSavePoints() -> String // empty default
// func formatRegisters() -> String // empty default
//
// // Non-empty defaulted
// func formatTrace() -> String
// func formatInput() -> String
// func formatInstructionWindow(windowSize: Int) -> String
//}

func lineNumber(_ i: Int) -> String {
"[\(i)]"
}
func lineNumber(_ pc: InstructionAddress) -> String {
lineNumber(pc.rawValue)
}

extension TracedProcessor where Registers: Collection{
func formatRegisters() -> String {
typealias E = ()
if !registers.isEmpty {
return "\(registers)\n"
}
return ""
}
}

extension TracedProcessor {
//
//extension Processor {
// func formatRegisters() -> String {
// typealias E = ()
// if !registers.isEmpty {
// return "\(registers)\n"
// }
// return ""
// }
//}

extension Processor {
func printTrace() { print(formatTrace()) }

func trace() {
Expand All @@ -60,16 +60,16 @@ extension TracedProcessor {
return ""
}

func formatSavePoints() -> String {
if !savePoints.isEmpty {
var result = "save points:\n"
for point in savePoints {
result += " \(point)\n"
}
return result
}
return ""
}
// func formatSavePoints() -> String {
// if !savePoints.isEmpty {
// var result = "save points:\n"
// for point in savePoints {
// result += " \(point)\n"
// }
// return result
// }
// return ""
// }

func formatRegisters() -> String {
typealias E = ()
Expand Down