mirror of
https://github.com/Noratrieb/brainfuck.git
synced 2026-01-15 22:05:02 +01:00
created react app but not actually started doing anything nice
This commit is contained in:
parent
812e492640
commit
3ee494fed9
39 changed files with 12654 additions and 925 deletions
|
|
@ -1,37 +1,37 @@
|
|||
mod interpreter;
|
||||
mod repl;
|
||||
|
||||
use std::{env, fs};
|
||||
use std::time::SystemTime;
|
||||
use crate::repl::start_repl;
|
||||
use crate::interpreter::optimized::{PrintMode};
|
||||
use std::error::Error;
|
||||
|
||||
|
||||
fn main() {
|
||||
let path = env::args().nth(1);
|
||||
|
||||
match path {
|
||||
Some(p) => {
|
||||
if let Err(why) = run_program(p) {
|
||||
eprintln!("An error occurred in the program: {}", why)
|
||||
}
|
||||
},
|
||||
None => start_repl()
|
||||
};
|
||||
}
|
||||
|
||||
fn run_program(path: String) -> Result<(), Box<dyn Error>> {
|
||||
let program = match fs::read_to_string(path) {
|
||||
Ok(p) => p,
|
||||
Err(e) => {
|
||||
println!("Error reading file: {}", e);
|
||||
return Err(Box::from(e));
|
||||
}
|
||||
};
|
||||
let start_time = SystemTime::now();
|
||||
let out = interpreter::optimized::run(&*program, PrintMode::DirectPrint)?;
|
||||
let duration = start_time.elapsed()?;
|
||||
println!("{}\nFinished execution. Took {}ms", out, duration.as_millis());
|
||||
Ok(())
|
||||
mod interpreter;
|
||||
mod repl;
|
||||
|
||||
use std::{env, fs};
|
||||
use std::time::SystemTime;
|
||||
use crate::repl::start_repl;
|
||||
use crate::interpreter::optimized::{PrintMode};
|
||||
use std::error::Error;
|
||||
|
||||
|
||||
fn main() {
|
||||
let path = env::args().nth(1);
|
||||
|
||||
match path {
|
||||
Some(p) => {
|
||||
if let Err(why) = run_program(p) {
|
||||
eprintln!("An error occurred in the program: {}", why)
|
||||
}
|
||||
},
|
||||
None => start_repl()
|
||||
};
|
||||
}
|
||||
|
||||
fn run_program(path: String) -> Result<(), Box<dyn Error>> {
|
||||
let program = match fs::read_to_string(path) {
|
||||
Ok(p) => p,
|
||||
Err(e) => {
|
||||
println!("Error reading file: {}", e);
|
||||
return Err(Box::from(e));
|
||||
}
|
||||
};
|
||||
let start_time = SystemTime::now();
|
||||
let out = interpreter::optimized::run(&*program, PrintMode::DirectPrint)?;
|
||||
let duration = start_time.elapsed()?;
|
||||
println!("{}\nFinished execution. Took {}ms", out, duration.as_millis());
|
||||
Ok(())
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue