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 <hawkinsw@obs.cr>
This commit is contained in:
@@ -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<InstantiatedParserState, P4Lang.ParserValue>.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<InstantiatedParserState, P4Lang.ParserValue>.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<InstantiatedParserState, P4Lang.ParserValue>.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<InstantiatedParserState, P4Lang.ParserValue>.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<InstantiatedParserState, P4Lang.ParserValue>.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<InstantiatedParserState, P4Lang.ParserValue>.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)))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user