pub struct Ctx<'book> {
pub book: &'book mut Book,
pub info: Diagnostics,
}
Fields§
§book: &'book mut Book
§info: Diagnostics
Implementations§
source§impl Ctx<'_>
impl Ctx<'_>
pub fn set_entrypoint(&mut self)
source§impl Ctx<'_>
impl Ctx<'_>
Checks if there are any repeated top level names. Constructors and functions can’t share names and adts can’t share names.
source§impl Ctx<'_>
impl Ctx<'_>
sourcepub fn check_unbound_vars(&mut self) -> Result<(), Diagnostics>
pub fn check_unbound_vars(&mut self) -> Result<(), Diagnostics>
Checks that there are no unbound variables in all definitions.
source§impl Ctx<'_>
impl Ctx<'_>
sourcepub fn apply_args(&mut self, args: Option<Vec<Term>>) -> Result<(), Diagnostics>
pub fn apply_args(&mut self, args: Option<Vec<Term>>) -> Result<(), Diagnostics>
Applies the arguments to the program being run by applying them to the main function.
Example:
main x1 x2 x3 = (MainBody x1 x2 x3)
Calling with bend run <file> arg1 arg2 arg3
, it becomes:
main = (λx1 λx2 λx3 (MainBody x1 x2 x3) arg1 arg2 arg3)
source§impl Ctx<'_>
impl Ctx<'_>
pub fn desugar_bend(&mut self) -> Result<(), Diagnostics>
source§impl Ctx<'_>
impl Ctx<'_>
sourcepub fn desugar_do_blocks(&mut self) -> Result<(), Diagnostics>
pub fn desugar_do_blocks(&mut self) -> Result<(), Diagnostics>
Converts ask
terms inside do
blocks into calls to a monadic bind operation.
source§impl Ctx<'_>
impl Ctx<'_>
sourcepub fn desugar_fold(&mut self) -> Result<(), Diagnostics>
pub fn desugar_fold(&mut self) -> Result<(), Diagnostics>
Desugars fold
expressions into recursive match
es.
foo xs =
...
fold bind = init with x1 x2 {
Type/Ctr1: (Foo bind.rec_fld bind.fld x1 x2 free_var)
Type/Ctr2: (Bar bind.fld x1 x2)
}
Desugars to:
foo xs =
...
(foo__fold0 init x1 x2 free_var)
foo__fold0 = @bind match bind {
Type/Ctr1: (Foo (foo_fold0 bind.rec_fld x1 x2 free_var) bind.fld x1 x2 free_var)
Type/Ctr2: (Bar bind.fld x1 x2)
}
source§impl Ctx<'_>
impl Ctx<'_>
sourcepub fn desugar_match_defs(&mut self) -> Result<(), Diagnostics>
pub fn desugar_match_defs(&mut self) -> Result<(), Diagnostics>
Converts equational-style pattern matching function definitions into trees of match terms.
source§impl Ctx<'_>
impl Ctx<'_>
pub fn desugar_open(&mut self) -> Result<(), Diagnostics>
source§impl Ctx<'_>
impl Ctx<'_>
sourcepub fn fix_match_defs(&mut self) -> Result<(), Diagnostics>
pub fn fix_match_defs(&mut self) -> Result<(), Diagnostics>
Makes every pattern matching definition have correct a left-hand side.
Does not check exhaustiveness of rules and type mismatches. (Inter-ctr/type proprieties)
source§impl Ctx<'_>
impl Ctx<'_>
sourcepub fn fix_match_terms(&mut self) -> Result<(), Diagnostics>
pub fn fix_match_terms(&mut self) -> Result<(), Diagnostics>
Convert all match and switch expressions to a normalized form.
- For matches, resolve the constructors and create the name of the field variables.
- For switches, resolve the succ case (“_”) and create the name of the pred variable.
- If the match arg is not a variable, it is separated into a let expression and bound to “%matched”
- Check for redundant arms and non-exhaustive matches.
Example: For the program
data MyList = (Cons h t) | Nil
match x {
Cons: (A x.h x.t)
Nil: switch (Foo y) { 0: B; 1: C; _: D }
}
The following AST transformations will be made:
- The binds
x.h
andx.t
will be generated and stored in the match term. (Foo y)`` will be put in a let expression, bound to the variable
%matched`;- The bind
%matched-2
will be generated and stored in the switch term. - If either was missing one of the match cases (a number or a constructor), we’d get an error.
- If either included one of the cases more than once (including wildcard patterns), we’d get a warning.
match x {
Cons: (A x.h x.t)
Nil: let %matched = (Foo y); switch %matched { 0: B; 1: C; _: D }
}
source§impl Ctx<'_>
impl Ctx<'_>
sourcepub fn resolve_refs(&mut self) -> Result<(), Diagnostics>
pub fn resolve_refs(&mut self) -> Result<(), Diagnostics>
Decides if names inside a term belong to a Var or to a Ref.
Converts Term::Var(nam)
into Term::Ref(nam)
when the name
refers to a function definition and there is no variable in
scope shadowing that definition.
Precondition: Refs are encoded as vars, Constructors are resolved.
Postcondition: Refs are encoded as refs, with the correct def id.
Trait Implementations§
Auto Trait Implementations§
impl<'book> Freeze for Ctx<'book>
impl<'book> RefUnwindSafe for Ctx<'book>
impl<'book> Send for Ctx<'book>
impl<'book> Sync for Ctx<'book>
impl<'book> Unpin for Ctx<'book>
impl<'book> !UnwindSafe for Ctx<'book>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more