Skip to content

Commit

Permalink
use lift in cli and web; sprinting
Browse files Browse the repository at this point in the history
  • Loading branch information
LighghtEeloo committed Apr 30, 2024
1 parent 0e4b7fc commit 3483508
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 34 deletions.
7 changes: 5 additions & 2 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,13 @@ fn run_files(
}
// type check
announce_phase(verbose, title, "tyck");
ZydecoFile::tyck(m.clone())?;
let ctx = ZydecoFile::tyck(m.clone())?;

// if not dry run, link and eval
// if not dry run: lift, link and eval
if !dry_run {
// lift (monad transformation)
announce_phase(verbose, title, "lift");
let m = ZydecoFile::lift(m, ctx.clone())?;
// link
announce_phase(verbose, title, "link");
let sem_m = ZydecoFile::link(m.inner())?;
Expand Down
3 changes: 2 additions & 1 deletion web/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ fn ZydecoUI() -> Html {
fn run(input: &str) -> Result<String, String> {
let p = ZydecoFile::parse_src(input, PathBuf::new())?;
let p = ZydecoFile::elab(p)?;
ZydecoFile::tyck(p.clone())?;
let ctx = ZydecoFile::tyck(p.clone())?;
let p = ZydecoFile::lift(p, ctx.clone())?;
let p = ZydecoFile::link(p.inner)?;
let p = ZydecoFile::eval_os(p, &[]);
let s = match p.entry {
Expand Down
10 changes: 2 additions & 8 deletions zydeco-lang/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,15 @@ pub mod statics {
pub mod err;
pub mod elab;
pub mod tyck;
pub mod lift;
mod fmt;
pub use self::{
elab::Elaboration,
lift::{MonadTransTerm, MonadTransType, MonadTrans},
tyck::{Ctx, Seal, TypeCheck},
};
}

/// monad transformers
pub mod lift {
mod r#type;
mod term;
pub use r#type::MonadTransType;
pub use term::MonadTransTerm;
}

pub mod library {
pub mod syntax;
mod builtins;
Expand Down
2 changes: 1 addition & 1 deletion zydeco-lang/src/library/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ impl From<&ss::TermComputation> for SynComp {
Dtor { body, dtorv: dtor.clone() }.into()
}
ss::TermComputation::BeginBlock(BeginBlock { monad, body }) => {
use crate::lift::MonadTransTerm;
use crate::statics::MonadTransTerm;
(&body.inner_ref().lift(monad.inner_ref())).into()
}
ss::TermComputation::TyAbsTerm(Abs { param: _, body }) => body.inner_ref().into(),
Expand Down
25 changes: 25 additions & 0 deletions zydeco-lang/src/statics/lift.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use crate::prelude::*;
use crate::statics::{err::*, syntax::*, tyck::*};

/// monad transformers
mod r#type;
mod term;

pub trait MonadTransType {
fn lift(&self, ty_m: Type, ctx: Ctx, span: &Span) -> Result<Type, TyckError>;
fn alg(&self, m: RcValue, ctx: Ctx, span: &Span) -> Result<TermComputation, TyckError>;
}

pub trait MonadTransTerm: Clone {
fn lift(&self, m: &TermValue) -> Self;
}

pub trait MonadTrans {
fn lift(self, ctx: Ctx) -> Self;
}

impl MonadTrans for Sp<Program> {
fn lift(self, _ctx: Ctx) -> Self {
todo!()
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
use crate::prelude::*;
use crate::statics::syntax::*;

pub trait MonadTransTerm: Clone {
fn lift(&self, m: &TermValue) -> Self;
}
use super::*;

// Note: no type level transformation is performed here since we're gonna remove them right after anyway

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
use crate::prelude::*;
use crate::statics::{err::*, syntax::*, tyck::*};

pub trait MonadTransType {
fn lift(&self, ty_m: Type, ctx: Ctx, span: &Span) -> Result<Type, TyckError>;
fn alg(&self, m: RcValue, ctx: Ctx, span: &Span) -> Result<TermComputation, TyckError>;
}
use super::*;

impl MonadTransType for Type {
fn lift(&self, ty_m: Type, ctx: Ctx, span: &Span) -> Result<Type, TyckError> {
Expand Down
2 changes: 1 addition & 1 deletion zydeco-lang/src/statics/tyck/computation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ impl TypeCheck for Sp<TermComputation> {
Step::Done(ty.inner_clone().subst(diff, &ctx)?)
}
TermComputation::BeginBlock(BeginBlock { monad, body }) => {
use crate::lift::MonadTransType;
use crate::statics::MonadTransType;
let ty_u_monad = monad.syn(ctx.clone())?;
let ty_monad =
ty_u_monad.clone().elim_thunk(ctx.clone(), span).ok_or_else(|| {
Expand Down
16 changes: 8 additions & 8 deletions zydeco-lang/src/zydeco.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{
syntax as ps,
},
prelude::*,
statics::{syntax as ss, tyck, Ctx, Elaboration, Seal, TypeCheck},
statics::{syntax as ss, tyck, Ctx, Elaboration, MonadTrans, Seal, TypeCheck},
syntax::Env,
utils::span::FileInfo,
};
Expand Down Expand Up @@ -57,14 +57,14 @@ impl ZydecoFile {
let p = Elaboration::elab(p).map_err(|e| format!("{}", e))?;
Ok(p)
}
pub fn tyck(m: Sp<ss::Program>) -> Result<(), String> {
m.syn(Ctx::default()).map_err(|e| format!("{}", e))?;
Ok(())
pub fn tyck(m: Sp<ss::Program>) -> Result<Ctx, String> {
let Seal((ctx, _ty)) = m.syn(Ctx::default()).map_err(|e| format!("{}", e))?;
Ok(ctx)
}
pub fn lift(m: Sp<ss::Program>, ctx: Ctx) -> Result<Sp<ss::Program>, String> {
let m = m.lift(ctx);
Ok(m)
}
// pub fn lift(m: Sp<ss::Program>) -> Result<ss::Program, String> {
// let m = m.lift(Ctx::default());
// Ok(m)
// }
pub fn link(m: ss::Program) -> Result<ls::Program, String> {
let m: ls::Program = m.into();
Ok(m)
Expand Down

0 comments on commit 3483508

Please sign in to comment.