@@ -708,7 +708,9 @@ extension TableKeys: Compilable {
|
|||||||
|
|
||||||
if !errors.isEmpty {
|
if !errors.isEmpty {
|
||||||
return .Error(
|
return .Error(
|
||||||
ErrorOnNode(node: node, withError: "Error(s) parsing table key: "
|
ErrorOnNode(
|
||||||
|
node: node,
|
||||||
|
withError: "Error(s) parsing table key: "
|
||||||
+ (errors.map { error in
|
+ (errors.map { error in
|
||||||
return "\(error.msg)"
|
return "\(error.msg)"
|
||||||
}.joined(separator: ";"))))
|
}.joined(separator: ";"))))
|
||||||
@@ -740,10 +742,12 @@ extension TableActionsProperty: Compilable {
|
|||||||
result: current_node, thing: walker.getNext(),
|
result: current_node, thing: walker.getNext(),
|
||||||
or: Result<(TableActionsProperty, CompilerContext)>.Error(
|
or: Result<(TableActionsProperty, CompilerContext)>.Error(
|
||||||
ErrorOnNode(
|
ErrorOnNode(
|
||||||
node: node, withError: "Missing table actions declaration component in control declaration"))
|
node: node,
|
||||||
|
withError: "Missing table actions declaration component in control declaration"))
|
||||||
)
|
)
|
||||||
|
|
||||||
let (actions, errors) = walker.try_map(n: node.childCount - 1, onlyNamed: true) { current_node in
|
let (actions, errors) = walker.try_map(n: node.childCount - 1, onlyNamed: true) {
|
||||||
|
current_node in
|
||||||
switch Identifier.Compile(node: current_node, withContext: context) {
|
switch Identifier.Compile(node: current_node, withContext: context) {
|
||||||
case .Ok(let listed_action):
|
case .Ok(let listed_action):
|
||||||
switch context.types.lookup(identifier: listed_action) {
|
switch context.types.lookup(identifier: listed_action) {
|
||||||
@@ -761,7 +765,9 @@ extension TableActionsProperty: Compilable {
|
|||||||
|
|
||||||
if !errors.isEmpty {
|
if !errors.isEmpty {
|
||||||
return .Error(
|
return .Error(
|
||||||
ErrorOnNode(node: node, withError: "Error(s) parsing table actions: "
|
ErrorOnNode(
|
||||||
|
node: node,
|
||||||
|
withError: "Error(s) parsing table actions: "
|
||||||
+ (errors.map { error in
|
+ (errors.map { error in
|
||||||
return "\(error.msg)"
|
return "\(error.msg)"
|
||||||
}.joined(separator: ";"))))
|
}.joined(separator: ";"))))
|
||||||
@@ -808,7 +814,9 @@ extension TablePropertyList: Compilable {
|
|||||||
|
|
||||||
if !errors.isEmpty {
|
if !errors.isEmpty {
|
||||||
return .Error(
|
return .Error(
|
||||||
ErrorOnNode(node: node, withError: "Error(s) parsing property list: "
|
ErrorOnNode(
|
||||||
|
node: node,
|
||||||
|
withError: "Error(s) parsing property list: "
|
||||||
+ (errors.map { error in
|
+ (errors.map { error in
|
||||||
return "\(error.msg)"
|
return "\(error.msg)"
|
||||||
}.joined(separator: ";"))))
|
}.joined(separator: ";"))))
|
||||||
|
|||||||
@@ -52,7 +52,9 @@ public struct Walker {
|
|||||||
return Result.Ok(())
|
return Result.Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
public func try_map<T>(n: Int, onlyNamed: Bool = false, todo: (Node) -> Result<T>) -> ([T], [Error]) {
|
public func try_map<T>(
|
||||||
|
n: Int, onlyNamed: Bool = false, todo: (Node) -> Result<T>
|
||||||
|
) -> ([T], [Error]) {
|
||||||
var errors: [Error] = Array()
|
var errors: [Error] = Array()
|
||||||
var results: [T] = Array()
|
var results: [T] = Array()
|
||||||
|
|
||||||
|
|||||||
@@ -78,7 +78,8 @@ public struct Action: CustomStringConvertible, P4DataType, P4DataValue {
|
|||||||
public var name: Identifier
|
public var name: Identifier
|
||||||
|
|
||||||
public init(
|
public init(
|
||||||
named name: Identifier = Identifier(name: ""), withParameters parameters: ParameterList = ParameterList([]),
|
named name: Identifier = Identifier(name: ""),
|
||||||
|
withParameters parameters: ParameterList = ParameterList([]),
|
||||||
withBody body: BlockStatement? = .none
|
withBody body: BlockStatement? = .none
|
||||||
) {
|
) {
|
||||||
self.name = name
|
self.name = name
|
||||||
@@ -187,8 +188,9 @@ public struct Table: CustomStringConvertible {
|
|||||||
/// compared to the entries and the match is assocated with an action
|
/// compared to the entries and the match is assocated with an action
|
||||||
/// that is invoked when the match occurs!
|
/// that is invoked when the match occurs!
|
||||||
|
|
||||||
public func update(addEntry entry: (P4Value, TypedIdentifier)) -> Table{
|
public func update(addEntry entry: (P4Value, TypedIdentifier)) -> Table {
|
||||||
return Table(withName: self.name, withPropertyList: self.properties, withEntries: self.entries + [entry])
|
return Table(
|
||||||
|
withName: self.name, withPropertyList: self.properties, withEntries: self.entries + [entry])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -277,7 +279,9 @@ public struct Control: P4DataType, P4DataValue, Equatable, CustomStringConvertib
|
|||||||
public func updateTable(addEntry entry: (P4Value, TypedIdentifier)) -> Control {
|
public func updateTable(addEntry entry: (P4Value, TypedIdentifier)) -> Control {
|
||||||
let table = self.table.update(addEntry: entry)
|
let table = self.table.update(addEntry: entry)
|
||||||
|
|
||||||
return Control(named: self.name, withParameters: self.parameters, withTable: table, withActions: self.actions, withApply: self.apply)
|
return Control(
|
||||||
|
named: self.name, withParameters: self.parameters, withTable: table,
|
||||||
|
withActions: self.actions, withApply: self.apply)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func def() -> any P4DataValue {
|
public func def() -> any P4DataValue {
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ extension Control: LibraryCallable {
|
|||||||
// Skip those with mismatching types.
|
// Skip those with mismatching types.
|
||||||
|
|
||||||
if !val.type().eq(key_val.type()) {
|
if !val.type().eq(key_val.type()) {
|
||||||
continue;
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
/// ASSUME: All matches are exact.
|
/// ASSUME: All matches are exact.
|
||||||
@@ -80,9 +80,13 @@ extension Control: LibraryCallable {
|
|||||||
return (.Ok(P4TableHitMissValue.Miss), control_execution)
|
return (.Ok(P4TableHitMissValue.Miss), control_execution)
|
||||||
}
|
}
|
||||||
|
|
||||||
switch Call(body: call_body, withArguments: arguments, withParameters: self.parameters, inExecution: control_execution) {
|
switch Call(
|
||||||
|
body: call_body, withArguments: arguments, withParameters: self.parameters,
|
||||||
|
inExecution: control_execution)
|
||||||
|
{
|
||||||
case (.Ok(let r), let updated_execution): return (r, updated_execution)
|
case (.Ok(let r), let updated_execution): return (r, updated_execution)
|
||||||
case (.Error(let e), let updated_execution): return (P4TableHitMissValue.Miss, updated_execution.setError(error: e))
|
case (.Error(let e), let updated_execution):
|
||||||
|
return (P4TableHitMissValue.Miss, updated_execution.setError(error: e))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,7 +35,9 @@ public struct Runtime<U, T: LibraryCallable<U>>: CustomStringConvertible {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Create a parser runtime from a P4 program
|
/// Create a parser runtime from a P4 program
|
||||||
public static func create(program: P4Lang.Program) -> Result<Runtime<InstantiatedParserState, Parser>> {
|
public static func create(
|
||||||
|
program: P4Lang.Program
|
||||||
|
) -> Result<Runtime<InstantiatedParserState, Parser>> {
|
||||||
return Runtime.create(program: program, withGlobalValues: .none)
|
return Runtime.create(program: program, withGlobalValues: .none)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,7 +46,9 @@ public struct Runtime<U, T: LibraryCallable<U>>: CustomStringConvertible {
|
|||||||
) -> Result<Runtime<InstantiatedParserState, Parser>> {
|
) -> Result<Runtime<InstantiatedParserState, Parser>> {
|
||||||
return switch program.starting_parser() {
|
return switch program.starting_parser() {
|
||||||
case .Ok(let parser):
|
case .Ok(let parser):
|
||||||
.Ok(P4Runtime.Runtime<InstantiatedParserState, Parser>(callable: parser, withGlobalValues: initial))
|
.Ok(
|
||||||
|
P4Runtime.Runtime<InstantiatedParserState, Parser>(
|
||||||
|
callable: parser, withGlobalValues: initial))
|
||||||
case .Error(let error): .Error(error)
|
case .Error(let error): .Error(error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -52,7 +56,8 @@ public struct Runtime<U, T: LibraryCallable<U>>: CustomStringConvertible {
|
|||||||
public static func create(
|
public static func create(
|
||||||
control: P4Lang.Control, withGlobalValues initial: VarValueScopes?
|
control: P4Lang.Control, withGlobalValues initial: VarValueScopes?
|
||||||
) -> Result<Runtime<P4TableHitMissValue, Control>> {
|
) -> Result<Runtime<P4TableHitMissValue, Control>> {
|
||||||
return .Ok(P4Runtime.Runtime<P4TableHitMissValue, Control>(callable: control, withGlobalValues: initial))
|
return .Ok(
|
||||||
|
P4Runtime.Runtime<P4TableHitMissValue, Control>(callable: control, withGlobalValues: initial))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Run a P4 parser with no arguments
|
/// Run a P4 parser with no arguments
|
||||||
|
|||||||
Reference in New Issue
Block a user