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

initial commit wip2

parent 320141f0
No related branches found
No related tags found
No related merge requests found
......@@ -57,18 +57,43 @@ enum Stmt {
Assign(Expr, Expr),
}
fn left_expr(e: &Expr) -> &Id {
fn left_expr(e: &Expr) -> Id {
match e {
Expr::Id(id) => id,
Expr::Id(id) => id.to_owned(),
Expr::Deref(e) => left_expr(e),
_ => unimplemented!("illegal left hand"),
}
}
fn right_expr(e: &Expr) -> &Expr {
println!("right_expr {:?}", e);
match e {
Expr::Id(_) => e,
Expr::Lit => e,
Expr::Ref(_) => {
println!("Ref");
e
}
Expr::RefMut(_) => {
println!("RefMut");
e
}
Expr::Deref(e) => {
println!("Deref");
right_expr(e)
}
}
}
fn check_stmt(s: &Stmt, store: &mut Store) {
match s {
Stmt::Let(id, e) => store.alloc(id.to_owned()),
Stmt::Assign(le, re) => {}
Stmt::Assign(le, re) => {
println!("assign le :{:?}, re: {:?}", le, re);
let id = left_expr(le);
let e = right_expr(re);
println!("assign id :{:?}, re: {:?}", id, e);
}
}
}
......@@ -87,6 +112,7 @@ fn main() {
Let(id("b"), Lit), // let b = ...;
Let(id("c"), Ref(Box::new(Id(id("a"))))), // let c = &a;
Assign(Id(id("a")), Lit), // a = ...;
Assign(Deref(Box::new(Id(id("c")))), Lit), // *c = ..;
];
println!("prog {:?}", v);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment