Skip to content

Commit

Permalink
Merge pull request #440 from 0xKanekiKen/repl-tool
Browse files Browse the repository at this point in the history
Implement Repl tool in Miden VM
  • Loading branch information
bobbinth authored Nov 2, 2022
2 parents f8caf1a + 7d33dcb commit 4553652
Show file tree
Hide file tree
Showing 6 changed files with 353 additions and 8 deletions.
3 changes: 2 additions & 1 deletion miden/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@ doctest = false
[features]
concurrent = ["prover/concurrent", "std"]
default = ["std"]
executable = ["crypto", "env_logger", "hex/std", "std", "serde/std", "serde_derive", "serde_json/std", "structopt", "winter-utils"]
executable = ["crypto", "env_logger", "hex/std", "std", "serde/std", "serde_derive", "serde_json/std", "structopt", "winter-utils", "rustyline"]
std = ["air/std", "assembly/std", "log/std", "processor/std", "prover/std", "verifier/std", "vm-core/std"]

[dependencies]
air = { package = "miden-air", path = "../air", version = "0.3", default-features = false }
assembly = { package = "miden-assembly", path = "../assembly", version = "0.3", default-features = false }
crypto = { package = "winter-crypto", version = "0.4", default-features = false, optional = true }
rustyline = { version = "10.0.0", default-features = false, optional = true}
env_logger = { version = "0.9", default-features = false, optional = true }
hex = { version = "0.4", optional = true }
log = { version = "0.4", default-features = false }
Expand Down
2 changes: 2 additions & 0 deletions miden/src/cli/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
mod compile;
mod data;
mod prove;
mod repl;
mod run;
mod verify;

pub use compile::CompileCmd;
pub use data::InputFile;
pub use prove::ProveCmd;
pub use repl::ReplCmd;
pub use run::RunCmd;
pub use verify::VerifyCmd;
7 changes: 7 additions & 0 deletions miden/src/cli/prove.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use super::data::{InputFile, OutputFile, ProgramFile, ProofFile};
use air::ProofOptions;
use crypto::Digest;
use std::io::Write;
use std::path::PathBuf;
use std::time::Instant;
use structopt::StructOpt;
Expand Down Expand Up @@ -42,6 +43,12 @@ impl ProveCmd {
println!("Prove program");
println!("============================================================");

// configure logging
env_logger::Builder::new()
.format(|buf, record| writeln!(buf, "{}", record.args()))
.filter_level(log::LevelFilter::Debug)
.init();

// load program from file and compile
let program = ProgramFile::read(&self.assembly_file)?;

Expand Down
14 changes: 14 additions & 0 deletions miden/src/cli/repl.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use crate::repl::start_repl;
use structopt::StructOpt;

#[derive(StructOpt, Debug)]
#[structopt(name = "Repl", about = "Initiates the Miden REPL tool")]
pub struct ReplCmd {}

impl ReplCmd {
pub fn execute(&self) -> Result<(), String> {
// initiates repl tool.
start_repl();
Ok(())
}
}
12 changes: 5 additions & 7 deletions miden/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::io::Write;
use structopt::StructOpt;

mod cli;
mod examples;
mod repl;
mod tools;

/// Root CLI struct
Expand All @@ -22,6 +22,8 @@ pub enum Actions {
Prove(cli::ProveCmd),
Run(cli::RunCmd),
Verify(cli::VerifyCmd),
#[cfg(feature = "std")]
Repl(cli::ReplCmd),
}

/// CLI entry point
Expand All @@ -34,18 +36,14 @@ impl Cli {
Actions::Prove(prove) => prove.execute(),
Actions::Run(run) => run.execute(),
Actions::Verify(verify) => verify.execute(),
#[cfg(feature = "std")]
Actions::Repl(repl) => repl.execute(),
}
}
}

/// Executable entry point
pub fn main() {
// configure logging
env_logger::Builder::new()
.format(|buf, record| writeln!(buf, "{}", record.args()))
.filter_level(log::LevelFilter::Debug)
.init();

// read command-line args
let cli = Cli::from_args();

Expand Down
Loading

0 comments on commit 4553652

Please sign in to comment.