Skip to content

Commit

Permalink
fix(sol-thir): add normalize function
Browse files Browse the repository at this point in the history
  • Loading branch information
aripiprazole committed May 12, 2024
1 parent 47b09bc commit 6943bdf
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
3 changes: 2 additions & 1 deletion sol-thir/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pub mod value;
pub struct Jar(
shared::Env,
shared::Env_push,
shared::Env_len,
shared::Context,
debruijin::Indices,
debruijin::Level,
Expand Down Expand Up @@ -72,7 +73,7 @@ impl<DB> ThirDb for DB where

/// Represents the lowering functions for Low-Level Intermediate Representation.
pub trait ThirLowering {
fn thir_eval(&self, env: Env, expr: Expr) -> Value;
fn thir_eval(&self, env: Env, term: Term) -> Value;

fn thir_quote(&self, lvl: Level, value: Value) -> Term;
}
Expand Down
5 changes: 5 additions & 0 deletions sol-thir/src/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ impl Env {
values.push_front(value);
Env::new(db, values)
}

#[salsa::tracked]
pub fn len(self, db: &dyn ThirDb) -> usize {
self.values(db).len()
}
}

pub type Meta = usize;
Expand Down
6 changes: 6 additions & 0 deletions sol-thir/src/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,9 @@ pub enum Term {
Location(Location, Expr),
Sorry(Location, Option<ThirError>),
}

impl Term {
pub fn normalise(self, db: &dyn ThirDb, env: shared::Env) -> Term {
db.thir_quote(Level::new(db, env.len(db)), db.thir_eval(env, self))
}
}
2 changes: 1 addition & 1 deletion sol-thir/src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl Value {
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
pub struct Closure {
pub env: shared::Env,
pub expr: Expr,
pub expr: Term,
}

impl Closure {
Expand Down

0 comments on commit 6943bdf

Please sign in to comment.