ast: better representation
This commit is contained in:
66
src/main.rs
66
src/main.rs
@@ -3,61 +3,13 @@ use std::io;
|
|||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
use std::env;
|
use std::env;
|
||||||
|
|
||||||
enum Exec {
|
const EXEC: [(i32, (&'static str, i32)); 1] = [
|
||||||
/*Addition operation*/
|
(0, ("add", 0))
|
||||||
ADD(0, "add"),
|
];
|
||||||
/*Subtraction operation*/
|
|
||||||
SUB(0, "sub"),
|
struct Exec {
|
||||||
/*Multiplication operation*/
|
arguments: i32,
|
||||||
MULT(0, "mult"),
|
name: String
|
||||||
/*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) {
|
||||||
@@ -95,9 +47,9 @@ fn main() {
|
|||||||
println!("{}", e);
|
println!("{}", e);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
let parsed = parse(contents);
|
let parsed = parse(contents);
|
||||||
|
|
||||||
let execd = exec(contents);
|
let execd = exec(parsed);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user