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:
@@ -47,7 +47,7 @@ import TreeSitterP4
|
||||
"""
|
||||
|
||||
let program = try #UseOkResult(Program.Compile(simple_parser_declaration))
|
||||
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
|
||||
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
|
||||
|
||||
var statements_executed: [String] = Array()
|
||||
|
||||
@@ -57,7 +57,9 @@ import TreeSitterP4
|
||||
|
||||
let (state_result, _) = try! #UseOkResult(runtime.run(withArguments: ArgumentList(), inExecution: ProgramExecution(ev)))
|
||||
|
||||
#expect(AsInstantiatedParserState(state_result) == P4Lang.accept)
|
||||
#expect(state_result == P4Lang.accept)
|
||||
|
||||
print("statements_executed: \(statements_executed)")
|
||||
|
||||
#expect(statements_executed[0].hasPrefix("VariableDeclarationStatement"))
|
||||
#expect(statements_executed[1].hasPrefix("ParserAssignmentStatement"))
|
||||
@@ -86,7 +88,7 @@ import TreeSitterP4
|
||||
"""
|
||||
|
||||
let program = try #UseOkResult(Program.Compile(simple_parser_declaration))
|
||||
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
|
||||
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.ParserValue>.create(program: program))
|
||||
|
||||
var expressions_evaluated: [String] = Array()
|
||||
|
||||
@@ -96,7 +98,7 @@ import TreeSitterP4
|
||||
|
||||
let (state_result, _) = try! #UseOkResult(runtime.run(withArguments: ArgumentList(), inExecution: ProgramExecution(ev)))
|
||||
|
||||
#expect(AsInstantiatedParserState(state_result) == P4Lang.accept)
|
||||
#expect(state_result == P4Lang.accept)
|
||||
|
||||
#expect(expressions_evaluated[0].hasPrefix("Value: true of Boolean"))
|
||||
#expect(expressions_evaluated[1].hasPrefix("Value: true of Boolean"))
|
||||
|
||||
Reference in New Issue
Block a user