Execute expressions properly

This way we can actually capture their execution status
This commit is contained in:
Nathan McCarty 2024-12-31 20:56:32 +00:00
parent 6971949a53
commit f085e8e14b

View file

@ -52,6 +52,21 @@ class IdrisError is Exception {
}
}
#| An error coming from a compiled expression
class ExpressionError is Exception {
has Str $.out;
has Str $.err;
has Int $.exit-code;
has Str $.expr;
method message {
qq:to/END/;
Error running expression: $.expr
Command exited with $.exit-code
END
}
}
#| Invoke an idris command
sub idris-run(*@cmd) is export {
my $proc = run "idris2", @cmd, :out, :err;
@ -69,5 +84,17 @@ sub idris-run(*@cmd) is export {
# TODO: Special handling for IO Bool to make this eaiser
#| Exec the expression with the given name in the given file
sub idris-exec($expr, $file) is export {
idris-run '--find-ipkg', '--exec', $expr, $file
# Have idris compile an executable for the expression,
idris-run '--find-ipkg', '--client', ":c iutils_out $expr", $file;
# Run the expression
my $proc = run 'build/exec/iutils_out', :out, :err;
my $out = $proc.out.slurp(:close);
my $err = $proc.err.slurp(:close);
unless $proc {
ExpressionError.new(
out => $out, err => $err,
exit-code => $proc.exitcode, expr => $expr
).throw;
}
return $out;
}