Iterate through program
This commit is contained in:
parent
dc4efa3aa6
commit
15aa810564
14
src/main.rs
14
src/main.rs
|
@ -1,10 +1,11 @@
|
|||
use std::fs;
|
||||
use std::env;
|
||||
use std::fmt;
|
||||
use std::usize;
|
||||
|
||||
struct Program {
|
||||
data: Vec<String>,
|
||||
pc: u32
|
||||
pc: usize
|
||||
}
|
||||
|
||||
impl Program {
|
||||
|
@ -22,8 +23,15 @@ impl Program {
|
|||
return Program{ data: op_list, pc: 0 };
|
||||
}
|
||||
|
||||
fn run(&self) {
|
||||
fn run(&mut self) {
|
||||
println!("{}", self);
|
||||
while self.pc < self.data.len() {
|
||||
println!("PC is {}", self.pc);
|
||||
let opcode = &self.data[self.pc];
|
||||
|
||||
|
||||
self.pc = self.pc + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -43,6 +51,6 @@ fn main() {
|
|||
let filename = &args[1];
|
||||
|
||||
let contents = fs::read_to_string(filename).expect("Something went wrong reading the file");
|
||||
let prog = Program::from_string(contents);
|
||||
let mut prog = Program::from_string(contents);
|
||||
prog.run();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue