Start Evaluation

Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
This commit is contained in:
Will Hawkins
2026-02-10 03:37:57 -05:00
parent 0dd5ce4be3
commit 3693bdc02d
15 changed files with 635 additions and 119 deletions
+24
View File
@@ -17,12 +17,27 @@
open class ProgramExecution: CustomStringConvertible {
public var scopes: Scopes = Scopes()
var error: Error?
public init() {}
open var description: String {
return "Runtime:\nScopes: \(scopes)"
}
public func hasError() -> Bool {
return self.error != nil
}
public func getError() -> Error? {
return self.error
}
public func setError(error: Error) -> ProgramExecution {
let npe = self
npe.error = error
return npe
}
}
@@ -96,6 +111,15 @@ public struct Scopes: CustomStringConvertible {
return s
}
public func evaluate(identifier: Identifier) -> Result<P4Value> {
for scope in scopes {
if let vari = scope.lookup(identifier: identifier) {
return .Ok(vari.value)
}
}
return .Error(Error(withMessage: "Cannot find \(identifier) in scope."))
}
public var count: Int {
get {
scopes.count