Skip to content

Commit

Permalink
Merge pull request #19 from calcit-lang/argh
Browse files Browse the repository at this point in the history
switch to argh
  • Loading branch information
NoEgAm authored Jul 23, 2024
2 parents 11aae3c + fa73489 commit dadbc96
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 20 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ on:
push:
branches:
- master
- main
pull_request: {}

name: Test
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ Cargo.lock


profile.json

.DS_Store
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ path = "src/bin/cli.rs"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
cirru_parser = "0.1.28"
regex = "1.10.2"
lazy_static = "1.4.0"
clap = { version = "4.4.18", features = ["derive"] }
cirru_parser = "0.1.31"
regex = "1.10.5"
lazy_static = "1.5.0"
bincode = "2.0.0-rc.3"
argh = "0.1.12"

# [target.'cfg(not(target_env = "msvc"))'.dependencies]
# tikv-jemallocator = "0.5"
Expand Down
29 changes: 15 additions & 14 deletions src/bin/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use std::fs;
use std::time::Instant;
use std::{collections::hash_map::HashMap, rc::Rc};

use argh::FromArgs;
use cirru_parser::{parse, Cirru};
use clap::{arg, Parser};

use calx_vm::{log_calx_value, parse_function, Calx, CalxFunc, CalxImportsDict, CalxVM};

Expand All @@ -23,27 +23,28 @@ pub struct CalxBinaryProgram {
pub fns: Vec<CalxFunc>,
}

/// Simple program to greet a person
#[derive(Parser, Debug)]
#[command(name = "Calx VM")]
#[command(author = "Jon Chen <[email protected]>")]
#[command(version = "0.1.6")]
#[command(about = "A toy VM", long_about = None)]
struct Args {
#[arg(short, long, value_name = "SHOW_CODE")]
#[derive(FromArgs)]
/// Calx VM args
struct TopLevel {
/// show code
#[argh(switch, short = 's')]
show_code: bool,
#[arg(short, long, value_name = "EMIT_BINARY")]
/// emit binary
#[argh(option, short = 'b')]
emit_binary: Option<String>,
#[arg(short, long, value_name = "VERBOSE")]
/// verbose
#[argh(switch, short = 'v')]
verbose: bool,
#[arg(long, value_name = "EVAL_BINARY")]
/// eval binary
#[argh(switch, short = 'e')]
eval_binary: bool,
#[arg(value_name = "SOURCE")]
/// source
#[argh(positional)]
source: String,
}

fn main() -> Result<(), String> {
let args = Args::parse();
let args: TopLevel = argh::from_env();

let source = args.source;
let show_code = args.show_code;
Expand Down
2 changes: 1 addition & 1 deletion src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub fn parse_function(nodes: &[Cirru]) -> Result<CalxFunc, String> {
}

Ok(CalxFunc {
name: Rc::from(name),
name,
params_types: params_types.into(),
ret_types: Rc::new(ret_types),
local_names: Rc::new(locals_collector.locals),
Expand Down
2 changes: 1 addition & 1 deletion src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ impl CalxVM {
if *idx >= self.top_frame.locals.len() {
return Err(self.gen_err(format!("out of bound in local.tee {}", idx)));
} else {
self.top_frame.locals[*idx] = v.to_owned()
v.clone_into(&mut self.top_frame.locals[*idx])
}
self.stack_push(v);
}
Expand Down

0 comments on commit dadbc96

Please sign in to comment.