-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented if statements and lambdas. (#5)
- Loading branch information
Showing
10 changed files
with
120 additions
and
7 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,21 @@ | ||
module Harper.Engine.Conditionals ( | ||
linearizeCond | ||
) | ||
where | ||
|
||
import Harper.Abs | ||
import Harper.Engine.Values | ||
|
||
-- Turns a conditional statement into a linear conditional statement. | ||
-- Linear means a list of if statements where we assume that the first if with a true predicate | ||
-- will be the only one to execute. | ||
linearizeCond :: ConditionalStatement -> ConditionalStatement | ||
linearizeCond s@(LinCondStmt _) = s | ||
linearizeCond (IfElifStmts _if elifs) = LinCondStmt (_if:map elifToIf elifs) | ||
linearizeCond (IfElifElseStmts _if elifs _else) = LinCondStmt (_if:map elifToIf elifs ++ [elseToIf _else]) | ||
|
||
elifToIf :: ElseIfStatement -> IfStatement | ||
elifToIf (ElifStmt v s) = IfStmt v s | ||
|
||
elseToIf :: ElseStatement -> IfStatement | ||
elseToIf (ElseStmt s) = IfStmt litTrue s |
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,13 @@ | ||
module Harper.Engine.Values | ||
where | ||
|
||
import Harper.Abs | ||
|
||
litTrue :: Value | ||
litTrue = LitVal (BoolLit BTrue) | ||
|
||
litFalse :: Value | ||
litFalse = LitVal (BoolLit BFalse) | ||
|
||
unit :: Value | ||
unit = UnitVal -- TODO: Turn into a literal. |
Binary file not shown.
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
Binary file not shown.