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:
@@ -41,14 +41,14 @@ import TreeSitterP4
|
||||
}
|
||||
};
|
||||
"""
|
||||
let x = { (tipe: P4QualifiedType) -> Bool in
|
||||
switch tipe.baseType() {
|
||||
let x = { (tipe: P4Type) -> Bool in
|
||||
switch tipe {
|
||||
case let c as Control: c.name == "simple"
|
||||
default: false
|
||||
}
|
||||
}
|
||||
let program = try! #UseOkResult(Program.Compile(simple_parser_declaration))
|
||||
#expect(program.InstancesWithTypes(x).count == 1)
|
||||
#expect(program.TypesWithTypes(x).count == 1)
|
||||
}
|
||||
|
||||
@Test func test_simple_control_declaration2() async throws {
|
||||
@@ -79,14 +79,14 @@ import TreeSitterP4
|
||||
};
|
||||
"""
|
||||
|
||||
let filter = { (tipe: P4QualifiedType) -> Bool in
|
||||
switch tipe.baseType() {
|
||||
let filter = { (tipe: P4Type) -> Bool in
|
||||
switch tipe {
|
||||
case let c as Control: c.name == "simple" || c.name == "complex"
|
||||
default: false
|
||||
}
|
||||
}
|
||||
let program = try! #UseOkResult(Program.Compile(simple_parser_declaration))
|
||||
#expect(program.InstancesWithTypes(filter).count == 2)
|
||||
#expect(program.TypesWithTypes(filter).count == 2)
|
||||
}
|
||||
|
||||
@Test func test_simple_control_declaration_with_actions() async throws {
|
||||
@@ -106,14 +106,14 @@ import TreeSitterP4
|
||||
}
|
||||
};
|
||||
"""
|
||||
let x = { (tipe: P4QualifiedType) -> Bool in
|
||||
switch tipe.baseType() {
|
||||
let x = { (tipe: P4Type) -> Bool in
|
||||
switch tipe {
|
||||
case let c as Control: c.name == "simple"
|
||||
default: false
|
||||
}
|
||||
}
|
||||
let program = try! #UseOkResult(Program.Compile(simple_parser_declaration))
|
||||
#expect(program.InstancesWithTypes(x).count == 1)
|
||||
#expect(program.TypesWithTypes(x).count == 1)
|
||||
}
|
||||
|
||||
@Test func test_simple_control_declaration_with_misnamed_actions() async throws {
|
||||
@@ -341,14 +341,14 @@ import TreeSitterP4
|
||||
};
|
||||
"""
|
||||
|
||||
let x = { (tipe: P4QualifiedType) -> Bool in
|
||||
switch tipe.baseType() {
|
||||
let x = { (tipe: P4Type) -> Bool in
|
||||
switch tipe {
|
||||
case let c as Control: c.name == "simple"
|
||||
default: false
|
||||
}
|
||||
}
|
||||
let program = try! #UseOkResult(Program.Compile(simple_parser_declaration))
|
||||
#expect(program.InstancesWithTypes(x).count == 1)
|
||||
#expect(program.TypesWithTypes(x).count == 1)
|
||||
}
|
||||
|
||||
@Test func test_simple_control_declaration_with_action_with_params_wrong_order() async throws {
|
||||
|
||||
Reference in New Issue
Block a user