compiler, language, runtime: Separate Parser Type From Instances
Continuous Integration / Grammar Tests (push) Successful in 4m2s
Continuous Integration / Library Format Tests (push) Successful in 5m0s
Continuous Integration / Library Tests (push) Successful in 8m1s

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:
Will Hawkins
2026-05-27 05:41:23 -04:00
parent 925f20a13b
commit 61d8f601e8
36 changed files with 1058 additions and 796 deletions
+12 -5
View File
@@ -72,14 +72,16 @@ public struct CodeGenerator: LanguageVisitor {
}
}
/// TODO: Handle instances.
/*
result = Fold(
input: v.instances, initial: result
) { (current, acc) in
return switch acc {
case .Ok(let acc): acc.getVisitorDriver().visit(current.baseType(), context: acc)
case .Ok(let acc): acc.getVisitorDriver().visit(current, context: acc)
case .Error(let e): .Error(e)
}
}
}*/
result = result.map {
.Ok($0.next(uc: $0.getUserContext().append("]")))
@@ -115,7 +117,7 @@ public struct CodeGenerator: LanguageVisitor {
}
public func visit(
_ v: InstantiatedParserState, _ c: VisitorContext<Generated>
_ v: ParserState, _ c: VisitorContext<Generated>
) -> Result<VisitorContext<Generated>> {
let direct_transition_codegen = {
(
@@ -135,14 +137,14 @@ public struct CodeGenerator: LanguageVisitor {
(
state: ParserStateSelectTransition, c: VisitorContext<Generated>
) -> Result<VisitorContext<Generated>> in
return switch self.visit(state.selectExpression, c.next(uc: c.getUserContext().append("["))) {
return switch self.visit(state.te, c.next(uc: c.getUserContext().append("["))) {
case .Ok(let res): .Ok(res.next(uc: res.getUserContext().append("]")))
case .Error(let e): .Error(e)
}
}
var initial = "{"
initial += "name: \"\(v.state)\","
initial += "name: \"\(v.getName())\","
initial += "transitions: "
let result: Result<VisitorContext<Generated>> =
@@ -281,4 +283,9 @@ public struct CodeGenerator: LanguageVisitor {
) -> Result<VisitorContext<Generated>> {
return .Ok(c)
}
public func visit(
_ parser_state: P4Lang.InstantiatedParserState, _ c: P4Lang.VisitorContext<Generated>
) -> Common.Result<P4Lang.VisitorContext<Generated>> {
return .Ok(c)
}
}