Skip to content
Snippets Groups Projects
Commit 320141f0 authored by Per Lindgren's avatar Per Lindgren
Browse files

initial commit wip1

parent 67464efd
Branches
Tags
No related merge requests found
......@@ -33,19 +33,24 @@ impl Store {
}
fn alloc(&mut self, id: Id) {
self.stack.push_front(Item::Unique(self.tag));
self.env.insert(id, self.tag);
self.tag += 1;
println!("alloc {:?}", self)
}
}
#[derive(Debug)]
enum Expr {
Id(Id),
Num(i32),
Lit,
Ref(Box<Expr>),
RefMut(Box<Expr>),
Deref(Box<Expr>),
}
fn id(id: &str) -> String {
id.to_string()
}
#[derive(Debug)]
enum Stmt {
Let(Id, Expr), // assumed mutable, e.g. let mut a = 0;
......@@ -76,7 +81,15 @@ fn check_stmts(v: &Vec<Stmt>, store: &mut Store) {
fn main() {
let mut env = Env::new();
use {Expr::*, Stmt::*};
let v = vec![Let("a".to_owned(), Num(0))];
let v = vec![
Let(id("a"), Lit), // let a = ...;
Let(id("b"), Lit), // let b = ...;
Let(id("c"), Ref(Box::new(Id(id("a"))))), // let c = &a;
Assign(Id(id("a")), Lit), // a = ...;
];
println!("prog {:?}", v);
check_stmts(&v, &mut Store::new());
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment