diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index b5f970e..b0a1889 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -9,16 +9,18 @@ jobs: name: Publish to cargo runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 + - uses: actions/checkout@v4 + + - uses: dtolnay/rust-toolchain@stable with: - toolchain: stable + toolchain: nightly + components: clippy - - run: cargo run -- -S examples/hello.cirru - - run: cargo run -- -S examples/sum.cirru - - run: cargo run -- -S examples/assert.cirru - - run: cargo run -- -S examples/nested.cirru - - run: cargo run -- -S examples/named.cirru + - run: cargo run -- -s examples/hello.cirru + - run: cargo run -- -s examples/sum.cirru + - run: cargo run -- -s examples/assert.cirru + - run: cargo run -- -s examples/nested.cirru + - run: cargo run -- -s examples/named.cirru - run: cargo run -- examples/recur.cirru - run: cargo run -- --emit-binary target/a.calx examples/named.cirru && cargo run -- --eval-binary target/a.calx diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 995b422..d71f498 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -17,27 +17,23 @@ jobs: pull-requests: write steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 + - uses: actions/checkout@v4 + + - uses: dtolnay/rust-toolchain@stable with: toolchain: nightly components: clippy - override: true - - run: cargo run -- -S examples/hello.cirru - - run: cargo run -- -S examples/sum.cirru - - run: cargo run -- -S examples/assert.cirru - - run: cargo run -- -S examples/nested.cirru - - run: cargo run -- -S examples/named.cirru + - run: cargo run -- -s examples/hello.cirru + - run: cargo run -- -s examples/sum.cirru + - run: cargo run -- -s examples/assert.cirru + - run: cargo run -- -s examples/nested.cirru + - run: cargo run -- -s examples/named.cirru - run: cargo run -- examples/recur.cirru - run: cargo run -- --emit-binary target/a.calx examples/named.cirru && cargo run -- --eval-binary target/a.calx - - uses: actions-rs/clippy-check@v1 + - uses: giraffate/clippy-action@v1 with: - token: ${{ secrets.GITHUB_TOKEN }} - args: --all-features + reporter: 'github-pr-review' + github_token: ${{ secrets.GITHUB_TOKEN }} - - uses: actions-rs/clippy-check@v1 - with: - token: ${{ secrets.GITHUB_TOKEN }} - args: --all-features diff --git a/Cargo.toml b/Cargo.toml index 8bf22b4..0f75a7b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,8 +1,8 @@ [package] name = "calx_vm" -version = "0.1.4" +version = "0.1.5" authors = ["jiyinyiyong "] -edition = "2018" +edition = "2021" license = "MIT" description = "Stack-based VM, with dynamic data, for experiment" homepage = "https://github.com/calcit-lang/calx-vm" @@ -16,11 +16,11 @@ exclude = [ # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -cirru_parser = "0.1.23" -regex = "1.6.0" +cirru_parser = "0.1.25" +regex = "1.10.2" lazy_static = "1.4.0" -clap = "3.2.12" -bincode = "2.0.0-rc.1" +clap = { version = "4.4.13", features = ["derive"] } +bincode = "2.0.0-rc.3" [profile.release] debug = true diff --git a/src/bin/calx.rs b/src/bin/calx.rs index d73244d..3f5e128 100644 --- a/src/bin/calx.rs +++ b/src/bin/calx.rs @@ -3,53 +3,37 @@ use std::fs; use std::time::Instant; use cirru_parser::{parse, Cirru}; -use clap::{Arg, Command}; +use clap::{arg, Parser}; use calx_vm::{log_calx_value, parse_function, Calx, CalxBinaryProgram, CalxFunc, CalxImportsDict, CalxVM, CALX_BINARY_EDITION}; +/// Simple program to greet a person +#[derive(Parser, Debug)] +#[command(name = "Calx VM")] +#[command(author = "Jon Chen ")] +#[command(version = "0.1.4")] +#[command(about = "A toy VM", long_about = None)] +struct Args { + #[arg(short, long, value_name = "SHOW_CODE")] + show_code: bool, + #[arg(short, long, value_name = "DISABLE_PRE")] + disable_pre: bool, + #[arg(short, long, value_name = "EMIT_BINARY")] + emit_binary: Option, + #[arg(long, value_name = "EVAL_BINARY")] + eval_binary: bool, + #[arg(value_name = "SOURCE")] + source: String, +} + fn main() -> Result<(), String> { - let matches = Command::new("Calx VM") - .version("0.1.0") - .author("Jon Chen ") - .about("A toy VM") - .arg( - Arg::new("SHOW_CODE") - .short('S') - .long("show-code") - .value_name("show-code") - .help("display processed instructions of functions") - .takes_value(false), - ) - .arg( - Arg::new("DISABLE_PRE") - .short('D') - .long("disable-pre") - .value_name("disable-pre") - .help("disabled preprocess") - .takes_value(false), - ) - .arg( - Arg::new("EMIT_BINARY") - .long("emit-binary") - .value_name("emit-binary") - .help("emit binary, rather than running") - .takes_value(true), - ) - .arg( - Arg::new("EVALUATE_BINARY") - .long("eval-binary") - .value_name("eval-binary") - .help("evaluate program from binary") - .takes_value(false), - ) - .arg(Arg::new("SOURCE").help("A *.cirru file for loading code").required(true).index(1)) - .get_matches(); - - let source = matches.value_of("SOURCE").unwrap(); - let show_code = matches.is_present("SHOW_CODE"); - let disable_pre = matches.is_present("DISABLE_PRE"); - let emit_binary = matches.is_present("EMIT_BINARY"); - let eval_binary = matches.is_present("EVALUATE_BINARY"); + let args = Args::parse(); + + let source = args.source; + let show_code = args.show_code; + let disable_pre = args.disable_pre; + let emit_binary = args.emit_binary; + let eval_binary = args.eval_binary; let mut fns: Vec = vec![]; @@ -81,7 +65,7 @@ fn main() -> Result<(), String> { } } - if emit_binary { + if emit_binary.is_some() { let mut slice = [0u8; 10000]; let program = CalxBinaryProgram { edition: CALX_BINARY_EDITION.to_string(), @@ -95,7 +79,7 @@ fn main() -> Result<(), String> { Err(e) => panic!("failed on default length of 10000: {}", e), }; let slice = &slice[..length]; - let target_file = matches.value_of("EMIT_BINARY").unwrap(); + let target_file = &emit_binary.unwrap(); match fs::write(target_file, slice) { Ok(_) => println!("wrote binary to {}", target_file), Err(e) => panic!("failed to write binary to {}: {}", target_file, e), diff --git a/src/parser.rs b/src/parser.rs index 2ee7230..68f10c0 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -451,7 +451,7 @@ fn parse_type_name(x: &str) -> Result { pub fn extract_nested(xs: &Cirru) -> Result, String> { match xs { Cirru::Leaf(x) => Err(format!("not extracting leaf: {}", x)), - Cirru::List(ys) => match ys.get(0) { + Cirru::List(ys) => match ys.first() { None => Err(String::from("unexpected empty expression")), Some(Cirru::List(zs)) => Err(format!("unexpected nested instruction name: {:?}", zs)), Some(Cirru::Leaf(zs)) => match &**zs {