-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move applications inside Lets and Cases (#1659)
* Move applications inside lets and cases * make ormolu happy
- Loading branch information
Showing
8 changed files
with
68 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,5 +6,6 @@ data TransformationId | |
= LambdaLifting | ||
| TopEtaExpand | ||
| RemoveTypeArgs | ||
| MoveApps | ||
| Identity | ||
deriving stock (Data) |
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,37 @@ | ||
module Juvix.Compiler.Core.Transformation.MoveApps | ||
( moveApps, | ||
module Juvix.Compiler.Core.Transformation.Base, | ||
) | ||
where | ||
|
||
import Juvix.Compiler.Core.Extra | ||
import Juvix.Compiler.Core.Transformation.Base | ||
|
||
convertNode :: Node -> Node | ||
convertNode = dmap go | ||
where | ||
go :: Node -> Node | ||
go node = case node of | ||
NApp {} -> | ||
let (tgt, args) = unfoldApps node | ||
in case tgt of | ||
NLet lt@(Let {..}) -> | ||
NLet lt {_letBody = mkApps _letBody (map (second (shift 1)) args)} | ||
NCase cs@(Case {..}) -> | ||
NCase | ||
cs | ||
{ _caseBranches = | ||
map | ||
( \br@CaseBranch {..} -> | ||
br | ||
{ _caseBranchBody = mkApps _caseBranchBody (map (second (shift _caseBranchBindersNum)) args) | ||
} | ||
) | ||
_caseBranches, | ||
_caseDefault = fmap (`mkApps` args) _caseDefault | ||
} | ||
_ -> node | ||
_ -> node | ||
|
||
moveApps :: InfoTable -> InfoTable | ||
moveApps tab = mapT (const convertNode) tab |
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 @@ | ||
9 |
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,12 @@ | ||
-- applications with lets and cases in function position | ||
|
||
inductive list { | ||
nil : list; | ||
cons : any -> list -> list; | ||
}; | ||
|
||
def f := \l (case l of { cons x _ := x; nil := \x x } ) (let y := \x x in (let z := \x x in case l of { _ := \x x } z) y) 7; | ||
|
||
def main := f (cons (\x \y x y + 2) nil); | ||
|
||
main |