Skip to content

Commit

Permalink
Merge branch 'main' into clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
tcoratger authored Nov 6, 2024
2 parents b82ad41 + 0a4fb78 commit a7f3e30
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
8 changes: 4 additions & 4 deletions crates/brainfuck_vm/src/bin/brainfuck_vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use std::{
io::{stdin, stdout},
path::PathBuf,
};
use tracing_subscriber::{fmt, EnvFilter};

use brainfuck_vm::{compiler::Compiler, machine::Machine};

Expand All @@ -15,6 +14,8 @@ use brainfuck_vm::{compiler::Compiler, machine::Machine};
struct Args {
#[clap(value_parser, value_hint=ValueHint::FilePath)]
filename: PathBuf,
#[clap(long, default_value = "info")]
log: String,
#[clap(long)]
trace: bool,
#[clap(long)]
Expand All @@ -26,10 +27,9 @@ struct Args {
fn main() {
let args = Args::parse();

// Constructs a subscriber whose severity level is filtered by `RUST_LOG`
fmt().with_env_filter(EnvFilter::from_default_env()).init();
tracing_subscriber::fmt().with_env_filter(args.log).init();

let code = fs::read_to_string(&args.filename).expect("Failed to read file").replace(' ', "");
let code = fs::read_to_string(&args.filename).expect("Failed to read file");
let mut bf_compiler = Compiler::new(&code);
let ins = bf_compiler.compile();
tracing::info!("Assembled instructions: {:?}", ins.iter().map(|x| x.0).collect::<Vec<u32>>());
Expand Down
11 changes: 10 additions & 1 deletion crates/brainfuck_vm/src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,16 @@ mod tests {
let compiler = Compiler::new(code);
let expected_trimmed_code =
vec!['+', '+', '>', ',', '<', '[', '>', '+', '.', '<', '-', ']'];
assert_eq!(expected_trimmed_code, compiler.code,);
assert_eq!(expected_trimmed_code, compiler.code);
}

#[test]
fn test_whitespace() {
let code = " + +> , < [> + .< - ] ".to_string();
let compiler = Compiler::new(code);
let expected_trimmed_code =
vec!['+', '+', '>', ',', '<', '[', '>', '+', '.', '<', '-', ']'];
assert_eq!(expected_trimmed_code, compiler.code);
}

#[test]
Expand Down

0 comments on commit a7f3e30

Please sign in to comment.