-
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.
- Loading branch information
Haoqiang Fan
committed
Jan 1, 2017
1 parent
a152a19
commit d588177
Showing
4 changed files
with
920 additions
and
32 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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module UCompile where | ||
import ULambdaExpression | ||
import qualified Data.Map as Map | ||
|
||
compileToC :: LExpr -> [Char] | ||
compileToC l = header++compileToCS l (Map.fromList []) 0 footer where | ||
header="void main_program(){\n" | ||
footer=";\n}" | ||
compileToCS :: LExpr -> Map.Map [Char] Int -> Int -> ShowS | ||
compileToCS l names curlevel = case l of | ||
LInt v -> showString ("makeInt("++(show v)++")") | ||
LDouble v -> showString ("makeDouble("++(show v)++")") | ||
LRef key -> case (Map.member key names) of | ||
True -> showString ("makeRef("++(show (curlevel-(names Map.! key)))++")") | ||
False -> showString ("makeBuiltin(\""++key++"\")") | ||
LAbs key l2 -> showString "makeAbs(\n" . compileToCS l2 (Map.insert key curlevel names) (curlevel+1) . showString ")" | ||
LApply l1 l2 -> showString "makeApply(\n" . (compileToCS l1 names curlevel) . showString ",\n" . (compileToCS l2 names curlevel) . showString ")" |
Oops, something went wrong.