Skip to content

Commit

Permalink
feat(sol-driver): reference functions
Browse files Browse the repository at this point in the history
  • Loading branch information
aripiprazole committed May 12, 2024
1 parent 6a9ca39 commit bdd561c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
28 changes: 27 additions & 1 deletion sol-driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ use sol_hir::{
lowering::HirLowering,
package::{HasManifest, Package},
primitives::{PrimitiveBag, PrimitiveProvider},
source::expr::Expr,
};
use sol_thir::{source::Term, value::Type, ThirLowering, ThirTyping};

/// Defines watcher strategies for [`RootDb`].
pub mod watcher;
Expand All @@ -35,7 +37,9 @@ extern crate salsa_2022 as salsa;
sol_syntax::Jar,
sol_diagnostic::Jar,
sol_typer::Jar,
sol_hir_lowering::Jar
sol_hir_lowering::Jar,
sol_thir::Jar,
sol_thir_lowering::Jar
)]
#[derive(Default)]
pub struct RootDb {
Expand All @@ -59,6 +63,28 @@ impl HirLowering for RootDb {
}
}

/// Bridges the [`RootDb`] with the [`sol_thir::ThirLowering`] trait.
impl ThirLowering for RootDb {
fn thir_eval(&self, env: sol_thir::shared::Env, term: Term) -> sol_thir::value::Value {
sol_thir_lowering::thir_eval(self, env, term)
}

fn thir_quote(&self, lvl: sol_thir::debruijin::Level, value: sol_thir::value::Value) -> Term {
sol_thir_lowering::thir_quote(self, lvl, value)
}
}

/// Bridges the [`RootDb`] with the [`sol_thir::ThirTyping`] trait.
impl ThirTyping for RootDb {
fn thir_infer(&self, ctx: sol_thir::shared::Context, expr: Expr) -> (Term, Type) {
sol_thir_lowering::thir_infer(self, ctx, expr)
}

fn thir_check(&self, ctx: sol_thir::shared::Context, expr: Expr, type_repr: Type) -> Term {
sol_thir_lowering::thir_check(self, ctx, expr, type_repr)
}
}

impl RootDb {
/// Registers a package in the database.
pub fn register_package(&self, package: Package) -> Package {
Expand Down
8 changes: 4 additions & 4 deletions sol-thir-lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ fn eval_app(callee: Value, argument: Value) -> Value {
}

#[salsa::tracked]
fn thir_eval(db: &dyn ThirLoweringDb, env: Env, term: Term) -> Value {
pub fn thir_eval(db: &dyn ThirLoweringDb, env: Env, term: Term) -> Value {
match term {
Term::U => Value::U,
Term::Var(idx, _) => env.get(db, idx),
Expand All @@ -68,7 +68,7 @@ fn thir_eval(db: &dyn ThirLoweringDb, env: Env, term: Term) -> Value {

/// The quoting function to convert the value back to the term.
#[salsa::tracked]
fn thir_quote(db: &dyn ThirLoweringDb, lvl: Level, value: Value) -> Term {
pub fn thir_quote(db: &dyn ThirLoweringDb, lvl: Level, value: Value) -> Term {
let (location, value) = value.force(db);

location
Expand Down Expand Up @@ -128,15 +128,15 @@ fn thir_quote_impl(

/// The infer function to infer the type of the term.
#[salsa::tracked]
fn thir_infer(db: &dyn ThirLoweringDb, ctx: Context, expr: Expr) -> (Term, Type) {
pub fn thir_infer(db: &dyn ThirLoweringDb, ctx: Context, expr: Expr) -> (Term, Type) {
ctx.location(db).update(expr.location(db));

todo!()
}

/// The check function to check the type of the term.
#[salsa::tracked]
fn thir_check(db: &dyn ThirLoweringDb, ctx: Context, expr: Expr, type_repr: Type) -> Term {
pub fn thir_check(db: &dyn ThirLoweringDb, ctx: Context, expr: Expr, type_repr: Type) -> Term {
todo!()
}

Expand Down

0 comments on commit bdd561c

Please sign in to comment.