on master help sign in
Added %lazy annotations
f03a655Edwin Brady
src/IRTS/LParser.hs+4−1
@@ -52,7 +52,7 @@ fovm f = do defs <- parseFOVM f
52 let defuns = defunctionalise nexttag ctxtIn
52 let defuns = defunctionalise nexttag ctxtIn
53-- print defuns
53-- print defuns
54 let checked = checkDefs defuns (toAlist defuns)
54 let checked = checkDefs defuns (toAlist defuns)
55−-- print checked
55+-- print checked
56 case checked of
56 case checked of
57 OK c -> codegenC c "a.out" True ["math.h"] "" TRACE
57 OK c -> codegenC c "a.out" True ["math.h"] "" TRACE
58 Error e -> fail $ show e
58 Error e -> fail $ show e
@@ -193,6 +193,9 @@ pPrim = do reserved "StrEq"; lchar '(';
193 <|> do reserved "WriteInt"; lchar '(';
193 <|> do reserved "WriteInt"; lchar '(';
194 e <- pLExp; lchar ')';
194 e <- pLExp; lchar ')';
195 return (LOp LPrintNum [e])
195 return (LOp LPrintNum [e])
196+ <|> do reserved "lazy"; lchar '(';
197+ e <- pLExp; lchar ')';
198+ return (LLazyExp e)
196
199
197pAlt :: LParser LAlt
200pAlt :: LParser LAlt
198pAlt = try (do x <- iName []
201pAlt = try (do x <- iName []
src/IRTS/Lang.hs+6
@@ -9,6 +9,7 @@ data LVar = Loc Int | Glob Name
9data LExp = LV LVar
9data LExp = LV LVar
10 | LApp Bool Name [LExp] -- True = tail call
10 | LApp Bool Name [LExp] -- True = tail call
11 | LLazyApp Name [LExp] -- True = tail call
11 | LLazyApp Name [LExp] -- True = tail call
12+ | LLazyExp LExp
12 | LLet Name LExp LExp -- name just for pretty printing
13 | LLet Name LExp LExp -- name just for pretty printing
13 | LLam [Name] LExp -- lambda, lifted out before compiling
14 | LLam [Name] LExp -- lambda, lifted out before compiling
14 | LCon Int Name [LExp]
15 | LCon Int Name [LExp]
@@ -81,6 +82,11 @@ lift env (LApp tc n args) = do args' <- mapM (lift env) args
81 return (LApp tc n args')
82 return (LApp tc n args')
82lift env (LLazyApp n args) = do args' <- mapM (lift env) args
83lift env (LLazyApp n args) = do args' <- mapM (lift env) args
83 return (LLazyApp n args')
84 return (LLazyApp n args')
85+lift env (LLazyExp (LConst c)) = return (LConst c)
86+lift env (LLazyExp e) = do e' <- lift env e
87+ fn <- getNextName
88+ addFn fn (LFun fn env e')
89+ return (LLazyApp fn (map (LV . Glob) env))
84lift env (LLet n v e) = do v' <- lift env v
90lift env (LLet n v e) = do v' <- lift env v
85 e' <- lift (env ++ [n]) e
91 e' <- lift (env ++ [n]) e
86 return (LLet n v' e')
92 return (LLet n v' e')