-
Notifications
You must be signed in to change notification settings - Fork 371
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ codegen ] get rid of trivial let statements (#2961)
- Loading branch information
1 parent
a00b7ee
commit e34b5a6
Showing
8 changed files
with
67 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import Data.List | ||
import Data.String | ||
import System.File | ||
|
||
path : String | ||
path = "build/exec/fold_app/fold.ss" | ||
|
||
mainLine : String -> Bool | ||
mainLine str = | ||
("(define Main-main" `isPrefixOf` str) && | ||
not ("Main-manyToSmall" `isInfixOf` str) | ||
|
||
main : IO () | ||
main = do | ||
Right str <- readFile path | ||
| Left err => putStrLn "Error when reading \{path}" | ||
case any mainLine (lines str) of | ||
True => putStrLn "Constant expression correctly folded" | ||
False => putStrLn "Failed to fold constant expression" |
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,27 @@ | ||
import Data.Nat | ||
|
||
%default total | ||
|
||
record Small where | ||
constructor S | ||
value : Nat | ||
{auto 0 prf : LTE value 20} | ||
|
||
Show Small where show = show . value | ||
|
||
record Smaller where | ||
constructor XS | ||
value : Nat | ||
{auto 0 prf : LTE value 10} | ||
|
||
-- This is the identity function | ||
toSmall : Smaller -> Small | ||
toSmall (XS v @{prf}) = S v @{transitive prf %search} | ||
|
||
-- This is again the identity function | ||
manyToSmall : List Smaller -> List Small | ||
manyToSmall [] = [] | ||
manyToSmall (x::xs) = toSmall x :: manyToSmall xs | ||
|
||
main : IO () | ||
main = printLn $ manyToSmall [XS 1, XS 2, XS 3] |
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,3 @@ | ||
1/1: Building Check (Check.idr) | ||
Main> Constant expression correctly folded | ||
Main> Bye for now! |
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,2 @@ | ||
:exec main | ||
:q |
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,5 @@ | ||
rm -rf build | ||
|
||
$1 --no-banner --no-color --quiet -o fold Fold.idr | ||
$1 --no-banner --no-color --console-width 0 Check.idr < input | ||
|