compiler, language, runtime: Separate Parser Type From Instances
In P4, parsers are considered types. Those parsers are instantiated. The instantiated parsers are values. Previously, gp4 treated a parser type and a parser value as identical. This PR makes that difference clear _and_ sets the stage for the future. TODO: Make the same distinction between control and action types and values. Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
This commit is contained in:
@@ -37,18 +37,19 @@ public struct Runtime<U, T: LibraryCallable<U>>: CustomStringConvertible {
|
||||
/// Create a parser runtime from a P4 program
|
||||
public static func create(
|
||||
program: P4Lang.Program
|
||||
) -> Result<Runtime<InstantiatedParserState, Parser>> {
|
||||
) -> Result<Runtime<InstantiatedParserState, ParserValue>> {
|
||||
return Runtime.create(program: program, withGlobalValues: .none)
|
||||
}
|
||||
|
||||
public static func create(
|
||||
program: P4Lang.Program, withGlobalValues initial: VarValueScopes?
|
||||
) -> Result<Runtime<InstantiatedParserState, Parser>> {
|
||||
) -> Result<Runtime<InstantiatedParserState, ParserValue>> {
|
||||
return switch program.starting_parser() {
|
||||
case .Ok(let parser):
|
||||
.Ok(
|
||||
P4Runtime.Runtime<InstantiatedParserState, Parser>(
|
||||
callable: parser, withGlobalValues: initial))
|
||||
P4Runtime.Runtime<InstantiatedParserState, ParserValue>(
|
||||
callable: parser.instantiate(Identifier(name: "starting_parser")),
|
||||
withGlobalValues: initial))
|
||||
case .Error(let error): .Error(error)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user