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

initial commit wip0

parent 3e57cda5
No related branches found
No related tags found
No related merge requests found
// Stacked borrows, Proof of Concept
use std::collections::{HashMap, VecDeque};
type Id = String;
type Stack = VecDeque<Item>;
type Env = HashMap<Id, Tag>;
type Tag = u32;
#[derive(Debug)]
enum Item {
Unique(Tag),
SharedRO(Tag),
SharedRW(Tag),
}
#[derive(Debug)]
struct Store {
tag: Tag,
stack: Stack,
env: Env,
}
impl Store {
fn new() -> Store {
Store {
tag: 0,
stack: Stack::new(),
env: Env::new(),
}
}
fn alloc(&mut self, id: Id) {
self.stack.push_front(Item::Unique(self.tag));
self.tag += 1;
}
}
#[derive(Debug)]
enum Expr {
Id(Id),
Num(i32),
Ref(Box<Expr>),
RefMut(Box<Expr>),
Deref(Box<Expr>),
}
#[derive(Debug)]
enum Stmt {
Let(Id, Expr), // assumed mutable, e.g. let mut a = 0;
Assign(Expr, Expr),
}
fn left_expr(e: &Expr) -> &Id {
match e {
Expr::Id(id) => id,
Expr::Deref(e) => left_expr(e),
_ => unimplemented!("illegal left hand"),
}
}
fn check_stmt(s: &Stmt, store: &mut Store) {
match s {
Stmt::Let(id, e) => store.alloc(id.to_owned()),
Stmt::Assign(le, re) => {}
}
}
fn check_stmts(v: &Vec<Stmt>, store: &mut Store) {
for s in v {
check_stmt(&s, store);
}
}
fn main() {
let mut env = Env::new();
use {Expr::*, Stmt::*};
let v = vec![Let("a".to_owned(), Num(0))];
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