mirror of
https://github.com/Noratrieb/brainfuck.git
synced 2026-01-15 13:55:02 +01:00
spans and tests
This commit is contained in:
parent
e82b14b09a
commit
5634330287
10 changed files with 300 additions and 112 deletions
|
|
@ -1,11 +1,8 @@
|
|||
#![feature(allocator_api, let_else)]
|
||||
#![warn(rust_2018_idioms)]
|
||||
|
||||
use bumpalo::Bump;
|
||||
use std::{env, fs, io, process};
|
||||
|
||||
use brainfuck::{ir_interpreter, opts, parse};
|
||||
|
||||
fn main() {
|
||||
let Some(path) = env::args().nth(1) else {
|
||||
eprintln!("error: Provide a path as input.");
|
||||
|
|
@ -17,24 +14,13 @@ fn main() {
|
|||
process::exit(1);
|
||||
});
|
||||
|
||||
let ast_alloc = Bump::new();
|
||||
|
||||
let parsed = parse::parse(&ast_alloc, file.bytes()).unwrap_or_else(|_| {
|
||||
eprintln!("Failed to parse brainfuck code.");
|
||||
process::exit(1);
|
||||
});
|
||||
|
||||
let ir_alloc = Bump::new();
|
||||
|
||||
let optimized_ir = opts::optimize(&ir_alloc, &parsed);
|
||||
|
||||
drop(parsed);
|
||||
drop(ast_alloc);
|
||||
|
||||
let stdout = io::stdout();
|
||||
let stdout = stdout.lock();
|
||||
let stdin = io::stdin();
|
||||
let stdin = stdin.lock();
|
||||
|
||||
ir_interpreter::run(&optimized_ir, stdout, stdin);
|
||||
brainfuck::run(file.bytes(), stdout, stdin).unwrap_or_else(|_| {
|
||||
eprintln!("error: Failed to parse brainfuck code");
|
||||
process::exit(1);
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue