testing
This commit is contained in:
parent
1a0c93f26a
commit
df308cc476
|
@ -7,8 +7,8 @@ use crate::{
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct RefMeta {
|
pub struct RefMeta {
|
||||||
now: u16,
|
pub now: u16,
|
||||||
total: Rc<Cell<u16>>,
|
pub total: Rc<Cell<u16>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Scope<'a> {
|
struct Scope<'a> {
|
||||||
|
@ -38,10 +38,9 @@ impl<'a> Scope<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn compile(mut e: Expr) {
|
pub fn compile(e: &mut Expr) {
|
||||||
let mut scope = Scope::with_parent(None);
|
let mut scope = Scope::with_parent(None);
|
||||||
analyze(&mut scope, &mut e);
|
analyze(&mut scope, e);
|
||||||
println!("{e:?}");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn analyze(scope: &mut Scope, e: &mut Expr) {
|
fn analyze(scope: &mut Scope, e: &mut Expr) {
|
||||||
|
@ -63,12 +62,10 @@ fn analyze(scope: &mut Scope, e: &mut Expr) {
|
||||||
// increment # of uses
|
// increment # of uses
|
||||||
count.update(|c| c + 1);
|
count.update(|c| c + 1);
|
||||||
// set ref meta
|
// set ref meta
|
||||||
let now = count.get();
|
|
||||||
*ref_meta = Some(RefMeta {
|
*ref_meta = Some(RefMeta {
|
||||||
now: count.get(),
|
now: count.get(),
|
||||||
total: count,
|
total: count,
|
||||||
});
|
});
|
||||||
println!("ref {id} #{now}");
|
|
||||||
}
|
}
|
||||||
// ignore
|
// ignore
|
||||||
Expr::Literal(_) => {}
|
Expr::Literal(_) => {}
|
||||||
|
|
|
@ -30,7 +30,14 @@ impl fmt::Display for Literal {
|
||||||
Literal::Integer(n) => write!(f, "{n}"),
|
Literal::Integer(n) => write!(f, "{n}"),
|
||||||
Literal::Float(n) => write!(f, "{n}"),
|
Literal::Float(n) => write!(f, "{n}"),
|
||||||
Literal::Boolean(b) => write!(f, "{b}"),
|
Literal::Boolean(b) => write!(f, "{b}"),
|
||||||
Literal::Ident(id, _) => write!(f, "{id}"),
|
Literal::Ident(id, ref_meta) => write!(
|
||||||
|
f,
|
||||||
|
"{id}{}",
|
||||||
|
ref_meta
|
||||||
|
.as_ref()
|
||||||
|
.map(|rm| format!("@{}/{}", rm.now, rm.total.get()))
|
||||||
|
.unwrap_or_default()
|
||||||
|
),
|
||||||
Literal::Nil => write!(f, "nil"),
|
Literal::Nil => write!(f, "nil"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,11 +16,12 @@ fn main() {
|
||||||
let block = parser.parse().unwrap();
|
let block = parser.parse().unwrap();
|
||||||
println!("Parse took {:?}", start.elapsed());
|
println!("Parse took {:?}", start.elapsed());
|
||||||
|
|
||||||
let e = parser::Expr::Block(block);
|
let mut e = parser::Expr::Block(block);
|
||||||
parser::util::display(&e);
|
parser::util::display(&e);
|
||||||
|
|
||||||
let start = Instant::now();
|
let start = Instant::now();
|
||||||
compiler::compile(e);
|
compiler::compile(&mut e);
|
||||||
|
|
||||||
println!("Analysis took {:?}", start.elapsed());
|
println!("Analysis took {:?}", start.elapsed());
|
||||||
|
parser::util::display(&e);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue