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