interim commit
This commit is contained in:
77
src/main.rs
77
src/main.rs
@@ -3,6 +3,63 @@ use std::io;
|
|||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
use std::env;
|
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) {
|
fn usage(pname: String) {
|
||||||
println!("usage: {} <file>", pname);
|
println!("usage: {} <file>", pname);
|
||||||
}
|
}
|
||||||
@@ -14,6 +71,13 @@ fn get_contents(fname: String) -> Result<String, io::Error> {
|
|||||||
Ok(contents)
|
Ok(contents)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn parse(contents: String) -> Vec<Exec> {
|
||||||
|
return vec![];
|
||||||
|
}
|
||||||
|
|
||||||
|
fn exec(instructions: Vec<Exec>) {
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let args: Vec<_> = env::args().collect();
|
let args: Vec<_> = env::args().collect();
|
||||||
|
|
||||||
@@ -25,8 +89,15 @@ fn main() {
|
|||||||
let fname = args[1].clone();
|
let fname = args[1].clone();
|
||||||
let contents = get_contents(fname);
|
let contents = get_contents(fname);
|
||||||
|
|
||||||
match contents {
|
let contents = match contents {
|
||||||
Ok(v) => println!("{}", v),
|
Ok(v) => v,
|
||||||
Err(e) => println!("{}", e)
|
Err(e) => {
|
||||||
|
println!("{}", e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let parsed = parse(contents);
|
||||||
|
|
||||||
|
let execd = exec(contents);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user