compiler, runtime: Begin Runtime Refactor
Continuous Integration / Grammar Tests (push) Failing after 39s
Continuous Integration / Library Format Tests (push) Successful in 1m46s
Continuous Integration / Library Tests (push) Successful in 4m38s

Ultimately, the goal is to completely separate the compilation from
the runtime to make it possible to have the interpreter/evaluator
be "just another" entity that can perform meaningful work when
given a parsed GP4 program.

Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
This commit is contained in:
Will Hawkins
2026-05-29 08:41:49 -04:00
parent 18461a9215
commit 44e93e4cda
30 changed files with 1264 additions and 854 deletions
+10 -13
View File
@@ -22,11 +22,11 @@ public struct LocalElements {}
public struct LocalElement {}
public struct ParserAssignmentStatement {
public let lvalue: EvaluatableLValueExpression
public let value: EvaluatableExpression
public let lvalue: P4LValueExpression
public let value: P4Expression
public init(
withLValue lvalue: EvaluatableLValueExpression, withValue value: EvaluatableExpression
withLValue lvalue: P4LValueExpression, withValue value: P4Expression
) {
self.lvalue = lvalue
self.value = value
@@ -34,12 +34,9 @@ public struct ParserAssignmentStatement {
}
/// A P4 Parser State
///
/// Note: A P4 Parser State is both a type and a value.
/// This "bare" parser state represents the state more as a type than a value.
public class ParserState: P4Type, Equatable, CustomStringConvertible {
let name: Identifier
public let statements: [EvaluatableStatement]
public let statements: [P4Statement]
public static func == (lhs: ParserState, rhs: ParserState) -> Bool {
return lhs.eq(rhs: rhs)
@@ -60,12 +57,12 @@ public class ParserState: P4Type, Equatable, CustomStringConvertible {
return self.name
}
public func getStatements() -> [EvaluatableStatement] {
public func getStatements() -> [P4Statement] {
return self.statements
}
/// Construct a ParserState
public init(_ name: Identifier, _ statements: [EvaluatableStatement] = Array()) {
public init(_ name: Identifier, _ statements: [P4Statement] = Array()) {
self.name = name
self.statements = statements
}
@@ -100,7 +97,7 @@ public class ParserStateDirectTransition: ParserState {
/// Construct a ParserState
public init(
name: Identifier, withNextState next_state: InstantiatedParserState,
withStatements stmts: [EvaluatableStatement] = Array(),
withStatements stmts: [P4Statement] = Array(),
) {
self.next_state = next_state
self.next_state_identifier = .none
@@ -109,7 +106,7 @@ public class ParserStateDirectTransition: ParserState {
public init(
name: Identifier, withNextStateIdentifier next_state_id: Identifier,
withStatements stmts: [EvaluatableStatement] = Array(),
withStatements stmts: [P4Statement] = Array(),
) {
self.next_state = .none
self.next_state_identifier = next_state_id
@@ -129,7 +126,7 @@ public class ParserStateDirectTransition: ParserState {
public class ParserStateNoTransition: ParserState {
/// Construct a ParserState
public init(
name: Identifier, withStatements stmts: [EvaluatableStatement] = Array(),
name: Identifier, withStatements stmts: [P4Statement] = Array(),
) {
super.init(name, stmts)
}
@@ -145,7 +142,7 @@ public class ParserStateSelectTransition: ParserState {
public init(
name: Identifier, withTransitionExpression te: SelectExpression,
withStatements stmts: [EvaluatableStatement] = Array()
withStatements stmts: [P4Statement] = Array()
) {
self.te = te
super.init(name, stmts)