Skip to content

Commit

Permalink
release(cli): v0.15.0
Browse files Browse the repository at this point in the history
  • Loading branch information
SaadiSave committed May 5, 2023
1 parent a58f2c4 commit e9b6e92
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
5 changes: 3 additions & 2 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cambridge-asm-cli"
version = "0.14.0"
version = "0.15.0"
authors = ["SaadiSave <https://github.com/SaadiSave>"]
edition = "2021"
license = "MPL-2.0"
Expand All @@ -21,9 +21,10 @@ serde_json = "1"
ron = "0.7"
serde_yaml = "0.8"
bincode = "2.0.0-rc.1"
anyhow = "1"

[dependencies.cambridge-asm]
version = "0.15"
version = "0.18"
default-features = false
features = ["compile"]

Expand Down
35 changes: 20 additions & 15 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use std::ffi::OsString;

#[derive(Parser)]
#[clap(name = "Cambridge Pseudoassembly Interpreter")]
#[clap(version = env!("CARGO_PKG_VERSION"))]
#[clap(version = concat!(env!("CARGO_PKG_VERSION"), "\n", "Library version 0.18.0"))]
#[clap(author = "Saadi Save <github.com/SaadiSave>")]
#[clap(about = "Run pseudoassembly from Cambridge International syllabus 9618 (2021)")]
enum Commands {
Expand Down Expand Up @@ -60,6 +60,10 @@ enum Commands {
/// Minify output
#[clap(short = 'm', long = "minify")]
minify: bool,

/// Include debuginfo
#[clap(short, long)]
debug: bool,
},
}

Expand All @@ -80,7 +84,7 @@ enum OutFormats {
Bin,
}

fn main() -> std::io::Result<()> {
fn main() -> anyhow::Result<()> {
#[cfg(not(debug_assertions))]
std::panic::set_hook(Box::new(handle_panic));

Expand All @@ -101,7 +105,8 @@ fn main() -> std::io::Result<()> {
verbosity,
format,
minify,
} => compile(input, output, verbosity, format, minify)?,
debug,
} => compile(input, output, verbosity, format, minify, debug)?,
}

Ok(())
Expand All @@ -114,7 +119,7 @@ fn run(
bench: bool,
format: InFormats,
io: Io,
) -> std::io::Result<()> {
) -> anyhow::Result<()> {
use InFormats::*;

init_logger(verbosity);
Expand All @@ -124,19 +129,15 @@ fn run(
let mut timer = bench.then(std::time::Instant::now);

let mut executor = match format {
Pasm => parse::jit::<DefaultSet, _>(String::from_utf8_lossy(&prog_bytes), io),
Json => serde_json::from_str::<CompiledProg>(&String::from_utf8_lossy(&prog_bytes))
.unwrap()
Pasm => parse::jit::<DefaultSet>(String::from_utf8_lossy(&prog_bytes), io).unwrap(),
Json => serde_json::from_str::<CompiledProg>(&String::from_utf8_lossy(&prog_bytes))?
.to_executor::<DefaultSet>(io),
Ron => ron::from_str::<CompiledProg>(&String::from_utf8_lossy(&prog_bytes))
.unwrap()
Ron => ron::from_str::<CompiledProg>(&String::from_utf8_lossy(&prog_bytes))?
.to_executor::<DefaultSet>(io),
Yaml => serde_yaml::from_str::<CompiledProg>(&String::from_utf8_lossy(&prog_bytes))
.unwrap()
Yaml => serde_yaml::from_str::<CompiledProg>(&String::from_utf8_lossy(&prog_bytes))?
.to_executor::<DefaultSet>(io),
Bin => {
bincode::decode_from_slice::<CompiledProg, _>(&prog_bytes, bincode::config::standard())
.unwrap()
bincode::decode_from_slice::<CompiledProg, _>(&prog_bytes, bincode::config::standard())?
.0
.to_executor::<DefaultSet>(io)
}
Expand All @@ -146,13 +147,16 @@ fn run(
println!("Total parse time: {:?}", t.elapsed());
std::time::Instant::now()
});

if timer.is_some() || verbosity > 0 {
println!("Execution starts on next line");
}

executor.exec::<DefaultSet>();

let _ = timer.map(|t| println!("Execution done\nExecution time: {:?}", t.elapsed()));
if let Some(t) = timer {
println!("Execution done\nExecution time: {:?}", t.elapsed());
}

Ok(())
}
Expand All @@ -164,14 +168,15 @@ fn compile(
verbosity: usize,
format: OutFormats,
minify: bool,
debug: bool,
) -> std::io::Result<()> {
use OutFormats::*;

init_logger(verbosity);

let prog = std::fs::read_to_string(&input)?;

let compiled = compile::compile::<DefaultSet, _>(prog);
let compiled = compile::compile::<DefaultSet>(prog, debug).unwrap();

let output_path = output.unwrap_or_else(|| {
input.push(match format {
Expand Down

0 comments on commit e9b6e92

Please sign in to comment.