add context
This commit is contained in:
21
src/context.rs
Normal file
21
src/context.rs
Normal file
@@ -0,0 +1,21 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Context {
|
||||
ptr: isize,
|
||||
stack: Vec<isize>,
|
||||
label_map: HashMap<isize, isize>,
|
||||
mem_map: HashMap<isize, isize>,
|
||||
}
|
||||
|
||||
impl Context {
|
||||
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
ptr: 0,
|
||||
stack: vec![],
|
||||
label_map: HashMap::new(),
|
||||
mem_map: HashMap::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum InsId {
|
||||
Push, // has data
|
||||
|
||||
11
src/main.rs
11
src/main.rs
@@ -1,8 +1,10 @@
|
||||
mod err;
|
||||
mod ins;
|
||||
mod context;
|
||||
|
||||
use err::*;
|
||||
use ins::*;
|
||||
use context::*;
|
||||
|
||||
const VALID_INSTRUCTION_CHARS: &str = "草泥马河蟹";
|
||||
|
||||
@@ -11,7 +13,14 @@ const VALID_INSTRUCTION_CHARS: &str = "草泥马河蟹";
|
||||
fn main() {
|
||||
let input = "草草草泥马 马草草草泥草草草草泥泥马 草马草 泥马草泥 草草草泥草泥草马 泥马草草 草草草泥马 泥草草草 草马草 草草草泥草泥泥马 泥草草泥 马泥草草泥草草草泥草泥马 马草马草泥草草草草泥泥马 马草草草泥草草草泥草泥马 草马马 马马马";
|
||||
|
||||
parse_lang(input).ok();
|
||||
let _instructions = match parse_lang(input) {
|
||||
Ok(i) => i, Err(err) => {
|
||||
println!("Parse error: {}", err);
|
||||
return;
|
||||
},
|
||||
};
|
||||
|
||||
let _context = Context::new();
|
||||
}
|
||||
|
||||
fn parse_lang(lang: &str) -> Result<Vec<Instruction>, ParseError> {
|
||||
|
||||
Reference in New Issue
Block a user