Iterate through program

This commit is contained in:
Yash 2021-02-03 15:54:13 -06:00
parent dc4efa3aa6
commit 15aa810564
No known key found for this signature in database
GPG Key ID: A794DA2529474BA5
1 changed files with 11 additions and 3 deletions

View File

@ -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();
}