interim commit

This commit is contained in:
2017-05-23 20:21:29 -04:00
parent 6f1f3b8a94
commit 2e54e59d63

View File

@@ -3,6 +3,63 @@ use std::io;
use std::io::Read;
use std::env;
enum Exec {
/*Addition operation*/
ADD(0, "add"),
/*Subtraction operation*/
SUB(0, "sub"),
/*Multiplication operation*/
MULT(0, "mult"),
/*Division operation*/
DIV(0, "div"),
/*Modulo operation*/
MOD(0, "mod"),
/*< operation*/
LT(0, "lt"),
/*== operation*/
EQ(0, "eq"),
/*> operation*/
GT(0, "gt"),
/*branch operation*/
BR(1, "br"),
/*branch if true operation*/
BRT(1, "brt"),
/*branch if false operation*/
BRF(1, "brf"),
/*put operation*/
CONST(1, "const"),
/*load variable operation*/
LOAD(1, "load"),
/*load global variable operation*/
GLOAD(1, "gload"),
/*store variable operation*/
STORE(1, "store"),
/*store global variable operation*/
GSTORE(1, "gstore"),
/*print operation*/
PRINT(0, "print"),
/*pop operation*/
POP(0, "pop"),
/*end/halt operation*/
HALT(0, "halt"),
/*<= operation*/
LEQ(0, "leq"),
/*>= operation*/
GEQ(0, "geq"),
/*call subroutine operation*/
CALL(2, "call"),
/*return from subroutine operation*/
RET(0, "ret"),
/*print integer operation*/
IPRINT(0, "iprint"),
/*fetch operation*/
FETCH(0, "fetch"),
/*++ operation*/
INC(0, "inc"),
/*-- operation*/
DEC(0, "dec")
}
fn usage(pname: String) {
println!("usage: {} <file>", pname);
}
@@ -14,6 +71,13 @@ fn get_contents(fname: String) -> Result<String, io::Error> {
Ok(contents)
}
fn parse(contents: String) -> Vec<Exec> {
return vec![];
}
fn exec(instructions: Vec<Exec>) {
}
fn main() {
let args: Vec<_> = env::args().collect();
@@ -25,8 +89,15 @@ fn main() {
let fname = args[1].clone();
let contents = get_contents(fname);
match contents {
Ok(v) => println!("{}", v),
Err(e) => println!("{}", e)
let contents = match contents {
Ok(v) => v,
Err(e) => {
println!("{}", e);
return;
}
}
let parsed = parse(contents);
let execd = exec(contents);
}