mirror of
https://github.com/kaesaecracker/echse.git
synced 2025-09-04 15:07:16 +02:00
initial commit
This commit is contained in:
commit
5ad6baa30d
35 changed files with 2877 additions and 0 deletions
8
echse_cute/Cargo.toml
Normal file
8
echse_cute/Cargo.toml
Normal file
|
@ -0,0 +1,8 @@
|
|||
[package]
|
||||
name = "echse_cute"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
clap.workspace = true
|
||||
echse = { path = "../echse" }
|
43
echse_cute/src/main.rs
Normal file
43
echse_cute/src/main.rs
Normal file
|
@ -0,0 +1,43 @@
|
|||
use echse::machine::MachineBuilder;
|
||||
use echse::parser::EiParser;
|
||||
|
||||
#[derive(clap::Parser)]
|
||||
#[command(version, about, long_about = None)]
|
||||
struct Cli {
|
||||
ei_file: String,
|
||||
#[arg(short, long, default_value_t = 2)]
|
||||
registers: usize,
|
||||
#[arg(short, long, default_value_t = false)]
|
||||
verbose: bool,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let args: Cli = clap::Parser::parse();
|
||||
|
||||
let parser = EiParser::from_file(&args.ei_file).unwrap();
|
||||
let instructions = match parser.parse() {
|
||||
Ok(i) => i,
|
||||
Err(e) => {
|
||||
parser
|
||||
.write_error_report(e, &mut std::io::stderr())
|
||||
.expect("failed to generate error report");
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
let mut machine = MachineBuilder::new()
|
||||
.with_registers(args.registers)
|
||||
.with_instructions(instructions)
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
println!("done building machine: \n{machine}");
|
||||
|
||||
while machine.step() {
|
||||
if args.verbose {
|
||||
println!("executed instruction: {machine:?}");
|
||||
}
|
||||
}
|
||||
|
||||
println!("final state: \n{machine}");
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue