@@ -26,4 +26,3 @@ public typealias TypeTypeScope = Scope<P4Type>
|
||||
|
||||
/// Scopes that resolve type identifiers to their types.
|
||||
public typealias TypeTypeScopes = Scopes<P4Type>
|
||||
|
||||
|
||||
@@ -120,12 +120,13 @@ public struct P4StructFields: Sequence, CustomStringConvertible, Equatable {
|
||||
|
||||
public func describe_with_values(values: [P4Value?]) -> String {
|
||||
assert(values.count == self.count())
|
||||
return zip(self.fields, values).map() { (field, value) in
|
||||
let actual_value = if let v = value {
|
||||
v.description
|
||||
} else {
|
||||
"Unset"
|
||||
}
|
||||
return zip(self.fields, values).map { (field, value) in
|
||||
let actual_value =
|
||||
if let v = value {
|
||||
v.description
|
||||
} else {
|
||||
"Unset"
|
||||
}
|
||||
return String("\(field): \(actual_value)")
|
||||
}.joined(separator: "; ")
|
||||
}
|
||||
@@ -211,7 +212,11 @@ public class P4StructValue: P4Value {
|
||||
for field_idx in 0..<stype.fields.count() {
|
||||
if stype.fields.fields[field_idx] == field {
|
||||
if !stype.fields.fields[field_idx].type.eq(rhs: to.type()) {
|
||||
return .Error(Error(withMessage: "Cannot assign value with type \(to.type()) to field with type \(stype.fields.fields[field_idx].type))"))
|
||||
return .Error(
|
||||
Error(
|
||||
withMessage:
|
||||
"Cannot assign value with type \(to.type()) to field with type \(stype.fields.fields[field_idx].type))"
|
||||
))
|
||||
}
|
||||
updated_values[field_idx] = to
|
||||
break
|
||||
|
||||
@@ -42,13 +42,15 @@ public protocol P4Value: EvaluatableExpression, CustomStringConvertible {
|
||||
func eq(rhs: P4Value) -> Bool
|
||||
}
|
||||
|
||||
public extension P4Value {
|
||||
func evaluate(execution: ProgramExecution) -> Result<P4Value> {
|
||||
extension P4Value {
|
||||
public func evaluate(execution: ProgramExecution) -> Result<P4Value> {
|
||||
return Result.Ok(self)
|
||||
}
|
||||
}
|
||||
|
||||
public protocol EvaluatableLValueExpression: EvaluatableExpression {
|
||||
func set(to: P4Value, inScopes scopes: VarValueScopes, duringExecution execution: ProgramExecution) -> Result<(VarValueScopes, P4Value)>
|
||||
func set(
|
||||
to: P4Value, inScopes scopes: VarValueScopes, duringExecution execution: ProgramExecution
|
||||
) -> Result<(VarValueScopes, P4Value)>
|
||||
func check(to: EvaluatableExpression, inScopes scopes: VarTypeScopes) -> Result<()>
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user