Parse parameter list

This commit is contained in:
2024-03-28 00:55:13 +01:00
parent 12869f0ec7
commit 90430c47f4
10 changed files with 76 additions and 14 deletions

View File

@ -0,0 +1,2 @@
5
3

View File

@ -0,0 +1 @@
5

View File

@ -0,0 +1,9 @@
proc g()
begin
writei(5);
writei(3)
end;
begin
g()
end.

View File

@ -1,4 +1,4 @@
proc f; writei(5);
proc f() writei(5);
begin
f()

View File

@ -0,0 +1,5 @@
proc f(a: Int) writei(a);
begin
f(5)
end.

View File

@ -43,17 +43,33 @@ namespace elna
return in_build_directory() / path;
}
test_result run_for_output(boost::asio::io_context& context, const std::filesystem::path& binary,
std::initializer_list<boost::string_view> arguments)
boost::process::v2::process_stdio get_output_streams(const std::uint8_t stream_number,
boost::asio::readable_pipe& read_pipe)
{
if (stream_number == 1)
{
return boost::process::v2::process_stdio{ nullptr, read_pipe };
}
if (stream_number == 2)
{
return boost::process::v2::process_stdio{ nullptr, {}, read_pipe };
}
return boost::process::v2::process_stdio{ nullptr, read_pipe, read_pipe };
}
test_result run_for_output(boost::asio::io_context& context, const std::uint8_t stream_number,
const std::filesystem::path& binary, std::initializer_list<boost::string_view> arguments)
{
boost::asio::readable_pipe read_pipe{ context };
test_result result{};
std::string output;
boost::asio::dynamic_string_buffer buffer = boost::asio::dynamic_buffer(output);
boost::system::error_code ec;
boost::process::v2::process_stdio process_stdio;
boost::process::v2::process elna_child(context,
binary, arguments,
boost::process::v2::process_stdio{ nullptr, read_pipe, read_pipe });
get_output_streams(stream_number, read_pipe));
do
{
std::size_t transferred = read_pipe.read_some(buffer.prepare(512), ec);
@ -84,7 +100,7 @@ namespace elna
std::filesystem::remove(test_binary);
std::filesystem::remove(test_object);
test_result result = run_for_output(context, "./build/bin/elna",
test_result result = run_for_output(context, 2, "./build/bin/elna",
{ "-o", test_object.string(), test_entry.path().string() });
if (result.code != 0)
@ -157,7 +173,7 @@ namespace elna
std::filesystem::path test_binary = in_build_directory(test_filename);
test_binary.replace_extension();
return run_for_output(context,
return run_for_output(context, 1,
boost::process::search_path("qemu-riscv32"),
{ test_binary.string() });
}