mirror of
https://github.com/HigherOrderCO/Bend.git
synced 2024-09-11 03:45:29 +03:00
Merge pull request #541 from HigherOrderCO/479-add-option-to-use-different-hvm-binary
Rename hvm bin option to hvm-bin, add env var with same name
This commit is contained in:
commit
3b88a7ec9c
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -62,7 +62,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bend-lang"
|
name = "bend-lang"
|
||||||
version = "0.2.28"
|
version = "0.2.29"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"TSPL",
|
"TSPL",
|
||||||
"clap",
|
"clap",
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
name = "bend-lang"
|
name = "bend-lang"
|
||||||
description = "A high-level, massively parallel programming language"
|
description = "A high-level, massively parallel programming language"
|
||||||
license = "Apache-2.0"
|
license = "Apache-2.0"
|
||||||
version = "0.2.28"
|
version = "0.2.29"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
rust-version = "1.74"
|
rust-version = "1.74"
|
||||||
exclude = ["tests/"]
|
exclude = ["tests/"]
|
||||||
|
76
src/main.rs
76
src/main.rs
@ -20,8 +20,8 @@ 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")]
|
#[arg(long, global = true, help = "HVM command or path to HVM binary")]
|
||||||
pub hvm_path: String,
|
pub hvm_bin: Option<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>,
|
||||||
@ -260,6 +260,16 @@ fn execute_cli_mode(mut cli: Cli) -> Result<(), Diagnostics> {
|
|||||||
Ok(book)
|
Ok(book)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Path/command for the HVM binary
|
||||||
|
// CLI option -> Env var -> Default
|
||||||
|
let hvm_bin = if let Some(hvm_bin) = cli.hvm_bin {
|
||||||
|
hvm_bin
|
||||||
|
} else if let Ok(hvm_bin) = std::env::var("HVM_BIN") {
|
||||||
|
hvm_bin
|
||||||
|
} else {
|
||||||
|
"hvm".to_string()
|
||||||
|
};
|
||||||
|
|
||||||
let gen_cmd = match &cli.mode {
|
let gen_cmd = match &cli.mode {
|
||||||
Mode::GenC(..) => "gen-c",
|
Mode::GenC(..) => "gen-c",
|
||||||
Mode::GenCu(..) => "gen-cu",
|
Mode::GenCu(..) => "gen-cu",
|
||||||
@ -293,6 +303,36 @@ fn execute_cli_mode(mut cli: Cli) -> Result<(), Diagnostics> {
|
|||||||
println!("{}", display_hvm_book(&compile_res.hvm_book));
|
println!("{}", display_hvm_book(&compile_res.hvm_book));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Mode::Run(RunArgs { pretty, run_opts, comp_opts, warn_opts, path, arguments })
|
||||||
|
| Mode::RunC(RunArgs { pretty, run_opts, comp_opts, warn_opts, path, arguments })
|
||||||
|
| Mode::RunCu(RunArgs { pretty, run_opts, comp_opts, warn_opts, path, arguments }) => {
|
||||||
|
let CliRunOpts { linear, print_stats } = run_opts;
|
||||||
|
|
||||||
|
let diagnostics_cfg =
|
||||||
|
set_warning_cfg_from_cli(DiagnosticsConfig::new(Severity::Allow, arg_verbose), warn_opts);
|
||||||
|
|
||||||
|
let compile_opts = compile_opts_from_cli(&comp_opts);
|
||||||
|
|
||||||
|
compile_opts.check_for_strict();
|
||||||
|
|
||||||
|
let run_opts = RunOpts { linear_readback: linear, pretty, hvm_path: hvm_bin };
|
||||||
|
|
||||||
|
let book = load_book(&path)?;
|
||||||
|
if let Some((term, stats, diags)) =
|
||||||
|
run_book(book, run_opts, compile_opts, diagnostics_cfg, arguments, run_cmd)?
|
||||||
|
{
|
||||||
|
eprint!("{diags}");
|
||||||
|
if pretty {
|
||||||
|
println!("Result:\n{}", term.display_pretty(0));
|
||||||
|
} else {
|
||||||
|
println!("Result: {}", term);
|
||||||
|
}
|
||||||
|
if print_stats {
|
||||||
|
println!("{stats}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Mode::GenC(GenArgs { comp_opts, warn_opts, path })
|
Mode::GenC(GenArgs { comp_opts, warn_opts, path })
|
||||||
| Mode::GenCu(GenArgs { comp_opts, warn_opts, path }) => {
|
| Mode::GenCu(GenArgs { comp_opts, warn_opts, path }) => {
|
||||||
let diagnostics_cfg = set_warning_cfg_from_cli(DiagnosticsConfig::default(), warn_opts);
|
let diagnostics_cfg = set_warning_cfg_from_cli(DiagnosticsConfig::default(), warn_opts);
|
||||||
@ -306,7 +346,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(cli.hvm_path);
|
let mut process = std::process::Command::new(hvm_bin);
|
||||||
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}"))
|
||||||
};
|
};
|
||||||
@ -340,36 +380,6 @@ fn execute_cli_mode(mut cli: Cli) -> Result<(), Diagnostics> {
|
|||||||
println!("{book}");
|
println!("{book}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Mode::Run(RunArgs { pretty, run_opts, comp_opts, warn_opts, path, arguments })
|
|
||||||
| Mode::RunC(RunArgs { pretty, run_opts, comp_opts, warn_opts, path, arguments })
|
|
||||||
| Mode::RunCu(RunArgs { pretty, run_opts, comp_opts, warn_opts, path, arguments }) => {
|
|
||||||
let CliRunOpts { linear, print_stats } = run_opts;
|
|
||||||
|
|
||||||
let diagnostics_cfg =
|
|
||||||
set_warning_cfg_from_cli(DiagnosticsConfig::new(Severity::Allow, arg_verbose), warn_opts);
|
|
||||||
|
|
||||||
let compile_opts = compile_opts_from_cli(&comp_opts);
|
|
||||||
|
|
||||||
compile_opts.check_for_strict();
|
|
||||||
|
|
||||||
let run_opts = RunOpts { linear_readback: linear, pretty, hvm_path: cli.hvm_path };
|
|
||||||
|
|
||||||
let book = load_book(&path)?;
|
|
||||||
if let Some((term, stats, diags)) =
|
|
||||||
run_book(book, run_opts, compile_opts, diagnostics_cfg, arguments, run_cmd)?
|
|
||||||
{
|
|
||||||
eprint!("{diags}");
|
|
||||||
if pretty {
|
|
||||||
println!("Result:\n{}", term.display_pretty(0));
|
|
||||||
} else {
|
|
||||||
println!("Result: {}", term);
|
|
||||||
}
|
|
||||||
if print_stats {
|
|
||||||
println!("{stats}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
3
tests/golden_tests/cli/custom_hvm_bin.args
Normal file
3
tests/golden_tests/cli/custom_hvm_bin.args
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
run
|
||||||
|
tests/golden_tests/cli/custom_hvm_bin.bend
|
||||||
|
--hvm-bin=hvm
|
1
tests/golden_tests/cli/custom_hvm_bin.bend
Normal file
1
tests/golden_tests/cli/custom_hvm_bin.bend
Normal file
@ -0,0 +1 @@
|
|||||||
|
main = @x x
|
5
tests/snapshots/cli__custom_hvm_bin.bend.snap
Normal file
5
tests/snapshots/cli__custom_hvm_bin.bend.snap
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
source: tests/golden_tests.rs
|
||||||
|
input_file: tests/golden_tests/cli/custom_hvm_bin.bend
|
||||||
|
---
|
||||||
|
Result: λa a
|
Loading…
Reference in New Issue
Block a user