Skip to content

Commit

Permalink
upgrade deps; update clap; tag 0.1.5
Browse files Browse the repository at this point in the history
  • Loading branch information
tiye committed Jan 6, 2024
1 parent 4324377 commit 258c197
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 75 deletions.
18 changes: 10 additions & 8 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
26 changes: 11 additions & 15 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[package]
name = "calx_vm"
version = "0.1.4"
version = "0.1.5"
authors = ["jiyinyiyong <[email protected]>"]
edition = "2018"
edition = "2021"
license = "MIT"
description = "Stack-based VM, with dynamic data, for experiment"
homepage = "https://github.com/calcit-lang/calx-vm"
Expand All @@ -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
74 changes: 29 additions & 45 deletions src/bin/calx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>")]
#[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<String>,
#[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 <[email protected]>")
.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<CalxFunc> = vec![];

Expand Down Expand Up @@ -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(),
Expand All @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ fn parse_type_name(x: &str) -> Result<CalxType, String> {
pub fn extract_nested(xs: &Cirru) -> Result<Vec<Cirru>, 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 {
Expand Down

0 comments on commit 258c197

Please sign in to comment.