-
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.
- Loading branch information
Showing
7 changed files
with
87 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
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,33 @@ | ||
module Tree.Transformation.ConvertUnaryCalls (allTests) where | ||
|
||
import Base | ||
import Juvix.Compiler.Tree.Transformation | ||
import Tree.Eval.Positive qualified as Eval | ||
import Tree.Transformation.Base | ||
|
||
allTests :: TestTree | ||
allTests = | ||
testGroup | ||
"ConvertUnaryCalls" | ||
( map liftTest $ | ||
Eval.filterTests | ||
[ "Test007: Higher-order functions", | ||
"Test022: Self-application", | ||
"Test025: Dynamic closure extension", | ||
"Test032: Church numerals", | ||
"Test043: Unary closure calls" | ||
] | ||
Eval.tests | ||
) | ||
|
||
pipe :: [TransformationId] | ||
pipe = [ConvertUnaryCalls] | ||
|
||
liftTest :: Eval.PosTest -> TestTree | ||
liftTest _testEval = | ||
fromTest | ||
Test | ||
{ _testTransformations = pipe, | ||
_testAssertion = const (return ()), | ||
_testEval | ||
} |
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 |
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,41 @@ | ||
|
||
type List { | ||
nil : List; | ||
cons : (*, List) -> List; | ||
} | ||
|
||
function lambda_add(integer) : integer; | ||
function lambda_add2(integer, integer) : integer; | ||
function mapnat(integer -> integer, List) : List; | ||
function main() : List; | ||
|
||
function lambda_add(_X' : integer) : integer { | ||
add(1, _X') | ||
} | ||
|
||
function lambda_add2(_X : integer, _Y : integer) : integer { | ||
add(_X, _Y) | ||
} | ||
|
||
function mapnat(f : integer -> integer, _X : List) : List { | ||
case[List](_X) { | ||
nil: alloc[nil]() | ||
cons: save { | ||
alloc[cons](ccall(f, tmp[0].cons[0]), call[mapnat](f, tmp[0].cons[1])) | ||
} | ||
} | ||
} | ||
|
||
function mysum(f : (integer, integer) -> integer, _X : List) : integer { | ||
case[List](_X) { | ||
nil: 0 | ||
cons: save { | ||
ccall(f, tmp[0].cons[0], call[mysum](f, tmp[0].cons[1])) | ||
} | ||
} | ||
} | ||
|
||
function main() : integer { | ||
call[mysum](calloc[lambda_add2](), call[mapnat](calloc[lambda_add](), alloc[cons](1, alloc[cons](3, alloc[cons](4, alloc[nil]()))))) | ||
-- result: 11 | ||
} |