mirror of
https://github.com/HigherOrderCO/Bend.git
synced 2024-09-11 03:45:29 +03:00
Merge pull request #535 from HigherOrderCO/hvm-path-option
Hvm path option
This commit is contained in:
commit
a5066181c5
15
src/lib.rs
15
src/lib.rs
@ -173,7 +173,7 @@ pub fn run_book(
|
|||||||
// cancel the run if a problem is detected.
|
// cancel the run if a problem is detected.
|
||||||
eprint!("{diagnostics}");
|
eprint!("{diagnostics}");
|
||||||
|
|
||||||
let out = run_hvm(&core_book, cmd)?;
|
let out = run_hvm(&core_book, cmd, &run_opts)?;
|
||||||
let (net, stats) = parse_hvm_output(&out)?;
|
let (net, stats) = parse_hvm_output(&out)?;
|
||||||
let (term, diags) =
|
let (term, diags) =
|
||||||
readback_hvm_net(&net, &book, &labels, run_opts.linear_readback, compile_opts.adt_encoding);
|
readback_hvm_net(&net, &book, &labels, run_opts.linear_readback, compile_opts.adt_encoding);
|
||||||
@ -198,7 +198,7 @@ pub fn readback_hvm_net(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Runs an HVM book by invoking HVM as a subprocess.
|
/// Runs an HVM book by invoking HVM as a subprocess.
|
||||||
fn run_hvm(book: &::hvm::ast::Book, cmd: &str) -> Result<String, String> {
|
fn run_hvm(book: &::hvm::ast::Book, cmd: &str, run_opts: &RunOpts) -> Result<String, String> {
|
||||||
fn filter_hvm_output(
|
fn filter_hvm_output(
|
||||||
mut stream: impl std::io::Read + Send,
|
mut stream: impl std::io::Read + Send,
|
||||||
mut output: impl std::io::Write + Send,
|
mut output: impl std::io::Write + Send,
|
||||||
@ -247,7 +247,7 @@ fn run_hvm(book: &::hvm::ast::Book, cmd: &str) -> Result<String, String> {
|
|||||||
|
|
||||||
let out_path = ".out.hvm";
|
let out_path = ".out.hvm";
|
||||||
std::fs::write(out_path, display_hvm_book(book).to_string()).map_err(|x| x.to_string())?;
|
std::fs::write(out_path, display_hvm_book(book).to_string()).map_err(|x| x.to_string())?;
|
||||||
let mut process = std::process::Command::new("hvm")
|
let mut process = std::process::Command::new(run_opts.hvm_path.clone())
|
||||||
.arg(cmd)
|
.arg(cmd)
|
||||||
.arg(out_path)
|
.arg(out_path)
|
||||||
.stdout(std::process::Stdio::piped())
|
.stdout(std::process::Stdio::piped())
|
||||||
@ -281,10 +281,17 @@ fn parse_hvm_output(out: &str) -> Result<(::hvm::ast::Net, String), String> {
|
|||||||
Ok((net, stats.to_string()))
|
Ok((net, stats.to_string()))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Default)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct RunOpts {
|
pub struct RunOpts {
|
||||||
pub linear_readback: bool,
|
pub linear_readback: bool,
|
||||||
pub pretty: bool,
|
pub pretty: bool,
|
||||||
|
pub hvm_path: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for RunOpts {
|
||||||
|
fn default() -> Self {
|
||||||
|
RunOpts { linear_readback: false, pretty: false, hvm_path: "hvm".to_string() }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Default)]
|
#[derive(Clone, Copy, Debug, Default)]
|
||||||
|
@ -20,6 +20,9 @@ struct Cli {
|
|||||||
#[arg(short, long, global = true)]
|
#[arg(short, long, global = true)]
|
||||||
pub verbose: bool,
|
pub verbose: bool,
|
||||||
|
|
||||||
|
#[arg(long, global = true, default_value = "hvm", help = "Path to hvm binary")]
|
||||||
|
pub hvm_path: String,
|
||||||
|
|
||||||
#[arg(short = 'e', long, global = true, help = "Use other entrypoint rather than main or Main")]
|
#[arg(short = 'e', long, global = true, help = "Use other entrypoint rather than main or Main")]
|
||||||
pub entrypoint: Option<String>,
|
pub entrypoint: Option<String>,
|
||||||
}
|
}
|
||||||
@ -303,7 +306,7 @@ fn execute_cli_mode(mut cli: Cli) -> Result<(), Diagnostics> {
|
|||||||
.map_err(|x| x.to_string())?;
|
.map_err(|x| x.to_string())?;
|
||||||
|
|
||||||
let gen_fn = |out_path: &str| {
|
let gen_fn = |out_path: &str| {
|
||||||
let mut process = std::process::Command::new("hvm");
|
let mut process = std::process::Command::new(cli.hvm_path);
|
||||||
process.arg(gen_cmd).arg(out_path);
|
process.arg(gen_cmd).arg(out_path);
|
||||||
process.output().map_err(|e| format!("While running hvm: {e}"))
|
process.output().map_err(|e| format!("While running hvm: {e}"))
|
||||||
};
|
};
|
||||||
@ -350,7 +353,7 @@ fn execute_cli_mode(mut cli: Cli) -> Result<(), Diagnostics> {
|
|||||||
|
|
||||||
compile_opts.check_for_strict();
|
compile_opts.check_for_strict();
|
||||||
|
|
||||||
let run_opts = RunOpts { linear_readback: linear, pretty };
|
let run_opts = RunOpts { linear_readback: linear, pretty, hvm_path: cli.hvm_path };
|
||||||
|
|
||||||
let book = load_book(&path)?;
|
let book = load_book(&path)?;
|
||||||
if let Some((term, stats, diags)) =
|
if let Some((term, stats, diags)) =
|
||||||
|
@ -175,7 +175,8 @@ fn run_file() {
|
|||||||
|
|
||||||
for adt_encoding in [AdtEncoding::NumScott, AdtEncoding::Scott] {
|
for adt_encoding in [AdtEncoding::NumScott, AdtEncoding::Scott] {
|
||||||
let compile_opts = CompileOpts { adt_encoding, ..CompileOpts::default() };
|
let compile_opts = CompileOpts { adt_encoding, ..CompileOpts::default() };
|
||||||
let (term, _, diags) = run_book_simple(book.clone(), run_opts, compile_opts, diagnostics_cfg, None)?;
|
let (term, _, diags) =
|
||||||
|
run_book_simple(book.clone(), run_opts.clone(), compile_opts, diagnostics_cfg, None)?;
|
||||||
res.push_str(&format!("{adt_encoding}:\n{diags}{term}\n\n"));
|
res.push_str(&format!("{adt_encoding}:\n{diags}{term}\n\n"));
|
||||||
}
|
}
|
||||||
Ok(res)
|
Ok(res)
|
||||||
|
Loading…
Reference in New Issue
Block a user