compiler: Refactor Compiler To Remove Ambiguities
Continuous Integration / Grammar Tests (push) Successful in 39s
Continuous Integration / Library Format Tests (push) Successful in 1m51s
Continuous Integration / Library Tests (push) Failing after 4m44s

There were significant overlaps in the names of data structures
between the compiler and the language that made it necessary
to litter the code with P4Lang.xxxx. This refactor removes that
requirement in most places (Parser is ambiguous wherever TreeSitter
is used -- cannot avoid that!)

Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
This commit is contained in:
Will Hawkins
2026-05-27 12:59:29 -04:00
parent 61d8f601e8
commit 294f76acd4
39 changed files with 735 additions and 699 deletions
+2 -2
View File
@@ -284,8 +284,8 @@ public struct CodeGenerator: LanguageVisitor {
return .Ok(c)
}
public func visit(
_ parser_state: P4Lang.InstantiatedParserState, _ c: P4Lang.VisitorContext<Generated>
) -> Common.Result<P4Lang.VisitorContext<Generated>> {
_ parser_state: InstantiatedParserState, _ c: VisitorContext<Generated>
) -> Common.Result<VisitorContext<Generated>> {
return .Ok(c)
}
}
+4 -4
View File
@@ -66,7 +66,7 @@ extension ParserStateDirectTransitionValue: EvaluatableParserState {
return false
}
public func state() -> P4Lang.ParserState {
public func state() -> ParserState {
return self.state
}
}
@@ -82,7 +82,7 @@ extension ParserStateNoTransitionValue: EvaluatableParserState {
return true
}
public func state() -> P4Lang.ParserState {
public func state() -> ParserState {
return self.state
}
}
@@ -125,7 +125,7 @@ extension ParserStateSelectTransitionValue: EvaluatableParserState {
return false
}
public func state() -> P4Lang.ParserState {
public func state() -> ParserState {
return self.state
}
}
@@ -134,7 +134,7 @@ extension ParserValue: LibraryCallable {
public typealias T = InstantiatedParserState
public func call(
execution: Common.ProgramExecution, arguments: ArgumentList
) -> (P4Lang.InstantiatedParserState, Common.ProgramExecution) {
) -> (InstantiatedParserState, Common.ProgramExecution) {
var execution = execution.enter_scope()
execution = execution.declare(
+3 -3
View File
@@ -36,13 +36,13 @@ public struct Runtime<U, T: LibraryCallable<U>>: CustomStringConvertible {
/// Create a parser runtime from a P4 program
public static func create(
program: P4Lang.Program
program: Program
) -> Result<Runtime<InstantiatedParserState, ParserValue>> {
return Runtime.create(program: program, withGlobalValues: .none)
}
public static func create(
program: P4Lang.Program, withGlobalValues initial: VarValueScopes?
program: Program, withGlobalValues initial: VarValueScopes?
) -> Result<Runtime<InstantiatedParserState, ParserValue>> {
return switch program.starting_parser() {
case .Ok(let parser):
@@ -55,7 +55,7 @@ public struct Runtime<U, T: LibraryCallable<U>>: CustomStringConvertible {
}
public static func create(
control: P4Lang.Control, withGlobalValues initial: VarValueScopes?
control: Control, withGlobalValues initial: VarValueScopes?
) -> Result<Runtime<P4TableHitMissValue, Control>> {
return .Ok(
P4Runtime.Runtime<P4TableHitMissValue, Control>(callable: control, withGlobalValues: initial))
+6
View File
@@ -133,3 +133,9 @@ extension ApplyStatement: EvaluatableStatement {
return (ControlFlow.Next, execution)
}
}
extension Instantiation: EvaluatableStatement {
public func evaluate(execution: ProgramExecution) -> (ControlFlow, ProgramExecution) {
return (ControlFlow.Next, execution)
}
}