From 294f76acd42d11770d49a54b7d98cc74305ad905 Mon Sep 17 00:00:00 2001 From: Will Hawkins Date: Wed, 27 May 2026 12:59:29 -0400 Subject: [PATCH] compiler: Refactor Compiler To Remove Ambiguities 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 --- Snippets/use-program-instanceswithtypes.swift | 2 +- Snippets/use-program-typeswithtypes.swift | 2 +- Sources/Cli/main.swift | 4 +- Sources/P4Compiler/Compiler.swift | 1 - Sources/P4Compiler/Declarations.swift | 40 +- Sources/P4Compiler/Parser.swift | 467 ++++++------------ Sources/P4Compiler/Program.swift | 157 ------ Sources/P4Compiler/SpecialCompilers.swift | 336 +++++++++++++ Sources/P4Compiler/Statement.swift | 6 +- Sources/P4Lang/Parser.swift | 10 +- Sources/P4Lang/Statement.swift | 2 + Sources/P4Runtime/CodeGen.swift | 4 +- Sources/P4Runtime/Parser.swift | 8 +- Sources/P4Runtime/Runtime.swift | 6 +- Sources/P4Runtime/Statements.swift | 6 + Tests/p4rseTests/ArrayTests.swift | 16 +- .../BinaryOperatorTests/AndOr.swift | 20 +- .../p4rseTests/BinaryOperatorTests/Bool.swift | 28 +- .../BinaryOperatorTests/Integer.swift | 52 +- .../BinaryOperatorTests/String.swift | 20 +- .../BinaryOperatorTests/Struct.swift | 10 +- Tests/p4rseTests/CodeGenTests/CodeGen.swift | 4 +- Tests/p4rseTests/ConditionalTests.swift | 4 +- Tests/p4rseTests/ControlTests/Compile.swift | 28 +- Tests/p4rseTests/ControlTests/Runtime.swift | 14 +- Tests/p4rseTests/Declarations.swift | 18 +- Tests/p4rseTests/ExpressionTests.swift | 6 +- .../ExpressionTests/FunctionCall.swift | 12 +- .../ExpressionTests/SelectExpression.swift | 16 +- Tests/p4rseTests/ExternDeclarations.swift | 4 +- Tests/p4rseTests/InterloperTests.swift | 4 +- Tests/p4rseTests/ParserCompilerTests.swift | 27 +- Tests/p4rseTests/RuntimeTests.swift | 14 +- Tests/p4rseTests/ScopeRuntimeTests.swift | 10 +- Tests/p4rseTests/StructTests.swift | 26 +- .../p4rseTests/SupportTests/SourceCode.swift | 8 +- Tests/p4rseTests/TransitionTests.swift | 6 +- Tests/p4rseTests/Unsupported.swift | 4 +- Tests/p4rseTests/ValueTypeParserTests.swift | 32 +- 39 files changed, 735 insertions(+), 699 deletions(-) delete mode 100644 Sources/P4Compiler/Program.swift create mode 100644 Sources/P4Compiler/SpecialCompilers.swift diff --git a/Snippets/use-program-instanceswithtypes.swift b/Snippets/use-program-instanceswithtypes.swift index 802538a..02b6ba6 100644 --- a/Snippets/use-program-instanceswithtypes.swift +++ b/Snippets/use-program-instanceswithtypes.swift @@ -45,6 +45,6 @@ let flter = { (tipe: P4QualifiedType) -> Bool in default: false } } -if case .Ok(let program) = Program.Compile(p4_program_with_control_decl) { +if case .Ok(let program) = SpecialCompilers.ProgramCompiler.Compile(p4_program_with_control_decl) { print(program.InstancesWithTypes(flter)) } diff --git a/Snippets/use-program-typeswithtypes.swift b/Snippets/use-program-typeswithtypes.swift index 45e8192..713c65b 100644 --- a/Snippets/use-program-typeswithtypes.swift +++ b/Snippets/use-program-typeswithtypes.swift @@ -38,7 +38,7 @@ let flter = { (tipe: P4Type) -> Bool in default: false } } -if case .Ok(let program) = Program.Compile(p4_program_with_struct_decl) { +if case .Ok(let program) = SpecialCompilers.ProgramCompiler.Compile(p4_program_with_struct_decl) { print(program.TypesWithTypes(flter)) } diff --git a/Sources/Cli/main.swift b/Sources/Cli/main.swift index ddd100e..d745283 100644 --- a/Sources/Cli/main.swift +++ b/Sources/Cli/main.swift @@ -94,7 +94,7 @@ extension Cli { return } - let maybe_program = Program.Compile(source.getSource()) + let maybe_program = SpecialCompilers.ProgramCompiler.Compile(source.getSource()) guard case .Ok(_) = maybe_program else { let feedback = CompilationFeedback(source, [maybe_program.error()!], formatter) print(feedback.feedback) @@ -134,7 +134,7 @@ extension Cli { return } - let maybe_program = Program.Compile(source.getSource()) + let maybe_program = SpecialCompilers.ProgramCompiler.Compile(source.getSource()) guard case .Ok(let program) = maybe_program else { print(ErrorWithLabel("Compiler Error", maybe_source.error()!).format(formatter)) return diff --git a/Sources/P4Compiler/Compiler.swift b/Sources/P4Compiler/Compiler.swift index a65786a..b51fb66 100644 --- a/Sources/P4Compiler/Compiler.swift +++ b/Sources/P4Compiler/Compiler.swift @@ -16,7 +16,6 @@ // along with this program. If not, see . import Common -import P4Lang import P4Runtime import SwiftTreeSitter import TreeSitterExtensions diff --git a/Sources/P4Compiler/Declarations.swift b/Sources/P4Compiler/Declarations.swift index 693d4c2..8de9739 100644 --- a/Sources/P4Compiler/Declarations.swift +++ b/Sources/P4Compiler/Declarations.swift @@ -140,7 +140,7 @@ extension FunctionDeclaration: CompilableDeclaration { // Do not use the updated context returned by parsing the body // and do not use the function_scope, either. // And, do not update the context if we are compiling in an - // extern context. + // extern context -- the wrapping extern declaration will take care of that. return .Ok( ( function_declaration, @@ -381,7 +381,7 @@ extension P4Lang.Parser: CompilableDeclaration { } /// TODO: Handle extern parsers. - switch Parser.Compile( + switch SpecialCompilers.Compile( withName: parser_name!, withParameters: parameter_list, node: current_node!, withContext: current_context) { @@ -393,9 +393,7 @@ extension P4Lang.Parser: CompilableDeclaration { ( parser_declaration, context.extern_context - ? updated_context.update( - newExterns: updated_context.externs.declare( - identifier: parser.name, withValue: parser_declaration)) + ? context : updated_context.update( newTypes: updated_context.types.declare(identifier: parser.name, withValue: parser)) )) @@ -561,9 +559,7 @@ extension Control: CompilableDeclaration { ( declared_control, context.extern_context - ? context.update( - newTypes: context.externs.declare( - identifier: control_name, withValue: declared_control)) + ? context : context.update( newTypes: context.types.declare( identifier: control_name, withValue: control)) @@ -575,7 +571,7 @@ extension Action: Compilable { public typealias T = Action public static func Compile( node: SwiftTreeSitter.Node, withContext context: CompilerContext - ) -> Common.Result<(P4Lang.Action, CompilerContext)> { + ) -> Common.Result<(Action, CompilerContext)> { #RequireNodeType( node: node, type: "action_declaration", nice_type_name: "Action Declaration") @@ -588,7 +584,7 @@ extension Action: Compilable { #MustOr( result: current_node, thing: walker.getNext(), - or: Result<(P4Lang.Action, CompilerContext)>.Error( + or: Result<(Action, CompilerContext)>.Error( ErrorWithLocation( sourceLocation: node.toSourceLocation(), withError: "Missing action declaration component" )) @@ -605,7 +601,7 @@ extension Action: Compilable { walker.next() #MustOr( result: current_node, thing: walker.getNext(), - or: Result<(P4Lang.Action, CompilerContext)>.Error( + or: Result<(Action, CompilerContext)>.Error( ErrorWithLocation( sourceLocation: node.toSourceLocation(), withError: "Missing action declaration component" )) @@ -633,7 +629,7 @@ extension Action: Compilable { walker.next() #MustOr( result: current_node, thing: walker.getNext(), - or: Result<(P4Lang.Action, CompilerContext)>.Error( + or: Result<(Action, CompilerContext)>.Error( ErrorWithLocation( sourceLocation: node.toSourceLocation(), withError: "Missing action declaration component" )) @@ -668,7 +664,7 @@ extension TableKeyEntry: Compilable { public typealias T = TableKeyEntry public static func Compile( node: SwiftTreeSitter.Node, withContext context: CompilerContext - ) -> Common.Result<(P4Lang.TableKeyEntry, CompilerContext)> { + ) -> Common.Result<(TableKeyEntry, CompilerContext)> { #RequireNodeType( node: node, type: "table_key_entry", nice_type_name: "Table Key Entry") @@ -681,7 +677,7 @@ extension TableKeyEntry: Compilable { #MustOr( result: current_node, thing: walker.getNext(), - or: Result<(P4Lang.TableKeyEntry, CompilerContext)>.Error( + or: Result<(TableKeyEntry, CompilerContext)>.Error( ErrorWithLocation( sourceLocation: node.toSourceLocation(), withError: "Missing table key entry declaration component"))) @@ -697,7 +693,7 @@ extension TableKeyEntry: Compilable { walker.next() #MustOr( result: current_node, thing: walker.getNext(), - or: Result<(P4Lang.TableKeyEntry, CompilerContext)>.Error( + or: Result<(TableKeyEntry, CompilerContext)>.Error( ErrorWithLocation( sourceLocation: node.toSourceLocation(), withError: "Missing table key entry declaration component"))) @@ -716,7 +712,7 @@ extension TableKeyMatchType: Compilable { public typealias T = TableKeyMatchType public static func Compile( node: SwiftTreeSitter.Node, withContext context: CompilerContext - ) -> Common.Result<(P4Lang.TableKeyMatchType, CompilerContext)> { + ) -> Common.Result<(TableKeyMatchType, CompilerContext)> { #RequireNodeType( node: node, type: "table_key_match_type", nice_type_name: "Table Key Match Type") @@ -734,7 +730,7 @@ extension TableKeys: Compilable { public typealias T = TableKeys public static func Compile( node: SwiftTreeSitter.Node, withContext context: CompilerContext - ) -> Common.Result<(P4Lang.TableKeys, CompilerContext)> { + ) -> Common.Result<(TableKeys, CompilerContext)> { #RequireNodeType( node: node, type: "table_keys", nice_type_name: "Table Keys") @@ -750,7 +746,7 @@ extension TableKeys: Compilable { #MustOr( result: current_node, thing: walker.getNext(), - or: Result<(P4Lang.TableKeys, CompilerContext)>.Error( + or: Result<(TableKeys, CompilerContext)>.Error( ErrorWithLocation( sourceLocation: node.toSourceLocation(), withError: "Missing table keys declaration component in control declaration")) @@ -839,7 +835,7 @@ extension TablePropertyList: Compilable { public typealias T = TablePropertyList public static func Compile( node: SwiftTreeSitter.Node, withContext context: CompilerContext - ) -> Common.Result<(P4Lang.TablePropertyList, CompilerContext)> { + ) -> Common.Result<(TablePropertyList, CompilerContext)> { #RequireNodeType( node: node, type: "table_property_list", nice_type_name: "Table Property List") @@ -913,7 +909,7 @@ extension Table: Compilable { public typealias T = Table public static func Compile( node: SwiftTreeSitter.Node, withContext context: CompilerContext - ) -> Common.Result<(P4Lang.Table, CompilerContext)> { + ) -> Common.Result<(Table, CompilerContext)> { let table_declaration_node = node #RequireNodeType( @@ -928,7 +924,7 @@ extension Table: Compilable { walker.next() // Skip the XXX? #MustOr( result: current_node, thing: walker.getNext(), - or: Result<(P4Lang.Table, CompilerContext)>.Error( + or: Result<(Table, CompilerContext)>.Error( ErrorWithLocation( sourceLocation: node.toSourceLocation(), withError: "Missing table declaration component") )) @@ -946,7 +942,7 @@ extension Table: Compilable { walker.next() #MustOr( result: current_node, thing: walker.getNext(), - or: Result<(P4Lang.Table, CompilerContext)>.Error( + or: Result<(Table, CompilerContext)>.Error( ErrorWithLocation( sourceLocation: node.toSourceLocation(), withError: "Missing table declaration component") )) diff --git a/Sources/P4Compiler/Parser.swift b/Sources/P4Compiler/Parser.swift index 6d59b75..f8e9c64 100644 --- a/Sources/P4Compiler/Parser.swift +++ b/Sources/P4Compiler/Parser.swift @@ -22,322 +22,165 @@ import SwiftTreeSitter import TreeSitterExtensions import TreeSitterP4 -public struct Parser { - public struct LocalElements { - static func Compile( - node: Node, withContext context: CompilerContext - ) -> Result<(EvaluatableStatement, CompilerContext)> { - let localElementsParsers: [String: CompilableStatement.Type] = [ - "variableDeclaration": VariableDeclarationStatement.self - ] +extension Statement: Compilable { + public typealias T = EvaluatableStatement + public static func Compile( + node: SwiftTreeSitter.Node, withContext context: CompilerContext + ) -> Common.Result<(EvaluatableStatement, CompilerContext)> { - guard let parser = localElementsParsers[node.nodeType ?? ""] else { - return Result.Error( - ErrorWithLocation( - sourceLocation: node.toSourceLocation(), - withError: "Unparseable statement type (\(node.nodeType ?? "Unknown Statement Type"))")) - } - - switch parser.Compile(node: node, withContext: context) { - case Result.Ok(let (parsed, parsed_updated_scopes)): - return Result.Ok((parsed, parsed_updated_scopes)) - case Result.Error(let e): - return Result.Error(Error(withMessage: "Failed to parse local element: \(e)")) - } - } - } - - public struct Statement { - static func Compile( - node: Node, withContext context: CompilerContext - ) -> Result<(EvaluatableStatement, CompilerContext)> { - if node.nodeType != "parserStatement" && node.nodeType != "statement" { - return Result.Error( - ErrorWithLocation( - sourceLocation: node.toSourceLocation(), withError: "Missing expected parser statement") - ) - } - - let statement = node.child(at: 0)! - - let statementParsers: [String: CompilableStatement.Type] = [ - "assignmentStatement": ParserAssignmentStatement.self, - "expressionStatement": ExpressionStatement.self, - "variableDeclaration": VariableDeclarationStatement.self, - "conditionalStatement": ConditionalStatement.self, "blockStatement": BlockStatement.self, - "return_statement": ReturnStatement.self, - ] - guard let parser = statementParsers[statement.nodeType ?? ""] else { - return Result.Error( - ErrorWithLocation( - sourceLocation: statement.toSourceLocation(), - withError: - "Unparseable statement type (\(statement.nodeType ?? "Unknown Statement Type"))")) - } - switch parser.Compile(node: statement, withContext: context) { - case Result.Ok(let (parsed, updated_context)): - return .Ok((parsed, updated_context)) - case Result.Error(let e): - return .Error( - ErrorWithLocation( - sourceLocation: node.toSourceLocation(), - withError: "Failed to parse a statement element: \(e)")) - } - } - } - - public struct TransitionStatement { - static func Compile( - node: Node, forState state_identifier: Common.Identifier, - withStatements stmts: [EvaluatableStatement], withContext context: CompilerContext - ) -> Result<(ParserState, CompilerContext)> { - - #RequireNodeType( - node: node, type: "parserTransitionStatement", nice_type_name: "parser transition statement" + if node.nodeType != "parserStatement" && node.nodeType != "statement" { + return Result.Error( + ErrorWithLocation( + sourceLocation: node.toSourceLocation(), withError: "Missing expected parser statement") ) - - guard let tse_node = node.child(at: 1), - tse_node.nodeType! == "transitionSelectionExpression" - else { - return .Error( - ErrorWithLocation( - sourceLocation: node.toSourceLocation(), - withError: "Could not find transition select expression")) - } - - guard let next_node = tse_node.child(at: 0) else { - return .Error( - ErrorWithLocation( - sourceLocation: node.toSourceLocation(), - withError: "Could not find the next token in a transition selection expression")) - } - - // If the next node is an identifier, we have the simple form ... - if next_node.nodeType == "identifier" { - let maybe_parsed_next_state_id = Identifier.Compile( - node: next_node, withContext: context) - if case .Ok(let next_state_id) = maybe_parsed_next_state_id { - if case .Ok(let next_state) = context.instances.lookup(identifier: next_state_id) { - switch next_state { - case (_, .some(let instance)): - return .Ok( - ( - ParserStateDirectTransition( - name: state_identifier, - withNextState: instance.dataValue() as! InstantiatedParserState, - withStatements: stmts), context - )) - case (_, .none): - return .Ok( - ( - ParserStateDirectTransition( - name: state_identifier, - withNextStateIdentifier: next_state_id, withStatements: stmts), context - )) - } - } else { - - return .Error( - Error( - withMessage: - "\(next_state_id) does not name a parser state in scope" - )) - } - } else { - return .Error( - Error( - withMessage: - "Could not parse the next state in a transition statement: \(maybe_parsed_next_state_id.error()!)" - )) - } - } - - // We know that the next node is a select expression. - return - switch SelectExpression.compile(node: next_node, withContext: context) - { - case .Ok(let tse): - .Ok( - ( - ParserStateSelectTransition( - name: state_identifier, withTransitionExpression: tse as! SelectExpression, - withStatements: stmts, - ), context - )) - case .Error(let e): .Error(e) - } - } - } - - public struct Statements { - static func Compile( - node: Node, withContext context: CompilerContext - ) -> Result<([EvaluatableStatement], CompilerContext)> { - if node.nodeType != "statements" && node.nodeType != "parserStatements" { - return Result.Error( - ErrorWithLocation( - sourceLocation: node.toSourceLocation(), withError: "Did not find expected statements")) - } - - var errors: (any Errorable)? = .none - var current_context = context - var parsed_s: [EvaluatableStatement] = Array() - - node.enumerateNamedChildren { node in - switch Statement.Compile( - node: node, withContext: current_context) - { - case .Ok((let parsed_statement, let updated_context)): - current_context = updated_context - parsed_s.append(parsed_statement) - case .Error(let e): - errors = - if let errors = errors { - errors.append(error: e) - } else { - e - } - } - } - - if let errors = errors { - return .Error(errors) - } - - return Result.Ok((parsed_s, current_context)) - } - } - - public struct State { - static func Compile( - node: Node, withContext context: CompilerContext - ) -> Result<(ParserState, CompilerContext)> { - var walker = Walker(node: node) - - var current_node: Node? = .none - - guard let node_type = node.nodeType, - node_type == "parserState" - else { - return Result.Error( - ErrorWithLocation( - sourceLocation: node.toSourceLocation(), - withError: "Did not find a parser state declaration")) - } - - #MustOr( - result: current_node, thing: walker.getNext(), - or: Result<(ParserState, CompilerContext)>.Error( - ErrorWithLocation( - sourceLocation: node.toSourceLocation(), - withError: "Missing elements in parser state declaration"))) - - if current_node!.nodeType == "annotations" { - return Result.Error( - ErrorWithLocation( - sourceLocation: current_node!.toSourceLocation(), - withError: "Annotations in parser state are not yet handled.")) - - // Would increment here. - } - - // Skip the keyword state - walker.next() - #MustOr( - result: current_node, thing: walker.getNext(), - or: Result<(ParserState, CompilerContext)>.Error( - ErrorWithLocation( - sourceLocation: node.toSourceLocation(), - withError: "Missing elements in parser state declaration"))) - - let maybe_state_identifier = Identifier.Compile( - node: current_node!, withContext: context) - guard case Result.Ok(let state_identifier) = maybe_state_identifier else { - return Result.Error(maybe_state_identifier.error()!) - } - - walker.next() - // Skip the '{' - walker.next() - #MustOr( - result: current_node, thing: walker.getNext(), - or: Result<(ParserState, CompilerContext)>.Error( - ErrorWithLocation( - sourceLocation: node.toSourceLocation(), withError: "Missing body of state declaration") - )) - - var errors: (any Errorable)? = .none - var current_context = context - var parsed_s: [EvaluatableStatement] = Array() - - if current_node!.nodeType == "parserStatements" { - switch Statements.Compile( - node: current_node!, withContext: current_context) - { - case .Ok(let (state_statements, updated_context)): - parsed_s = state_statements - current_context = updated_context - case .Error(let error): - errors = - if let errors = errors { - errors.append(error: error) - } else { - error - } - } - walker.next() - } - - if let errors = errors { - return .Error(errors) - } - - #MustOr( - result: current_node, thing: walker.getNext(), - or: Result<(ParserState, CompilerContext)>.Error( - ErrorWithLocation( - sourceLocation: node.toSourceLocation(), - withError: "Missing transition statement of state declaration"))) - - return TransitionStatement.Compile( - node: current_node!, forState: state_identifier, withStatements: parsed_s, - withContext: current_context) - } - } - - static func Compile( - withName name: Common.Identifier, withParameters parameters: ParameterList, node: Node, - withContext context: CompilerContext - ) -> Result<(P4Lang.Parser, CompilerContext)> { - - var parser = P4Lang.Parser(withName: name, withParameters: parameters) - - // Build a state from each one listed. - var error: (any Errorable)? = .none - - var current_context = context - /// TODO: Assert that there is only one. - node.enumerateNamedChildren { parser_state in - if parser_state.nodeType != "parserState" { - return - } - - // Parse a state in a nested scope. - switch Parser.State.Compile( - node: parser_state, - withContext: context.update(newInstances: current_context.instances.enter())) - { - case Result.Ok(let (state, updated_context)): - parser.states = parser.states.append(state: state) - current_context = updated_context - case Result.Error(let e): error = e - } } - if let error = error { - return .Error(error) - } + let statement = node.child(at: 0)! - return Result.Ok((parser, current_context)) + let statementParsers: [String: CompilableStatement.Type] = [ + "assignmentStatement": ParserAssignmentStatement.self, + "expressionStatement": ExpressionStatement.self, + "variableDeclaration": VariableDeclarationStatement.self, + "conditionalStatement": ConditionalStatement.self, "blockStatement": BlockStatement.self, + "return_statement": ReturnStatement.self, + ] + guard let parser = statementParsers[statement.nodeType ?? ""] else { + return Result.Error( + ErrorWithLocation( + sourceLocation: statement.toSourceLocation(), + withError: + "Unparseable statement type (\(statement.nodeType ?? "Unknown Statement Type"))")) + } + switch parser.Compile(node: statement, withContext: context) { + case Result.Ok(let (parsed, updated_context)): + return .Ok((parsed, updated_context)) + case Result.Error(let e): + return .Error( + ErrorWithLocation( + sourceLocation: node.toSourceLocation(), + withError: "Failed to parse a statement element: \(e)")) + } + } +} +extension LocalElements: Compilable { + public typealias T = EvaluatableStatement + public static func Compile( + node: Node, withContext context: CompilerContext + ) -> Result<(EvaluatableStatement, CompilerContext)> { + let localElementsParsers: [String: CompilableStatement.Type] = [ + "variableDeclaration": VariableDeclarationStatement.self + ] + + guard let parser = localElementsParsers[node.nodeType ?? ""] else { + return Result.Error( + ErrorWithLocation( + sourceLocation: node.toSourceLocation(), + withError: "Unparseable statement type (\(node.nodeType ?? "Unknown Statement Type"))")) + } + + switch parser.Compile(node: node, withContext: context) { + case Result.Ok(let (parsed, parsed_updated_scopes)): + return Result.Ok((parsed, parsed_updated_scopes)) + case Result.Error(let e): + return Result.Error(Error(withMessage: "Failed to parse local element: \(e)")) + } + } +} + +extension ParserState: Compilable { + public typealias T = ParserState + public static func Compile( + node: Node, withContext context: CompilerContext + ) -> Result<(ParserState, CompilerContext)> { + var walker = Walker(node: node) + + var current_node: Node? = .none + + guard let node_type = node.nodeType, + node_type == "parserState" + else { + return Result.Error( + ErrorWithLocation( + sourceLocation: node.toSourceLocation(), + withError: "Did not find a parser state declaration")) + } + + #MustOr( + result: current_node, thing: walker.getNext(), + or: Result<(ParserState, CompilerContext)>.Error( + ErrorWithLocation( + sourceLocation: node.toSourceLocation(), + withError: "Missing elements in parser state declaration"))) + + if current_node!.nodeType == "annotations" { + return Result.Error( + ErrorWithLocation( + sourceLocation: current_node!.toSourceLocation(), + withError: "Annotations in parser state are not yet handled.")) + + // Would increment here. + } + + // Skip the keyword state + walker.next() + #MustOr( + result: current_node, thing: walker.getNext(), + or: Result<(ParserState, CompilerContext)>.Error( + ErrorWithLocation( + sourceLocation: node.toSourceLocation(), + withError: "Missing elements in parser state declaration"))) + + let maybe_state_identifier = Identifier.Compile( + node: current_node!, withContext: context) + guard case Result.Ok(let state_identifier) = maybe_state_identifier else { + return Result.Error(maybe_state_identifier.error()!) + } + + walker.next() + // Skip the '{' + walker.next() + #MustOr( + result: current_node, thing: walker.getNext(), + or: Result<(ParserState, CompilerContext)>.Error( + ErrorWithLocation( + sourceLocation: node.toSourceLocation(), withError: "Missing body of state declaration") + )) + + var errors: (any Errorable)? = .none + var current_context = context + var parsed_s: [EvaluatableStatement] = Array() + + if current_node!.nodeType == "parserStatements" { + switch SpecialCompilers.Statements.Compile( + node: current_node!, withContext: current_context) + { + case .Ok(let (state_statements, updated_context)): + parsed_s = state_statements + current_context = updated_context + case .Error(let error): + errors = + if let errors = errors { + errors.append(error: error) + } else { + error + } + } + walker.next() + } + + if let errors = errors { + return .Error(errors) + } + + #MustOr( + result: current_node, thing: walker.getNext(), + or: Result<(ParserState, CompilerContext)>.Error( + ErrorWithLocation( + sourceLocation: node.toSourceLocation(), + withError: "Missing transition statement of state declaration"))) + + return SpecialCompilers.TransitionStatement.Compile( + node: current_node!, forState: state_identifier, withStatements: parsed_s, + withContext: current_context) } } diff --git a/Sources/P4Compiler/Program.swift b/Sources/P4Compiler/Program.swift deleted file mode 100644 index 3584906..0000000 --- a/Sources/P4Compiler/Program.swift +++ /dev/null @@ -1,157 +0,0 @@ -// p4rse, Copyright 2026, Will Hawkins -// -// This file is part of p4rse. -// -// This file is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -import Common -import P4Lang -import P4Runtime -import SwiftTreeSitter -import TreeSitterExtensions -import TreeSitterP4 - -public struct Program { - public static func Compile(_ source: String) -> Result { - - // Certain names are always in scope during compilation. - var globals = StaticVarValueScopes().enter() - globals = globals.declare( - identifier: accept.state().getName(), - withValue: (P4QualifiedType(accept.type()), P4Value(accept)) - ) - .declare( - identifier: reject.state.getName(), - withValue: (P4QualifiedType(reject.type()), P4Value(reject))) - - return Program.Compile( - source, withGlobalInstances: globals, withGlobalTypes: .none, withFFIs: []) - } - - public static func Compile( - _ source: String, withGlobalInstances globalInstances: StaticVarValueScopes - ) -> Result { - return Program.Compile( - source, withGlobalInstances: globalInstances, withGlobalTypes: .none, withFFIs: []) - } - - public static func Compile( - _ source: String, withGlobalInstances globalInstances: StaticVarValueScopes?, - withGlobalTypes globalTypes: TypeTypeScopes?, withFFIs ffis: [P4FFI] = Array() - ) -> Result { - - let maybe_parser = ConfigureP4Parser() - guard case .Ok(let p) = maybe_parser else { - return .Error(maybe_parser.error()!) - } - - let result = p.parse(source) - guard let tree = result, - !tree.isError(lang: p4lang), - !tree.containsMissing(lang: p4lang) - else { - return Result.Error(Error(withMessage: "Could not compile the P4 program")) - } - - var program = P4Lang.Program() - - // Set up a context for parsing. - var compilation_context = CompilerContext() - - // Add our FFIs - compilation_context = compilation_context.update(newFFIs: ffis) - - var errors: (any Errorable)? = .none - - // If the caller gave any global instances, add them here. - if let globalInstances = globalInstances { - compilation_context = compilation_context.update(newInstances: globalInstances) - } - - // If the caller gave any global types, add them here. - if let globalTypes = globalTypes { - compilation_context = compilation_context.update(newTypes: globalTypes) - } - - // Try to parse all top-level declarations. - result?.rootNode?.enumerateNamedChildren { (declaration_node: Node) in - let specific_declaration_node = declaration_node.child(at: 0)! - - let declaration_parsers: [CompilableDeclaration.Type] = [ - Declaration.self, P4Lang.Parser.self, - ] - var found_parser = false - - for parser in declaration_parsers { - switch parser.Compile(node: specific_declaration_node, withContext: compilation_context) { - case .Ok(.none): {}() - case .Ok(.some((_, let updated_context))): - found_parser = true - compilation_context = updated_context - break - case .Error(let e): - found_parser = true - errors = - if let errors = errors { - errors.append(error: e) - } else { - e - } - break - } - } - - // If none of the declaration parsers chose to parse, that's an error, too! - if !found_parser { - - let no_parser_error = ErrorWithLocation( - sourceLocation: specific_declaration_node.toSourceLocation(), - withError: "Could not find parser for declaration node" - ) - errors = - if let errors = errors { - errors.append(error: no_parser_error) - } else { - no_parser_error - } - } - } - - if let errors = errors { - return .Error(errors) - } - - // Any of the instances that are in the top-level scope should go into the program! - program.instances = Array( - compilation_context.instances.filter { (_, v) in - v.1 != nil - }.map { (_, v) in - v.1! - }) - - // Any of the types that are in the top-level scope should go into the program! - program.types = Array( - compilation_context.types.map { (_, v) in - v - }) - - // Any of the extern types that are in the top-level scope should go into the program! - program.externs = Array( - compilation_context.externs.map { (_, v) in - v - }) - - return Result.Ok(program) - } -} diff --git a/Sources/P4Compiler/SpecialCompilers.swift b/Sources/P4Compiler/SpecialCompilers.swift new file mode 100644 index 0000000..682512d --- /dev/null +++ b/Sources/P4Compiler/SpecialCompilers.swift @@ -0,0 +1,336 @@ +// p4rse, Copyright 2026, Will Hawkins +// +// This file is part of p4rse. +// +// This file is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +import Common +import P4Lang +import P4Runtime +import SwiftTreeSitter +import TreeSitterExtensions +import TreeSitterP4 + +public struct SpecialCompilers { + public struct TransitionStatement { + static func Compile( + node: Node, forState state_identifier: Common.Identifier, + withStatements stmts: [EvaluatableStatement], withContext context: CompilerContext + ) -> Result<(ParserState, CompilerContext)> { + + #RequireNodeType( + node: node, type: "parserTransitionStatement", nice_type_name: "parser transition statement" + ) + + guard let tse_node = node.child(at: 1), + tse_node.nodeType! == "transitionSelectionExpression" + else { + return .Error( + ErrorWithLocation( + sourceLocation: node.toSourceLocation(), + withError: "Could not find transition select expression")) + } + + guard let next_node = tse_node.child(at: 0) else { + return .Error( + ErrorWithLocation( + sourceLocation: node.toSourceLocation(), + withError: "Could not find the next token in a transition selection expression")) + } + + // If the next node is an identifier, we have the simple form ... + if next_node.nodeType == "identifier" { + let maybe_parsed_next_state_id = Identifier.Compile( + node: next_node, withContext: context) + if case .Ok(let next_state_id) = maybe_parsed_next_state_id { + if case .Ok(let next_state) = context.instances.lookup(identifier: next_state_id) { + switch next_state { + case (_, .some(let instance)): + return .Ok( + ( + ParserStateDirectTransition( + name: state_identifier, + withNextState: instance.dataValue() as! InstantiatedParserState, + withStatements: stmts), context + )) + case (_, .none): + return .Ok( + ( + ParserStateDirectTransition( + name: state_identifier, + withNextStateIdentifier: next_state_id, withStatements: stmts), context + )) + } + } else { + + return .Error( + Error( + withMessage: + "\(next_state_id) does not name a parser state in scope" + )) + } + } else { + return .Error( + Error( + withMessage: + "Could not parse the next state in a transition statement: \(maybe_parsed_next_state_id.error()!)" + )) + } + } + + // We know that the next node is a select expression. + return + switch SelectExpression.compile(node: next_node, withContext: context) + { + case .Ok(let tse): + .Ok( + ( + ParserStateSelectTransition( + name: state_identifier, withTransitionExpression: tse as! SelectExpression, + withStatements: stmts, + ), context + )) + case .Error(let e): .Error(e) + } + } + } + + public struct Statements { + static func Compile( + node: Node, withContext context: CompilerContext + ) -> Result<([EvaluatableStatement], CompilerContext)> { + if node.nodeType != "statements" && node.nodeType != "parserStatements" { + return Result.Error( + ErrorWithLocation( + sourceLocation: node.toSourceLocation(), withError: "Did not find expected statements")) + } + + var errors: (any Errorable)? = .none + var current_context = context + var parsed_s: [EvaluatableStatement] = Array() + + node.enumerateNamedChildren { node in + switch Statement.Compile( + node: node, withContext: current_context) + { + case .Ok((let parsed_statement, let updated_context)): + current_context = updated_context + parsed_s.append(parsed_statement) + case .Error(let e): + errors = + if let errors = errors { + errors.append(error: e) + } else { + e + } + } + } + + if let errors = errors { + return .Error(errors) + } + + return Result.Ok((parsed_s, current_context)) + } + } + + static func Compile( + withName name: Common.Identifier, withParameters parameters: ParameterList, node: Node, + withContext context: CompilerContext + ) -> Result<(P4Lang.Parser, CompilerContext)> { + + var parser = P4Lang.Parser(withName: name, withParameters: parameters) + + // Build a state from each one listed. + var error: (any Errorable)? = .none + + var current_context = context + /// TODO: Assert that there is only one. + node.enumerateNamedChildren { parser_state in + if parser_state.nodeType != "parserState" { + return + } + + // Parse a state in a nested scope. + switch ParserState.Compile( + node: parser_state, + withContext: context.update(newInstances: current_context.instances.enter())) + { + case Result.Ok(let (state, updated_context)): + parser.states = parser.states.append(state: state) + current_context = updated_context + case Result.Error(let e): error = e + } + } + + if let error = error { + return .Error(error) + } + + return Result.Ok((parser, current_context)) + } + + public struct ProgramCompiler { + public static func Compile(_ source: String) -> Result { + + // Certain names are always in scope during compilation. + var globals = StaticVarValueScopes().enter() + globals = globals.declare( + identifier: accept.state().getName(), + withValue: (P4QualifiedType(accept.type()), P4Value(accept)) + ) + .declare( + identifier: reject.state.getName(), + withValue: (P4QualifiedType(reject.type()), P4Value(reject))) + + return ProgramCompiler.Compile( + source, withGlobalInstances: globals, withGlobalTypes: .none, withFFIs: []) + } + + public static func Compile( + _ source: String, withGlobalInstances globalInstances: StaticVarValueScopes + ) -> Result { + return ProgramCompiler.Compile( + source, withGlobalInstances: globalInstances, withGlobalTypes: .none, withFFIs: []) + } + + public static func Compile( + _ source: String, withGlobalInstances globalInstances: StaticVarValueScopes?, + withGlobalTypes globalTypes: TypeTypeScopes?, withFFIs ffis: [P4FFI] = Array() + ) -> Result { + + let maybe_parser = ConfigureP4Parser() + guard case .Ok(let p) = maybe_parser else { + return .Error(maybe_parser.error()!) + } + + let result = p.parse(source) + guard let tree = result, + !tree.isError(lang: p4lang), + !tree.containsMissing(lang: p4lang) + else { + return Result.Error(Error(withMessage: "Could not compile the P4 program")) + } + + var program = P4Lang.Program() + + // Set up a context for parsing. + var compilation_context = CompilerContext() + + // Add our FFIs + compilation_context = compilation_context.update(newFFIs: ffis) + + var errors: (any Errorable)? = .none + + // If the caller gave any global instances, add them here. + if let globalInstances = globalInstances { + compilation_context = compilation_context.update(newInstances: globalInstances) + } + + // If the caller gave any global types, add them here. + if let globalTypes = globalTypes { + compilation_context = compilation_context.update(newTypes: globalTypes) + } + + // Try to parse all top-level declarations. + result?.rootNode?.enumerateNamedChildren { (declaration_node: Node) in + let specific_declaration_node = declaration_node.child(at: 0)! + + let declaration_parsers: [CompilableDeclaration.Type] = [ + Declaration.self, P4Lang.Parser.self, + ] + var found_parser = false + + for parser in declaration_parsers { + switch parser.Compile(node: specific_declaration_node, withContext: compilation_context) { + case .Ok(.none): {}() + case .Ok(.some((_, let updated_context))): + found_parser = true + compilation_context = updated_context + break + case .Error(let e): + found_parser = true + errors = + if let errors = errors { + errors.append(error: e) + } else { + e + } + break + } + } + + // If none of the declaration parsers chose to parse, that's an error, too! + if !found_parser { + + print("spec: \(declaration_node)") + // Try to see if it is an instantiation! + if declaration_node.nodeType == "instantiation" { + switch Instantiation.Compile( + node: declaration_node, withContext: compilation_context) + { + case .Ok((let x, let updated_context)): + print("instantiation: \(x)") + compilation_context = updated_context + case .Error(let e): + errors = + if let errors = errors { + errors.append(error: e) + } else { + e + } + } + } else { + let no_parser_error = ErrorWithLocation( + sourceLocation: specific_declaration_node.toSourceLocation(), + withError: "Could not find parser for declaration node" + ) + errors = + if let errors = errors { + errors.append(error: no_parser_error) + } else { + no_parser_error + } + } + } + } + + if let errors = errors { + return .Error(errors) + } + + // Any of the instances that are in the top-level scope should go into the program! + program.instances = Array( + compilation_context.instances.filter { (_, v) in + v.1 != nil + }.map { (_, v) in + v.1! + }) + + // Any of the types that are in the top-level scope should go into the program! + program.types = Array( + compilation_context.types.map { (_, v) in + v + }) + + // Any of the extern types that are in the top-level scope should go into the program! + program.externs = Array( + compilation_context.externs.map { (_, v) in + v + }) + + return Result.Ok(program) + } + } +} diff --git a/Sources/P4Compiler/Statement.swift b/Sources/P4Compiler/Statement.swift index e7da607..7ea25f6 100644 --- a/Sources/P4Compiler/Statement.swift +++ b/Sources/P4Compiler/Statement.swift @@ -57,7 +57,7 @@ extension BlockStatement: CompilableStatement { sourceLocation: node.toSourceLocation(), withError: "Malformed block statement"))) if current_node!.nodeType == "statements" { - switch Parser.Statements.Compile( + switch SpecialCompilers.Statements.Compile( node: current_node!, withContext: current_context) { case .Ok(let (parsed_statements, updated_context)): @@ -128,7 +128,7 @@ extension ConditionalStatement: CompilableStatement { } guard - case .Ok((let thenns, _)) = Parser.Statement.Compile( + case .Ok((let thenns, _)) = Statement.Compile( node: thens, withContext: context) else { return Result.Error( @@ -140,7 +140,7 @@ extension ConditionalStatement: CompilableStatement { let optional_elss: Result<(any EvaluatableStatement, CompilerContext)>? = if let elss = node.child(at: 6) { .some( - Parser.Statement.Compile( + Statement.Compile( node: elss, withContext: context)) } else { .none diff --git a/Sources/P4Lang/Parser.swift b/Sources/P4Lang/Parser.swift index 7daef25..bace87a 100644 --- a/Sources/P4Lang/Parser.swift +++ b/Sources/P4Lang/Parser.swift @@ -17,13 +17,9 @@ import Common -public struct LocalElements { +public struct LocalElements {} -} - -public struct LocalElement { - -} +public struct LocalElement {} public struct ParserAssignmentStatement { public let lvalue: EvaluatableLValueExpression @@ -94,6 +90,8 @@ public class _AnyParserState: ParserState { nonisolated(unsafe) public let AnyParserState = _AnyParserState(Identifier(name: "AnyParserState")) +public struct TransitionStatement {} + public class ParserStateDirectTransition: ParserState { public let next_state: InstantiatedParserState? diff --git a/Sources/P4Lang/Statement.swift b/Sources/P4Lang/Statement.swift index 059bb2f..f8751e3 100644 --- a/Sources/P4Lang/Statement.swift +++ b/Sources/P4Lang/Statement.swift @@ -17,6 +17,8 @@ import Common +public struct Statement {} + public struct VariableDeclarationStatement { public var initializer: EvaluatableExpression public var identifier: Identifier diff --git a/Sources/P4Runtime/CodeGen.swift b/Sources/P4Runtime/CodeGen.swift index 6cf17b7..40d68b9 100644 --- a/Sources/P4Runtime/CodeGen.swift +++ b/Sources/P4Runtime/CodeGen.swift @@ -284,8 +284,8 @@ public struct CodeGenerator: LanguageVisitor { return .Ok(c) } public func visit( - _ parser_state: P4Lang.InstantiatedParserState, _ c: P4Lang.VisitorContext - ) -> Common.Result> { + _ parser_state: InstantiatedParserState, _ c: VisitorContext + ) -> Common.Result> { return .Ok(c) } } diff --git a/Sources/P4Runtime/Parser.swift b/Sources/P4Runtime/Parser.swift index 3263908..7c41a40 100644 --- a/Sources/P4Runtime/Parser.swift +++ b/Sources/P4Runtime/Parser.swift @@ -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( diff --git a/Sources/P4Runtime/Runtime.swift b/Sources/P4Runtime/Runtime.swift index 3d9129f..8ffc932 100644 --- a/Sources/P4Runtime/Runtime.swift +++ b/Sources/P4Runtime/Runtime.swift @@ -36,13 +36,13 @@ public struct Runtime>: CustomStringConvertible { /// Create a parser runtime from a P4 program public static func create( - program: P4Lang.Program + program: Program ) -> Result> { return Runtime.create(program: program, withGlobalValues: .none) } public static func create( - program: P4Lang.Program, withGlobalValues initial: VarValueScopes? + program: Program, withGlobalValues initial: VarValueScopes? ) -> Result> { return switch program.starting_parser() { case .Ok(let parser): @@ -55,7 +55,7 @@ public struct Runtime>: CustomStringConvertible { } public static func create( - control: P4Lang.Control, withGlobalValues initial: VarValueScopes? + control: Control, withGlobalValues initial: VarValueScopes? ) -> Result> { return .Ok( P4Runtime.Runtime(callable: control, withGlobalValues: initial)) diff --git a/Sources/P4Runtime/Statements.swift b/Sources/P4Runtime/Statements.swift index 6063c33..268c284 100644 --- a/Sources/P4Runtime/Statements.swift +++ b/Sources/P4Runtime/Statements.swift @@ -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) + } +} diff --git a/Tests/p4rseTests/ArrayTests.swift b/Tests/p4rseTests/ArrayTests.swift index 42f4c7f..b203091 100644 --- a/Tests/p4rseTests/ArrayTests.swift +++ b/Tests/p4rseTests/ArrayTests.swift @@ -56,7 +56,7 @@ import TreeSitterP4 P4Value(P4IntValue(withValue: 3)), ]))) let program = try #UseOkResult( - Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations)) + SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration, withGlobalInstances: test_declarations)) let runtime = try #UseOkResult( P4Runtime.Runtime.create( program: program, withGlobalValues: test_values)) @@ -87,7 +87,7 @@ import TreeSitterP4 withMessage: "{49, 22}: Failed to parse a statement element: {65, 2}: ta does not name an array type" ), - Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations)) + SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration, withGlobalInstances: test_declarations)) ) } @@ -119,7 +119,7 @@ import TreeSitterP4 P4Value(P4IntValue(withValue: 3)), ]))) let program = try #UseOkResult( - Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations)) + SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration, withGlobalInstances: test_declarations)) let runtime = try #UseOkResult( P4Runtime.Runtime.create( program: program, withGlobalValues: test_values)) @@ -155,7 +155,7 @@ import TreeSitterP4 P4Value(P4IntValue(withValue: 3)), ]))) let program = try #UseOkResult( - Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations)) + SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration, withGlobalInstances: test_declarations)) let runtime = try #UseOkResult( P4Runtime.Runtime.create( program: program, withGlobalValues: test_values)) @@ -190,7 +190,7 @@ import TreeSitterP4 P4Value(P4IntValue(withValue: 3)), ]))) let program = try #UseOkResult( - Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations)) + SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration, withGlobalInstances: test_declarations)) let runtime = try #UseOkResult( P4Runtime.Runtime.create( program: program, withGlobalValues: test_values)) @@ -237,7 +237,7 @@ import TreeSitterP4 withValue: [nested]))) let program = try #UseOkResult( - Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations)) + SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration, withGlobalInstances: test_declarations)) let runtime = try #UseOkResult( P4Runtime.Runtime.create( program: program, withGlobalValues: test_values)) @@ -276,7 +276,7 @@ import TreeSitterP4 ]))) let program = try #UseOkResult( - Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations)) + SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration, withGlobalInstances: test_declarations)) let runtime = try #UseOkResult( P4Runtime.Runtime.create( program: program, withGlobalValues: test_values)) @@ -325,7 +325,7 @@ import TreeSitterP4 withValue: [nested]))) let program = try #UseOkResult( - Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations)) + SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration, withGlobalInstances: test_declarations)) let runtime = try #UseOkResult( P4Runtime.Runtime.create( program: program, withGlobalValues: test_values)) diff --git a/Tests/p4rseTests/BinaryOperatorTests/AndOr.swift b/Tests/p4rseTests/BinaryOperatorTests/AndOr.swift index fc6a69f..0694168 100644 --- a/Tests/p4rseTests/BinaryOperatorTests/AndOr.swift +++ b/Tests/p4rseTests/BinaryOperatorTests/AndOr.swift @@ -41,7 +41,7 @@ import TreeSitterP4 }; """ - let program = try #UseOkResult(Program.Compile(simple)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple)) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) @@ -60,7 +60,7 @@ import TreeSitterP4 }; """ - let program = try #UseOkResult(Program.Compile(simple)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple)) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) @@ -79,7 +79,7 @@ import TreeSitterP4 }; """ - let program = try #UseOkResult(Program.Compile(simple)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple)) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) @@ -98,7 +98,7 @@ import TreeSitterP4 }; """ - let program = try #UseOkResult(Program.Compile(simple)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple)) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) @@ -117,7 +117,7 @@ import TreeSitterP4 }; """ - let program = try #UseOkResult(Program.Compile(simple)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple)) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) @@ -136,7 +136,7 @@ import TreeSitterP4 }; """ - let program = try #UseOkResult(Program.Compile(simple)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple)) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) @@ -155,7 +155,7 @@ import TreeSitterP4 }; """ - let program = try #UseOkResult(Program.Compile(simple)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple)) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) @@ -174,7 +174,7 @@ import TreeSitterP4 }; """ - let program = try #UseOkResult(Program.Compile(simple)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple)) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) @@ -193,7 +193,7 @@ import TreeSitterP4 }; """ - let program = try #UseOkResult(Program.Compile(simple)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple)) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) @@ -212,7 +212,7 @@ import TreeSitterP4 }; """ - let program = try #UseOkResult(Program.Compile(simple)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple)) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) diff --git a/Tests/p4rseTests/BinaryOperatorTests/Bool.swift b/Tests/p4rseTests/BinaryOperatorTests/Bool.swift index 4b9bc58..3b708d5 100644 --- a/Tests/p4rseTests/BinaryOperatorTests/Bool.swift +++ b/Tests/p4rseTests/BinaryOperatorTests/Bool.swift @@ -41,7 +41,7 @@ import TreeSitterP4 }; """ - let program = try #UseOkResult(Program.Compile(simple)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple)) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) @@ -60,7 +60,7 @@ import TreeSitterP4 }; """ - let program = try #UseOkResult(Program.Compile(simple)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple)) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) @@ -79,7 +79,7 @@ import TreeSitterP4 }; """ - let program = try #UseOkResult(Program.Compile(simple)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple)) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) @@ -98,7 +98,7 @@ import TreeSitterP4 }; """ - let program = try #UseOkResult(Program.Compile(simple)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple)) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) @@ -117,7 +117,7 @@ import TreeSitterP4 }; """ - let program = try #UseOkResult(Program.Compile(simple)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple)) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) @@ -136,7 +136,7 @@ import TreeSitterP4 }; """ - let program = try #UseOkResult(Program.Compile(simple)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple)) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) @@ -155,7 +155,7 @@ import TreeSitterP4 }; """ - let program = try #UseOkResult(Program.Compile(simple)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple)) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) @@ -174,7 +174,7 @@ import TreeSitterP4 }; """ - let program = try #UseOkResult(Program.Compile(simple)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple)) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) @@ -193,7 +193,7 @@ import TreeSitterP4 }; """ - let program = try #UseOkResult(Program.Compile(simple)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple)) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) @@ -212,7 +212,7 @@ import TreeSitterP4 }; """ - let program = try #UseOkResult(Program.Compile(simple)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple)) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) @@ -231,7 +231,7 @@ import TreeSitterP4 }; """ - let program = try #UseOkResult(Program.Compile(simple)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple)) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) @@ -250,7 +250,7 @@ import TreeSitterP4 }; """ - let program = try #UseOkResult(Program.Compile(simple)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple)) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) @@ -269,7 +269,7 @@ import TreeSitterP4 }; """ - let program = try #UseOkResult(Program.Compile(simple)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple)) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) @@ -288,7 +288,7 @@ import TreeSitterP4 }; """ - let program = try #UseOkResult(Program.Compile(simple)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple)) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) diff --git a/Tests/p4rseTests/BinaryOperatorTests/Integer.swift b/Tests/p4rseTests/BinaryOperatorTests/Integer.swift index 4869f83..86a06cd 100644 --- a/Tests/p4rseTests/BinaryOperatorTests/Integer.swift +++ b/Tests/p4rseTests/BinaryOperatorTests/Integer.swift @@ -41,7 +41,7 @@ import TreeSitterP4 }; """ - let program = try #UseOkResult(Program.Compile(simple)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple)) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) @@ -60,7 +60,7 @@ import TreeSitterP4 }; """ - let program = try #UseOkResult(Program.Compile(simple)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple)) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) @@ -79,7 +79,7 @@ import TreeSitterP4 }; """ - let program = try #UseOkResult(Program.Compile(simple)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple)) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) @@ -98,7 +98,7 @@ import TreeSitterP4 }; """ - let program = try #UseOkResult(Program.Compile(simple)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple)) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) @@ -117,7 +117,7 @@ import TreeSitterP4 }; """ - let program = try #UseOkResult(Program.Compile(simple)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple)) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) @@ -136,7 +136,7 @@ import TreeSitterP4 }; """ - let program = try #UseOkResult(Program.Compile(simple)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple)) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) @@ -155,7 +155,7 @@ import TreeSitterP4 }; """ - let program = try #UseOkResult(Program.Compile(simple)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple)) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) @@ -174,7 +174,7 @@ import TreeSitterP4 }; """ - let program = try #UseOkResult(Program.Compile(simple)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple)) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) @@ -193,7 +193,7 @@ import TreeSitterP4 }; """ - let program = try #UseOkResult(Program.Compile(simple)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple)) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) @@ -212,7 +212,7 @@ import TreeSitterP4 }; """ - let program = try #UseOkResult(Program.Compile(simple)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple)) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) @@ -231,7 +231,7 @@ import TreeSitterP4 }; """ - let program = try #UseOkResult(Program.Compile(simple)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple)) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) @@ -250,7 +250,7 @@ import TreeSitterP4 }; """ - let program = try #UseOkResult(Program.Compile(simple)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple)) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) @@ -269,7 +269,7 @@ import TreeSitterP4 }; """ - let program = try #UseOkResult(Program.Compile(simple)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple)) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) @@ -288,7 +288,7 @@ import TreeSitterP4 }; """ - let program = try #UseOkResult(Program.Compile(simple)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple)) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) @@ -310,7 +310,7 @@ import TreeSitterP4 }; """ - let program = try #UseOkResult(Program.Compile(simple)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple)) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) @@ -335,7 +335,7 @@ import TreeSitterP4 withMessage: "{72, 12}: Could not parse transition select expression selector expression: Mathematical operation on operands with non-int type is not allowed" ), - Program.Compile(simple))) + SpecialCompilers.ProgramCompiler.Compile(simple))) } @Test func test_simple_parser_binary_operator_add_non_integer2() async throws { @@ -356,7 +356,7 @@ import TreeSitterP4 withMessage: "{72, 9}: Could not parse transition select expression selector expression: Types of values used with binary expression are not the same" ), - Program.Compile(simple))) + SpecialCompilers.ProgramCompiler.Compile(simple))) } // Subtract Integers @@ -373,7 +373,7 @@ import TreeSitterP4 }; """ - let program = try #UseOkResult(Program.Compile(simple)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple)) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) @@ -398,7 +398,7 @@ import TreeSitterP4 withMessage: "{72, 12}: Could not parse transition select expression selector expression: Mathematical operation on operands with non-int type is not allowed" ), - Program.Compile(simple))) + SpecialCompilers.ProgramCompiler.Compile(simple))) } @Test func test_simple_parser_binary_operator_subtract_non_integer2() async throws { @@ -419,7 +419,7 @@ import TreeSitterP4 withMessage: "{72, 9}: Could not parse transition select expression selector expression: Types of values used with binary expression are not the same" ), - Program.Compile(simple))) + SpecialCompilers.ProgramCompiler.Compile(simple))) } // Multiply Integers @@ -436,7 +436,7 @@ import TreeSitterP4 }; """ - let program = try #UseOkResult(Program.Compile(simple)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple)) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) @@ -461,7 +461,7 @@ import TreeSitterP4 withMessage: "{72, 12}: Could not parse transition select expression selector expression: Mathematical operation on operands with non-int type is not allowed" ), - Program.Compile(simple))) + SpecialCompilers.ProgramCompiler.Compile(simple))) } @Test func test_simple_parser_binary_operator_multiply_non_integer2() async throws { @@ -482,7 +482,7 @@ import TreeSitterP4 withMessage: "{72, 9}: Could not parse transition select expression selector expression: Types of values used with binary expression are not the same" ), - Program.Compile(simple))) + SpecialCompilers.ProgramCompiler.Compile(simple))) } // Divide Integers @@ -499,7 +499,7 @@ import TreeSitterP4 }; """ - let program = try #UseOkResult(Program.Compile(simple)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple)) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) @@ -524,7 +524,7 @@ import TreeSitterP4 withMessage: "{72, 12}: Could not parse transition select expression selector expression: Mathematical operation on operands with non-int type is not allowed" ), - Program.Compile(simple))) + SpecialCompilers.ProgramCompiler.Compile(simple))) } @Test func test_simple_parser_binary_operator_divide_non_integer2() async throws { @@ -545,5 +545,5 @@ import TreeSitterP4 withMessage: "{72, 9}: Could not parse transition select expression selector expression: Types of values used with binary expression are not the same" ), - Program.Compile(simple))) + SpecialCompilers.ProgramCompiler.Compile(simple))) } diff --git a/Tests/p4rseTests/BinaryOperatorTests/String.swift b/Tests/p4rseTests/BinaryOperatorTests/String.swift index aa9a61d..9593074 100644 --- a/Tests/p4rseTests/BinaryOperatorTests/String.swift +++ b/Tests/p4rseTests/BinaryOperatorTests/String.swift @@ -41,7 +41,7 @@ import TreeSitterP4 }; """ - let program = try #UseOkResult(Program.Compile(simple)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple)) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) @@ -60,7 +60,7 @@ import TreeSitterP4 }; """ - let program = try #UseOkResult(Program.Compile(simple)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple)) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) @@ -79,7 +79,7 @@ import TreeSitterP4 }; """ - let program = try #UseOkResult(Program.Compile(simple)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple)) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) @@ -98,7 +98,7 @@ import TreeSitterP4 }; """ - let program = try #UseOkResult(Program.Compile(simple)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple)) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) @@ -117,7 +117,7 @@ import TreeSitterP4 }; """ - let program = try #UseOkResult(Program.Compile(simple)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple)) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) @@ -136,7 +136,7 @@ import TreeSitterP4 }; """ - let program = try #UseOkResult(Program.Compile(simple)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple)) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) @@ -155,7 +155,7 @@ import TreeSitterP4 }; """ - let program = try #UseOkResult(Program.Compile(simple)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple)) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) @@ -174,7 +174,7 @@ import TreeSitterP4 }; """ - let program = try #UseOkResult(Program.Compile(simple)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple)) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) @@ -193,7 +193,7 @@ import TreeSitterP4 }; """ - let program = try #UseOkResult(Program.Compile(simple)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple)) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) @@ -212,7 +212,7 @@ import TreeSitterP4 }; """ - let program = try #UseOkResult(Program.Compile(simple)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple)) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) diff --git a/Tests/p4rseTests/BinaryOperatorTests/Struct.swift b/Tests/p4rseTests/BinaryOperatorTests/Struct.swift index f6901be..e8b469c 100644 --- a/Tests/p4rseTests/BinaryOperatorTests/Struct.swift +++ b/Tests/p4rseTests/BinaryOperatorTests/Struct.swift @@ -49,7 +49,7 @@ import TreeSitterP4 test_types = test_types.declare(identifier: Identifier(name: "Testing"), withValue: struct_type) let program = try #UseOkResult( - Program.Compile(simple_parser_declaration, withGlobalInstances: .none, withGlobalTypes: test_types)) + SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration, withGlobalInstances: .none, withGlobalTypes: test_types)) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) @@ -81,7 +81,7 @@ import TreeSitterP4 test_types = test_types.declare(identifier: Identifier(name: "Testing"), withValue: struct_type) let program = try #UseOkResult( - Program.Compile(simple_parser_declaration, withGlobalInstances: .none, withGlobalTypes: test_types)) + SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration, withGlobalInstances: .none, withGlobalTypes: test_types)) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) @@ -114,7 +114,7 @@ import TreeSitterP4 test_types = test_types.declare(identifier: Identifier(name: "Testing"), withValue: struct_type) let program = try #UseOkResult( - Program.Compile(simple_parser_declaration, withGlobalInstances: .none, withGlobalTypes: test_types)) + SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration, withGlobalInstances: .none, withGlobalTypes: test_types)) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) @@ -150,7 +150,7 @@ import TreeSitterP4 test_types = test_types.declare(identifier: Identifier(name: "Testing"), withValue: struct_type) let program = try #UseOkResult( - Program.Compile(simple_parser_declaration, withGlobalInstances: .none, withGlobalTypes: test_types)) + SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration, withGlobalInstances: .none, withGlobalTypes: test_types)) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) @@ -186,7 +186,7 @@ import TreeSitterP4 test_types = test_types.declare(identifier: Identifier(name: "Testing"), withValue: struct_type) let program = try #UseOkResult( - Program.Compile(simple_parser_declaration, withGlobalInstances: .none, withGlobalTypes: test_types)) + SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration, withGlobalInstances: .none, withGlobalTypes: test_types)) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) diff --git a/Tests/p4rseTests/CodeGenTests/CodeGen.swift b/Tests/p4rseTests/CodeGenTests/CodeGen.swift index 33f3596..320b80f 100644 --- a/Tests/p4rseTests/CodeGenTests/CodeGen.swift +++ b/Tests/p4rseTests/CodeGenTests/CodeGen.swift @@ -41,7 +41,7 @@ func shrink(_ from: String) -> String { } }; """ - let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration)) let cg = try #UseOkResult(CodeGenerator().codeGen(program)) let expected = shrink( @@ -73,7 +73,7 @@ func shrink(_ from: String) -> String { } }; """ - let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration)) let cg = try #UseOkResult(CodeGenerator().codeGen(program)) /// TODO: Fix this test. diff --git a/Tests/p4rseTests/ConditionalTests.swift b/Tests/p4rseTests/ConditionalTests.swift index 73b2308..6c51b50 100644 --- a/Tests/p4rseTests/ConditionalTests.swift +++ b/Tests/p4rseTests/ConditionalTests.swift @@ -45,7 +45,7 @@ import TreeSitterP4 }; """ - let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration)) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) @@ -73,7 +73,7 @@ import TreeSitterP4 }; """ - let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration)) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) diff --git a/Tests/p4rseTests/ControlTests/Compile.swift b/Tests/p4rseTests/ControlTests/Compile.swift index 251cbfb..bf3f725 100644 --- a/Tests/p4rseTests/ControlTests/Compile.swift +++ b/Tests/p4rseTests/ControlTests/Compile.swift @@ -47,7 +47,7 @@ import TreeSitterP4 default: false } } - let program = try! #UseOkResult(Program.Compile(simple_parser_declaration)) + let program = try! #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration)) #expect(program.TypesWithTypes(x).count == 1) } @@ -85,7 +85,7 @@ import TreeSitterP4 default: false } } - let program = try! #UseOkResult(Program.Compile(simple_parser_declaration)) + let program = try! #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration)) #expect(program.TypesWithTypes(filter).count == 2) } @@ -112,7 +112,7 @@ import TreeSitterP4 default: false } } - let program = try! #UseOkResult(Program.Compile(simple_parser_declaration)) + let program = try! #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration)) #expect(program.TypesWithTypes(x).count == 1) } @@ -139,7 +139,7 @@ import TreeSitterP4 withMessage: "{54, 63}: Error(s) parsing property list: {91, 26}: Error(s) parsing table actions: Cannot find b in lexical scope." ), - Program.Compile(simple_parser_declaration)) + SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration)) ) } @@ -167,7 +167,7 @@ import TreeSitterP4 withMessage: "{54, 72}: Error(s) parsing property list: {91, 35}: Error(s) parsing table actions: Cannot find b in lexical scope." ), - Program.Compile(simple_parser_declaration)) + SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration)) ) } @@ -195,7 +195,7 @@ import TreeSitterP4 withMessage: "{64, 63}: Error(s) parsing property list: {101, 26}: Error(s) parsing table actions: {101, 26}: a does not name an action" ), - Program.Compile(simple_parser_declaration)) + SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration)) ) } @@ -214,7 +214,7 @@ import TreeSitterP4 } }; """ - #expect(#RequireOkResult(Program.Compile(simple_parser_declaration))) + #expect(#RequireOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration))) } @Test func test_simple_control_declaration_with_multiple_tables() async throws { @@ -243,7 +243,7 @@ import TreeSitterP4 Error( withMessage: "{0, 215}: More than one table in control declaration" ), - Program.Compile(simple_parser_declaration)) + SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration)) ) } @@ -263,7 +263,7 @@ import TreeSitterP4 } }; """ - #expect(#RequireOkResult(Program.Compile(simple_parser_declaration))) + #expect(#RequireOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration))) } @Test func test_simple_control_declaration_with_action_using_parameter_wrong_type() async throws { @@ -288,7 +288,7 @@ import TreeSitterP4 withMessage: "{57, 10}: Failed to parse a statement element: {57, 1}: Cannot assign value with type Boolean to identifier z with type Int (width: Infinite)" ), - Program.Compile(simple_parser_declaration)) + SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration)) ) } @@ -320,7 +320,7 @@ import TreeSitterP4 withMessage: "Could not compile the P4 program" ), - Program.Compile(simple_parser_declaration)) + SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration)) ) } @@ -347,7 +347,7 @@ import TreeSitterP4 default: false } } - let program = try! #UseOkResult(Program.Compile(simple_parser_declaration)) + let program = try! #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration)) #expect(program.TypesWithTypes(x).count == 1) } @@ -372,7 +372,7 @@ import TreeSitterP4 ErrorWithLocation( sourceLocation: SourceLocation(41, 23), withError: "All parameters with direction must precede directionless parameters"), - Program.Compile(simple_parser_declaration)) + SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration)) ) } @@ -397,6 +397,6 @@ import TreeSitterP4 ErrorWithLocation( sourceLocation: SourceLocation(41, 38), withError: "All parameters with direction must precede directionless parameters"), - Program.Compile(simple_parser_declaration)) + SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration)) ) } diff --git a/Tests/p4rseTests/ControlTests/Runtime.swift b/Tests/p4rseTests/ControlTests/Runtime.swift index 1dbd318..ea11403 100644 --- a/Tests/p4rseTests/ControlTests/Runtime.swift +++ b/Tests/p4rseTests/ControlTests/Runtime.swift @@ -50,7 +50,7 @@ import TreeSitterP4 }; """ - let program = try! #UseOkResult(Program.Compile(simple_parser_declaration)) + let program = try! #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration)) // Pull the control out of the compiled program. let controls = program.TypesWithTypes { (tipe: P4Type) -> Bool in @@ -125,7 +125,7 @@ import TreeSitterP4 }; """ - let program = try! #UseOkResult(Program.Compile(simple_parser_declaration)) + let program = try! #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration)) // Pull the control out of the compiled program. let controls = program.TypesWithTypes { (tipe: P4Type) -> Bool in @@ -200,7 +200,7 @@ import TreeSitterP4 }; """ - let program = try! #UseOkResult(Program.Compile(simple_parser_declaration)) + let program = try! #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration)) // Pull the control out of the compiled program. let controls = program.TypesWithTypes { (tipe: P4Type) -> Bool in @@ -274,7 +274,7 @@ import TreeSitterP4 }; """ - let program = try! #UseOkResult(Program.Compile(simple_parser_declaration)) + let program = try! #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration)) // Pull the control out of the compiled program. let controls = program.TypesWithTypes { (tipe: P4Type) -> Bool in @@ -349,7 +349,7 @@ import TreeSitterP4 }; """ - let program = try! #UseOkResult(Program.Compile(simple_parser_declaration)) + let program = try! #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration)) // Pull the control out of the compiled program. let controls = program.TypesWithTypes { (tipe: P4Type) -> Bool in @@ -429,7 +429,7 @@ import TreeSitterP4 }; """ - let program = try! #UseOkResult(Program.Compile(simple_parser_declaration)) + let program = try! #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration)) // Pull the control out of the compiled program. let controls = program.TypesWithTypes { (tipe: P4Type) -> Bool in @@ -557,7 +557,7 @@ import TreeSitterP4 }; """ - let program = try! #UseOkResult(Program.Compile(simple_parser_declaration)) + let program = try! #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration)) // Pull the control out of the compiled program. let controls = program.TypesWithTypes { (tipe: P4Type) -> Bool in diff --git a/Tests/p4rseTests/Declarations.swift b/Tests/p4rseTests/Declarations.swift index 2e1be41..7b3e5bf 100644 --- a/Tests/p4rseTests/Declarations.swift +++ b/Tests/p4rseTests/Declarations.swift @@ -46,7 +46,7 @@ import TreeSitterP4 }; """ let program = try #UseOkResult( - Program.Compile(simple_parser_declaration)) + SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration)) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(state_result == P4Lang.accept) @@ -71,7 +71,7 @@ import TreeSitterP4 }; """ let program = try #UseOkResult( - Program.Compile(simple_parser_declaration)) + SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration)) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(state_result == P4Lang.accept) @@ -94,7 +94,7 @@ import TreeSitterP4 }; """ let program = try #UseOkResult( - Program.Compile(simple_parser_declaration)) + SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration)) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(state_result == P4Lang.accept) @@ -117,7 +117,7 @@ import TreeSitterP4 }; """ let program = try #UseOkResult( - Program.Compile(simple_parser_declaration)) + SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration)) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(state_result == P4Lang.accept) @@ -141,7 +141,7 @@ import TreeSitterP4 }; """ let program = try #UseOkResult( - Program.Compile(simple_parser_declaration)) + SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration)) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) #expect(state_result == P4Lang.reject) @@ -153,7 +153,7 @@ import TreeSitterP4 int count; }; """ - #expect(#RequireOkResult(Program.Compile(simple_parser_declaration))) + #expect(#RequireOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration))) } @@ -163,7 +163,7 @@ import TreeSitterP4 x = true; }; """ - #expect(#RequireOkResult(Program.Compile(simple_parser_declaration))) + #expect(#RequireOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration))) } @Test func test_function_declaration_with_parameters_and_direction() async throws { @@ -178,7 +178,7 @@ import TreeSitterP4 withMessage: "{63, 9}: Failed to parse a statement element: {63, 1}: Cannot assign value with type Boolean to identifier x that is in parameter" ), - Program.Compile(simple_parser_declaration)) + SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration)) ) } @@ -198,7 +198,7 @@ import TreeSitterP4 withMessage: "{120, 15}: Failed to parse a statement element: {120, 7}: Cannot assign to field yesno of x that is in parameter" ), - Program.Compile(simple_parser_declaration)) + SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration)) ) } diff --git a/Tests/p4rseTests/ExpressionTests.swift b/Tests/p4rseTests/ExpressionTests.swift index fff30aa..35a27ff 100644 --- a/Tests/p4rseTests/ExpressionTests.swift +++ b/Tests/p4rseTests/ExpressionTests.swift @@ -40,7 +40,7 @@ import TreeSitterP4 }; """ - let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration)) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) @@ -60,7 +60,7 @@ import TreeSitterP4 }; """ - let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration)) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) @@ -80,7 +80,7 @@ import TreeSitterP4 }; """ - let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration)) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) diff --git a/Tests/p4rseTests/ExpressionTests/FunctionCall.swift b/Tests/p4rseTests/ExpressionTests/FunctionCall.swift index 9d8f867..6689f4b 100644 --- a/Tests/p4rseTests/ExpressionTests/FunctionCall.swift +++ b/Tests/p4rseTests/ExpressionTests/FunctionCall.swift @@ -44,7 +44,7 @@ import TreeSitterP4 }; """ - let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration)) let parser = try #UseOkResult(program.find_parser(withName: Identifier(name: "main_parser"))) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) @@ -73,7 +73,7 @@ import TreeSitterP4 }; """ - let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration)) let parser = try #UseOkResult(program.find_parser(withName: Identifier(name: "main_parser"))) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) @@ -101,7 +101,7 @@ import TreeSitterP4 }; """ - let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration)) let parser = try #UseOkResult(program.find_parser(withName: Identifier(name: "main_parser"))) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) @@ -128,7 +128,7 @@ import TreeSitterP4 }; """ - let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration)) let parser = try #UseOkResult(program.find_parser(withName: Identifier(name: "main_parser"))) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) @@ -154,7 +154,7 @@ import TreeSitterP4 }; """ - let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration)) let parser = try #UseOkResult(program.find_parser(withName: Identifier(name: "main_parser"))) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) @@ -180,7 +180,7 @@ import TreeSitterP4 }; """ - let error = try #UseErrorResult(Program.Compile(simple_parser_declaration)) + let error = try #UseErrorResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration)) #expect(error.msg().contains("{29, 12}: Type of expression in return statement (Boolean) is not compatible with function return type (Int (width: Infinite))")) } diff --git a/Tests/p4rseTests/ExpressionTests/SelectExpression.swift b/Tests/p4rseTests/ExpressionTests/SelectExpression.swift index f10b158..0b116d8 100644 --- a/Tests/p4rseTests/ExpressionTests/SelectExpression.swift +++ b/Tests/p4rseTests/ExpressionTests/SelectExpression.swift @@ -39,7 +39,7 @@ import TreeSitterP4 }; """ - let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration)) let parser = try #UseOkResult(program.find_parser(withName: Identifier(name: "main_parser"))) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) @@ -61,7 +61,7 @@ import TreeSitterP4 }; """ - let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration)) let parser = try #UseOkResult(program.find_parser(withName: Identifier(name: "main_parser"))) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) @@ -83,7 +83,7 @@ import TreeSitterP4 }; """ - let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration)) let parser = try #UseOkResult(program.find_parser(withName: Identifier(name: "main_parser"))) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) @@ -105,7 +105,7 @@ import TreeSitterP4 } }; """ - let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration)) let parser = try #UseOkResult(program.find_parser(withName: Identifier(name: "main_parser"))) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) @@ -134,7 +134,7 @@ import TreeSitterP4 withMessage: "Error(s) parsing select cases: {81, 4}: Key expression of type Boolean is not compatible with selector type Int (width: Infinite)" ), - Program.Compile(simple_parser_declaration))) + SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration))) } @Test func test_select_expression_selection_order() async throws { @@ -149,7 +149,7 @@ import TreeSitterP4 } }; """ - let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration)) let parser = try #UseOkResult(program.find_parser(withName: Identifier(name: "main_parser"))) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) @@ -171,7 +171,7 @@ import TreeSitterP4 } }; """ - let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration)) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let args = ArgumentList([ @@ -192,7 +192,7 @@ import TreeSitterP4 } }; """ - let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration)) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let args = ArgumentList([ diff --git a/Tests/p4rseTests/ExternDeclarations.swift b/Tests/p4rseTests/ExternDeclarations.swift index 3f16d0d..cb2780f 100644 --- a/Tests/p4rseTests/ExternDeclarations.swift +++ b/Tests/p4rseTests/ExternDeclarations.swift @@ -85,7 +85,7 @@ public struct Return6: P4FFI { let externally = Return5() let program = try! #UseOkResult( - Program.Compile( + SpecialCompilers.ProgramCompiler.Compile( simple_parser_declaration, withGlobalInstances: .none, withGlobalTypes: .none, withFFIs: [externally])) @@ -113,7 +113,7 @@ public struct Return6: P4FFI { let externally = Return6() let program = try! #UseOkResult( - Program.Compile( + SpecialCompilers.ProgramCompiler.Compile( simple_parser_declaration, withGlobalInstances: .none, withGlobalTypes: .none, withFFIs: [externally])) diff --git a/Tests/p4rseTests/InterloperTests.swift b/Tests/p4rseTests/InterloperTests.swift index 6dbf4bb..d31d5c0 100644 --- a/Tests/p4rseTests/InterloperTests.swift +++ b/Tests/p4rseTests/InterloperTests.swift @@ -46,7 +46,7 @@ import TreeSitterP4 }; """ - let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration)) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) var statements_executed: [String] = Array() @@ -87,7 +87,7 @@ import TreeSitterP4 }; """ - let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration)) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) var expressions_evaluated: [String] = Array() diff --git a/Tests/p4rseTests/ParserCompilerTests.swift b/Tests/p4rseTests/ParserCompilerTests.swift index d328f1a..49ff158 100644 --- a/Tests/p4rseTests/ParserCompilerTests.swift +++ b/Tests/p4rseTests/ParserCompilerTests.swift @@ -38,7 +38,7 @@ import P4Lang #expect( #RequireErrorResult( Error(withMessage: "Could not compile the P4 program"), - Program.Compile(simple_parser_declaration))) + SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration))) } @Test func test_simple_compilation_with_statement() async throws { @@ -51,7 +51,7 @@ import P4Lang }; """ - let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration)) let parser = try #UseOkResult(program.find_parser(withName: Identifier(name: "main_parser"))) #expect(parser.states.count() == 1) @@ -73,7 +73,7 @@ import P4Lang }; """ - let compilation_error = try #UseErrorResult(Program.Compile(simple_parser_declaration)) + let compilation_error = try #UseErrorResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration)) #expect(compilation_error.msg().contains("asde")) #expect(compilation_error.msg().contains("asdf")) @@ -110,7 +110,7 @@ import P4Lang }; """ - let program = try! #UseOkResult(Program.Compile(simple)) + let program = try! #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple)) let parser = try! #UseOkResult(program.find_parser(withName: Identifier(name: "main_parser"))) let parameters = parser.parameters @@ -130,7 +130,7 @@ import P4Lang }; """ - let program = try! #UseOkResult(Program.Compile(simple)) + let program = try! #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple)) let parser = try! #UseOkResult(program.find_parser(withName: Identifier(name: "main_parser"))) let parameters = parser.parameters @@ -153,7 +153,7 @@ import P4Lang }; """ - let program = try! #UseOkResult(Program.Compile(simple)) + let program = try! #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple)) let parser = try! #UseOkResult(program.find_parser(withName: Identifier(name: "main_parser"))) let parameters = parser.parameters @@ -180,5 +180,18 @@ import P4Lang }; """ - #expect(#RequireOkResult(Program.Compile(simple))) + #expect(#RequireOkResult(SpecialCompilers.ProgramCompiler.Compile(simple))) } + +@Test func test_simple_compiler_with_instantiation() async throws { + let simple_instantiation_program = """ + parser MainParser() { + state start { + transition accept; + } + }; + + MainParser() mp; + """ + #expect(#RequireOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_instantiation_program))) +} \ No newline at end of file diff --git a/Tests/p4rseTests/RuntimeTests.swift b/Tests/p4rseTests/RuntimeTests.swift index 4984216..5b9fb02 100644 --- a/Tests/p4rseTests/RuntimeTests.swift +++ b/Tests/p4rseTests/RuntimeTests.swift @@ -37,7 +37,7 @@ import TreeSitterP4 }; """ - let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration)) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) @@ -55,7 +55,7 @@ import TreeSitterP4 }; """ - let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration)) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) // We should be in the accept state. @@ -72,7 +72,7 @@ import TreeSitterP4 }; """ - let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration)) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) #expect( @@ -92,7 +92,7 @@ import TreeSitterP4 } }; """ - let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration)) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let args = ArgumentList([ @@ -114,7 +114,7 @@ import TreeSitterP4 } }; """ - let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration)) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let args = ArgumentList([ @@ -138,7 +138,7 @@ import TreeSitterP4 } }; """ - let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration)) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let args = ArgumentList([ @@ -162,7 +162,7 @@ import TreeSitterP4 } }; """ - let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration)) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let args = ArgumentList([Argument(P4Value(P4BooleanValue(withValue: true)), atIndex: 0)]) diff --git a/Tests/p4rseTests/ScopeRuntimeTests.swift b/Tests/p4rseTests/ScopeRuntimeTests.swift index 99f36b8..55e868b 100644 --- a/Tests/p4rseTests/ScopeRuntimeTests.swift +++ b/Tests/p4rseTests/ScopeRuntimeTests.swift @@ -42,7 +42,7 @@ import TreeSitterP4 """ - let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration)) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) @@ -68,7 +68,7 @@ import TreeSitterP4 """ - let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration)) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) @@ -96,7 +96,7 @@ import TreeSitterP4 """ - let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration)) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) @@ -120,7 +120,7 @@ import TreeSitterP4 """ - let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration)) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) @@ -151,7 +151,7 @@ import TreeSitterP4 """ - let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration)) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) diff --git a/Tests/p4rseTests/StructTests.swift b/Tests/p4rseTests/StructTests.swift index 931d6fd..77147ce 100644 --- a/Tests/p4rseTests/StructTests.swift +++ b/Tests/p4rseTests/StructTests.swift @@ -60,7 +60,7 @@ import TreeSitterP4 ]))) let program = try #UseOkResult( - Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations)) + SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration, withGlobalInstances: test_declarations)) let runtime = try #UseOkResult( P4Runtime.Runtime.create( program: program, withGlobalValues: test_values)) @@ -91,7 +91,7 @@ import TreeSitterP4 test_types = test_types.declare(identifier: Identifier(name: "Testing"), withValue: struct_type) let program = try #UseOkResult( - Program.Compile( + SpecialCompilers.ProgramCompiler.Compile( simple_parser_declaration, withGlobalInstances: .none, withGlobalTypes: test_types)) let runtime = try #UseOkResult( P4Runtime.Runtime.create(program: program)) @@ -124,7 +124,7 @@ import TreeSitterP4 identifier: Identifier(name: "Testing"), withValue: struct_type) let program = try #UseOkResult( - Program.Compile(simple_parser_declaration, withGlobalInstances: .none, withGlobalTypes: test_declarations)) + SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration, withGlobalInstances: .none, withGlobalTypes: test_declarations)) let runtime = try #UseOkResult( P4Runtime.Runtime.create(program: program)) @@ -165,7 +165,7 @@ import TreeSitterP4 ]))) let program = try #UseOkResult( - Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations)) + SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration, withGlobalInstances: test_declarations)) let runtime = try #UseOkResult( P4Runtime.Runtime.create( program: program, withGlobalValues: test_values)) @@ -205,7 +205,7 @@ import TreeSitterP4 ]))) let program = try #UseOkResult( - Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations)) + SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration, withGlobalInstances: test_declarations)) let runtime = try #UseOkResult( P4Runtime.Runtime.create( program: program, withGlobalValues: test_values)) @@ -245,7 +245,7 @@ import TreeSitterP4 ]))) let program = try #UseOkResult( - Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations)) + SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration, withGlobalInstances: test_declarations)) let runtime = try #UseOkResult( P4Runtime.Runtime.create( program: program, withGlobalValues: test_values)) @@ -298,7 +298,7 @@ import TreeSitterP4 ])) ]))) let program = try #UseOkResult( - Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations)) + SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration, withGlobalInstances: test_declarations)) let runtime = try #UseOkResult( P4Runtime.Runtime.create( program: program, withGlobalValues: test_values)) @@ -340,7 +340,7 @@ import TreeSitterP4 ]))) let program = try #UseOkResult( - Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations)) + SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration, withGlobalInstances: test_declarations)) let runtime = try #UseOkResult( P4Runtime.Runtime.create( program: program, withGlobalValues: test_values)) @@ -372,7 +372,7 @@ import TreeSitterP4 withMessage: "{49, 13}: Failed to parse a statement element: {49, 8}: Cannot assign value of type Int (width: Infinite) to field yesno of type Boolean" ), - Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations)) + SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration, withGlobalInstances: test_declarations)) ) } @@ -422,7 +422,7 @@ import TreeSitterP4 ])) ]))) let program = try #UseOkResult( - Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations)) + SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration, withGlobalInstances: test_declarations)) let runtime = try #UseOkResult( P4Runtime.Runtime.create( program: program, withGlobalValues: test_values)) @@ -477,7 +477,7 @@ import TreeSitterP4 ])) ]))) let program = try #UseOkResult( - Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations)) + SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration, withGlobalInstances: test_declarations)) let runtime = try #UseOkResult( P4Runtime.Runtime.create( program: program, withGlobalValues: test_values)) @@ -520,7 +520,7 @@ import TreeSitterP4 withMessage: "{49, 20}: Failed to parse a statement element: {49, 11}: Cannot assign value of type Boolean to field count of type Int (width: Infinite)" ), - Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations)) + SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration, withGlobalInstances: test_declarations)) ) } @@ -551,6 +551,6 @@ import TreeSitterP4 withMessage: "{68, 21}: Could not parse transition select expression selector expression: Types of values used with binary expression are not the same" ), - Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations)) + SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration, withGlobalInstances: test_declarations)) ) } diff --git a/Tests/p4rseTests/SupportTests/SourceCode.swift b/Tests/p4rseTests/SupportTests/SourceCode.swift index 9b1dd75..b0af010 100644 --- a/Tests/p4rseTests/SupportTests/SourceCode.swift +++ b/Tests/p4rseTests/SupportTests/SourceCode.swift @@ -34,7 +34,7 @@ import TreeSitterP4 let file = FilePath.init(stringLiteral: "simple.p4") let source = try! (#UseOkResult(prep.preprocess(file))) - let program = try! #UseOkResult(Program.Compile(source.getSource())) + let program = try! #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(source.getSource())) #expect(#RequireOkResult((program.find_parser(withName: Identifier(name: "main_parser"))))) #expect(source.getLocations().getPath() == file) } @@ -45,7 +45,7 @@ import TreeSitterP4 let file = FilePath.init(stringLiteral: "simple.p4") let source = try! (#UseOkResult(prep.preprocess(file))) - let program = try! #UseOkResult(Program.Compile(source.getSource())) + let program = try! #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(source.getSource())) #expect(#RequireOkResult((program.find_parser(withName: Identifier(name: "main_parser"))))) #expect(source.getLocations().getPath() == file) } @@ -58,7 +58,7 @@ import TreeSitterP4 #expect(#RequireOkResult(prep.preprocess(file))) let source = try! (#UseOkResult(prep.preprocess(file))) - let program = try! #UseOkResult(Program.Compile(source.getSource())) + let program = try! #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(source.getSource())) #expect(#RequireOkResult((program.find_parser(withName: Identifier(name: "main_parser"))))) #expect(source.getLocations().getPath() == file) } @@ -71,7 +71,7 @@ import TreeSitterP4 #expect(#RequireOkResult(prep.preprocess(file))) let source = try! (#UseOkResult(prep.preprocess(file))) - let program = try! #UseOkResult(Program.Compile(source.getSource())) + let program = try! #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(source.getSource())) #expect(#RequireOkResult((program.find_parser(withName: Identifier(name: "main_parser"))))) #expect(source.getLocations().getPath() == file) } diff --git a/Tests/p4rseTests/TransitionTests.swift b/Tests/p4rseTests/TransitionTests.swift index ec9faee..5dd9fa3 100644 --- a/Tests/p4rseTests/TransitionTests.swift +++ b/Tests/p4rseTests/TransitionTests.swift @@ -39,7 +39,7 @@ import TreeSitterP4 }; """ - let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration)) let parser = try #UseOkResult(program.find_parser(withName: Identifier(name: "main_parser"))) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) @@ -61,7 +61,7 @@ import TreeSitterP4 }; """ - let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration)) let parser = try #UseOkResult(program.find_parser(withName: Identifier(name: "main_parser"))) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) @@ -81,7 +81,7 @@ import TreeSitterP4 }; """ - let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration)) let runtime = try #UseOkResult(P4Runtime.Runtime.create(program: program)) #expect( diff --git a/Tests/p4rseTests/Unsupported.swift b/Tests/p4rseTests/Unsupported.swift index 5e8bbbc..38141b5 100644 --- a/Tests/p4rseTests/Unsupported.swift +++ b/Tests/p4rseTests/Unsupported.swift @@ -38,7 +38,7 @@ import TreeSitterP4 #expect( #RequireErrorResult( Error(withMessage: "{0, 8}: Annotations in parser type are not yet handled."), - Program.Compile(simple_annotated_parser_declaration))) + SpecialCompilers.ProgramCompiler.Compile(simple_annotated_parser_declaration))) } @Test func test_unsupported_annotations_state() async throws { @@ -52,5 +52,5 @@ import TreeSitterP4 #expect( #RequireErrorResult( Error(withMessage: "{26, 8}: Annotations in parser state are not yet handled."), - Program.Compile(simple_annotated_parser_declaration))) + SpecialCompilers.ProgramCompiler.Compile(simple_annotated_parser_declaration))) } diff --git a/Tests/p4rseTests/ValueTypeParserTests.swift b/Tests/p4rseTests/ValueTypeParserTests.swift index 12437b7..fb40702 100644 --- a/Tests/p4rseTests/ValueTypeParserTests.swift +++ b/Tests/p4rseTests/ValueTypeParserTests.swift @@ -38,7 +38,7 @@ import TreeSitterP4 }; """ - let err = Program.Compile(simple_parser_declaration) + let err = SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration) guard case Result.Error(let e) = err else { assert(false, "Expected an error, but had success") } @@ -66,7 +66,7 @@ import TreeSitterP4 withMessage: "{112, 16}: Failed to parse a statement element: {112, 8}: Cannot assign value with type Boolean to identifier where_to with type String" ), - Program.Compile(simple_parser_declaration))) + SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration))) } @Test func test_invalid_type_in_assignment2() async throws { @@ -87,7 +87,7 @@ import TreeSitterP4 withMessage: "{114, 22}: Failed to parse a statement element: {114, 8}: Cannot assign value with type String to identifier where_to with type Boolean" ), - Program.Compile(simple_parser_declaration))) + SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration))) } @Test func test_invalid_type_in_declaration() async throws { @@ -107,7 +107,7 @@ import TreeSitterP4 withMessage: "{86, 27}: Failed to parse a statement element: Cannot initialize where_to (with type Boolean) from expression with type String" ), - Program.Compile(simple_parser_declaration))) + SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration))) } @Test func test_invalid_type_in_declaration2() async throws { @@ -127,7 +127,7 @@ import TreeSitterP4 withMessage: "{77, 29}: Failed to parse a statement element: Cannot initialize where_from (with type String) from expression with type Boolean" ), - Program.Compile(simple_parser_declaration))) + SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration))) } @Test func test_invalid_type_in_declaration3() async throws { @@ -141,7 +141,7 @@ import TreeSitterP4 }; """ - let error = try! #UseErrorResult(Program.Compile(simple_parser_declaration)) + let error = try! #UseErrorResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration)) #expect( error.msg().contains( @@ -160,7 +160,7 @@ import TreeSitterP4 }; """ - #expect(#RequireOkResult(Program.Compile(simple_parser_declaration))) + #expect(#RequireOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration))) } @Test func test_expression_in_declaration_initializer_specific_width_int_type() async throws { @@ -177,7 +177,7 @@ import TreeSitterP4 }; """ - let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration)) let runtime = try #UseOkResult( P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) @@ -202,7 +202,7 @@ import TreeSitterP4 }; """ - let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration)) let runtime = try #UseOkResult( P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) @@ -225,7 +225,7 @@ import TreeSitterP4 } }; """ - let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration)) let runtime = try #UseOkResult( P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) @@ -248,7 +248,7 @@ import TreeSitterP4 } }; """ - let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration)) let runtime = try #UseOkResult( P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) @@ -271,7 +271,7 @@ import TreeSitterP4 } }; """ - let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration)) let runtime = try #UseOkResult( P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) @@ -294,7 +294,7 @@ import TreeSitterP4 } }; """ - let program = try #UseOkResult(Program.Compile(simple_parser_declaration)) + let program = try #UseOkResult(SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration)) let runtime = try #UseOkResult( P4Runtime.Runtime.create(program: program)) let (state_result, _) = try! #UseOkResult(runtime.run()) @@ -324,7 +324,7 @@ import TreeSitterP4 withMessage: "{49, 35}: Failed to parse a statement element: Types of values used with binary expression are not the same" ), - Program.Compile(simple_parser_declaration))) + SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration))) } @@ -351,7 +351,7 @@ import TreeSitterP4 withMessage: "{49, 22}: Failed to parse a statement element: Cannot initialize where_to (with type Boolean) from expression with type Int (width: Infinite)" ), - Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations))) + SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration, withGlobalInstances: test_declarations))) } @Test func test_simple_compiler_parser_parameters_invalid_types() async throws { @@ -369,5 +369,5 @@ import TreeSitterP4 withMessage: "{85, 9}: Failed to parse a statement element: {85, 4}: Cannot assign value with type Int (width: Infinite) to identifier pmtr with type Boolean" ), - Program.Compile(simple_parser_declaration))) + SpecialCompilers.ProgramCompiler.Compile(simple_parser_declaration))) }