runtime: Parameterize Runtime

Parameterize Runtime (nee ParserRuntime) so that it can run anything
that is LibraryCallable. TODO: Refactor its API -- left mostly as
it was because changing unit tests will be laborious.
This commit is contained in:
Will Hawkins
2026-04-30 18:37:21 -04:00
parent b97aa1af72
commit bd262e5b73
19 changed files with 147 additions and 153 deletions
+10 -10
View File
@@ -57,7 +57,7 @@ import TreeSitterP4
let program = try #UseOkResult(
Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program, withGlobalValues: test_values))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program, withGlobalValues: test_values))
let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.accept)
}
@@ -86,7 +86,7 @@ import TreeSitterP4
let program = try #UseOkResult(
Program.Compile(simple_parser_declaration, withGlobalInstances: .none, withGlobalTypes: test_types))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.accept)
}
@@ -116,7 +116,7 @@ import TreeSitterP4
let program = try #UseOkResult(
Program.Compile(simple_parser_declaration, withGlobalInstances: .none, withGlobalTypes: test_types))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program))
let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.accept)
}
@@ -151,7 +151,7 @@ import TreeSitterP4
let program = try #UseOkResult(
Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program, withGlobalValues: test_values))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program, withGlobalValues: test_values))
let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.reject)
}
@@ -186,7 +186,7 @@ import TreeSitterP4
let program = try #UseOkResult(
Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program, withGlobalValues: test_values))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program, withGlobalValues: test_values))
let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.accept)
}
@@ -220,7 +220,7 @@ import TreeSitterP4
let program = try #UseOkResult(
Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program, withGlobalValues: test_values))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program, withGlobalValues: test_values))
let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.reject)
}
@@ -266,7 +266,7 @@ import TreeSitterP4
])))
let program = try #UseOkResult(
Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program, withGlobalValues: test_values))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program, withGlobalValues: test_values))
let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.accept)
}
@@ -302,7 +302,7 @@ import TreeSitterP4
let program = try #UseOkResult(
Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program, withGlobalValues: test_values))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program, withGlobalValues: test_values))
let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.accept)
}
@@ -375,7 +375,7 @@ import TreeSitterP4
])))
let program = try #UseOkResult(
Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program, withGlobalValues: test_values))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program, withGlobalValues: test_values))
let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.accept)
}
@@ -423,7 +423,7 @@ import TreeSitterP4
])))
let program = try #UseOkResult(
Program.Compile(simple_parser_declaration, withGlobalInstances: test_declarations))
let runtime = try #UseOkResult(P4Runtime.ParserRuntime.create(program: program, withGlobalValues: test_values))
let runtime = try #UseOkResult(P4Runtime.Runtime<InstantiatedParserState, P4Lang.Parser>.create(program: program, withGlobalValues: test_values))
let (state_result, _) = try! #UseOkResult(runtime.run())
#expect(AsInstantiatedParserState(state_result) == P4Lang.accept)
}