mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 06:14:46 +00:00
wasm_interp: pass arguments from CLI
This commit is contained in:
parent
fa1e0a8614
commit
a09fd95fd7
6 changed files with 92 additions and 36 deletions
|
@ -1,4 +1,5 @@
|
|||
use bumpalo::Bump;
|
||||
use clap::parser::ValuesRef;
|
||||
use clap::ArgAction;
|
||||
use clap::{Arg, Command};
|
||||
use roc_wasm_interp::Action;
|
||||
|
@ -14,6 +15,7 @@ pub const FLAG_FUNCTION: &str = "function";
|
|||
pub const FLAG_DEBUG: &str = "debug";
|
||||
pub const FLAG_HEX: &str = "hex";
|
||||
pub const WASM_FILE: &str = "WASM_FILE";
|
||||
pub const ARGS_FOR_APP: &str = "ARGS_FOR_APP";
|
||||
|
||||
fn main() -> io::Result<()> {
|
||||
// Define the command line arguments
|
||||
|
@ -41,12 +43,20 @@ fn main() -> io::Result<()> {
|
|||
.allow_invalid_utf8(true)
|
||||
.required(true);
|
||||
|
||||
let args_for_app = Arg::new(ARGS_FOR_APP)
|
||||
.help("Arguments to pass into the WebAssembly app\ne.g. `roc_wasm_interp app.wasm -- 123 123.45`")
|
||||
.multiple_values(true)
|
||||
.takes_value(true)
|
||||
.last(true);
|
||||
|
||||
let app = Command::new("roc_wasm_interp")
|
||||
.about("Run the given .wasm file")
|
||||
.arg(flag_function)
|
||||
.arg(flag_debug)
|
||||
.arg(flag_hex)
|
||||
.arg(wasm_file_to_run);
|
||||
.arg(wasm_file_to_run)
|
||||
.trailing_var_arg(true)
|
||||
.arg(args_for_app);
|
||||
|
||||
// Parse the command line arguments
|
||||
|
||||
|
@ -54,6 +64,10 @@ fn main() -> io::Result<()> {
|
|||
let start_fn_name = matches.get_one::<String>(FLAG_FUNCTION).unwrap();
|
||||
let is_debug_mode = matches.get_flag(FLAG_DEBUG);
|
||||
let is_hex_format = matches.get_flag(FLAG_HEX);
|
||||
let start_arg_strings = matches
|
||||
.get_many::<String>(ARGS_FOR_APP)
|
||||
.unwrap_or(ValuesRef::default())
|
||||
.map(|s| s.as_str());
|
||||
|
||||
// Load the WebAssembly binary file
|
||||
|
||||
|
@ -76,11 +90,17 @@ fn main() -> io::Result<()> {
|
|||
|
||||
// Initialise the execution state
|
||||
|
||||
let mut state = ExecutionState::for_module(&arena, &module, start_fn_name, is_debug_mode)
|
||||
.unwrap_or_else(|e| {
|
||||
eprintln!("{}", e);
|
||||
process::exit(2);
|
||||
});
|
||||
let mut state = ExecutionState::for_module(
|
||||
&arena,
|
||||
&module,
|
||||
start_fn_name,
|
||||
is_debug_mode,
|
||||
start_arg_strings,
|
||||
)
|
||||
.unwrap_or_else(|e| {
|
||||
eprintln!("{}", e);
|
||||
process::exit(2);
|
||||
});
|
||||
|
||||
// Run
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue