-
Notifications
You must be signed in to change notification settings - Fork 442
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
149 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use crate::{ | ||
maybe_grow, | ||
term::{Book, Pattern, Term}, | ||
}; | ||
|
||
impl Book { | ||
pub fn apply_bnd(&mut self) { | ||
for def in self.defs.values_mut() { | ||
for rule in def.rules.iter_mut() { | ||
rule.body.apply_bnd(); | ||
} | ||
} | ||
} | ||
} | ||
|
||
impl Term { | ||
pub fn apply_bnd(&mut self) { | ||
maybe_grow(|| { | ||
for children in self.children_mut() { | ||
children.apply_bnd(); | ||
} | ||
}); | ||
|
||
if let Term::Bnd { fun, ask, val, nxt } = self { | ||
let mut fvs = nxt.free_vars(); | ||
ask.binds().flatten().for_each(|bind| _ = fvs.remove(bind)); | ||
let fvs = fvs.into_keys().collect::<Vec<_>>(); | ||
let nxt = | ||
fvs.iter().fold(*nxt.clone(), |nxt, nam| Term::lam(Pattern::Var(Some(nam.clone())), nxt.clone())); | ||
let nxt = Term::lam(*ask.clone(), nxt); | ||
let term = Term::call(Term::Ref { nam: fun.clone() }, [*val.clone(), nxt]); | ||
*self = Term::call(term, fvs.into_iter().map(|nam| Term::Var { nam })); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
pub mod apply_args; | ||
pub mod apply_bnd; | ||
pub mod apply_use; | ||
pub mod definition_merge; | ||
pub mod definition_pruning; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Result.bind (Result.ok val) f = (f val) | ||
Result.bind err _ = err | ||
|
||
Main = do Result.bind { | ||
ask y = (HVM.store "file.txt" "Alice"); | ||
ask x = (HVM.load "file.txt"); | ||
x | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
Result.bind (Result.ok val) f = (f val) | ||
Result.bind err _ = err | ||
|
||
Bar x = (Result.err 0) | ||
|
||
Foo x y = do Result.bind { | ||
ask x = (Bar x); | ||
(Foo x y) | ||
} | ||
|
||
Main = (Foo "a" 0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
--- | ||
source: tests/golden_tests.rs | ||
input_file: tests/golden_tests/desugar_file/bind_syntax.hvm | ||
--- | ||
(Result.bind) = λa #Result (a Result.bind$C1 Result.bind$C0) | ||
|
||
(Main) = (Result.bind (HVM.store (String.cons 102 (String.cons 105 (String.cons 108 (String.cons 101 (String.cons 46 (String.cons 116 (String.cons 120 (String.cons 116 String.nil)))))))) (String.cons 65 (String.cons 108 (String.cons 105 (String.cons 99 (String.cons 101 String.nil)))))) λ* (Result.bind (HVM.load (String.cons 102 (String.cons 105 (String.cons 108 (String.cons 101 (String.cons 46 (String.cons 116 (String.cons 120 (String.cons 116 String.nil))))))))) λb b)) | ||
|
||
(String.cons) = λa λb #String λc #String λ* #String (c a b) | ||
|
||
(String.nil) = #String λ* #String λb b | ||
|
||
(Result.ok) = λa #Result λb #Result λ* #Result (b a) | ||
|
||
(Result.err) = λa #Result λ* #Result λc #Result (c a) | ||
|
||
(Result.bind$C0) = #Result λd λ* (Result.err d) | ||
|
||
(Result.bind$C1) = #Result λb λc (c b) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
source: tests/golden_tests.rs | ||
input_file: tests/golden_tests/run_file/recursive_bind.hvm | ||
--- | ||
Lazy mode: | ||
(Result.err 0) | ||
|
||
Strict mode: | ||
(Result.err 0) |