add context

This commit is contained in:
2020-05-06 00:30:57 +08:00
parent 42826cc78f
commit 2c4f15ada1
3 changed files with 31 additions and 2 deletions

21
src/context.rs Normal file
View 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(),
}
}
}

View File

@@ -1,5 +1,4 @@
#[derive(Debug)]
pub enum InsId {
Push, // has data

View File

@@ -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> {