-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
upgrade deps; update clap; tag 0.1.5
- Loading branch information
Showing
5 changed files
with
57 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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![]; | ||
|
||
|
@@ -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), | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters