Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test command line #1316

Merged
merged 17 commits into from
Jul 8, 2024
Prev Previous commit
Next Next commit
Fix
  • Loading branch information
raviqqe committed Jul 8, 2024
commit be0ca567ee5fa1f39740c0997a243ea991bab584
14 changes: 11 additions & 3 deletions cmd/run/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

const PRELUDE_SOURCE: &str = include_minified!("prelude.scm");
const COMPILER_PROGRAM: &[u8] = include_r7rs!("compile.scm");
const SCHEME_FILE_EXTENSION: &str = ".scm";

#[derive(Clone, Copy, clap::ValueEnum)]
enum Library {
Expand All @@ -37,7 +38,7 @@
#[command(about, version)]
struct Arguments {
#[arg(required(true))]
files: Vec<PathBuf>,
arguments: Vec<String>,
#[arg(short = 's', long, default_value_t = DEFAULT_HEAP_SIZE)]
heap_size: usize,
#[arg(short, long, default_value = "r7rs")]
Expand All @@ -54,8 +55,15 @@
Library::R7rs => PRELUDE_SOURCE.into(),
};
let mut target = vec![];
let Some(index) = arguments
.arguments
.iter()
.rposition(|argument| argument.ends_with(SCHEME_FILE_EXTENSION))

Check warning on line 61 in cmd/run/src/main.rs

View workflow job for this annotation

GitHub Actions / spell_check

Unknown word (rposition)
else {
return Err("No scheme file specified".into());
};

read_source(&arguments.files, &mut source)?;
read_source(&arguments.arguments[..index], &mut source)?;
compile(&source, &mut target, &mut heap)?;

let mut vm = Vm::new(
Expand All @@ -72,7 +80,7 @@
Ok(vm.run()?)
}

fn read_source(files: &[PathBuf], source: &mut String) -> Result<(), io::Error> {
fn read_source(files: &[String], source: &mut String) -> Result<(), io::Error> {
for file in files {
File::open(file)?.read_to_string(source)?;
}
Expand Down
Loading