Start Rewrite
Continuous Integration / Grammar Tests (push) Successful in 3m54s
Continuous Integration / Library Format Tests (push) Failing after 4m49s
Continuous Integration / Library Tests (push) Successful in 7m40s

Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
This commit is contained in:
Will Hawkins
2026-06-12 06:24:53 -04:00
parent 6908d9a91d
commit b9ff228362
73 changed files with 1779 additions and 11477 deletions
+1 -55
View File
@@ -58,67 +58,13 @@ public protocol Formattable {
}
public protocol P4Statement {
/// Evaluate a statement for a given execution
/// - Parameters
/// - execution: The execution context in which to evaluate the parser statement
/// - Returns: A tuple of
/// 1. Whether this statement affects control flow.
/// 2. An updated execution after evaluating the parser statement
func evaluate(execution: ProgramExecution) -> (ControlFlow, ProgramExecution)
func effect(context: CompilerContext) -> CompilerContext
}
public protocol P4Expression {
func effect(context: CompilerContext) -> CompilerContext
func type() -> P4QualifiedType
/// Evaluate an expression for a given execution
/// - Parameters
/// - execution: The execution context in which to evaluate the expression
/// - Returns: The value of expression
func evaluate(execution: ProgramExecution) -> (Result<P4Value>, ProgramExecution)
}
extension P4Expression {
func effect(context: CompilerContext) -> CompilerContext {
return context
}
}
public protocol P4LValueExpression {
func effect(context: CompilerContext) -> CompilerContext
func type() -> P4QualifiedType
func check(to: P4Expression, inScopes scopes: StaticVarValueScopes) -> Result<()>
func set(
to: P4Value, inScopes scopes: VarValueScopes, duringExecution execution: ProgramExecution
) -> Result<(VarValueScopes, P4Value)>
}
/// TODO: Only generate these after going through the codegen!
public typealias EvaluatableStatement = P4Statement
public typealias EvaluatableLValueExpression = P4LValueExpression
public typealias EvaluatableExpression = P4Expression
public protocol ProgramExecutionEvaluator {
func ExecuteStatements(
_ statements: [EvaluatableStatement], inExecution execution: ProgramExecution,
_ handler: ExecuteStatementResultHandlerT?
) -> (ControlFlow, ProgramExecution)
func ExecuteStatements(
_ statements: [EvaluatableStatement], inExecution execution: ProgramExecution
) -> (ControlFlow, ProgramExecution)
func EvaluateExpression(
_ expression: EvaluatableExpression, inExecution execution: ProgramExecution,
) -> (Result<P4Value>, ProgramExecution)
}
extension ProgramExecutionEvaluator {
public func ExecuteStatements(
_ statements: [EvaluatableStatement], inExecution execution: ProgramExecution
) -> (ControlFlow, ProgramExecution) {
return ExecuteStatements(statements, inExecution: execution, .none)
}
extension P4Expression {
}