mirror of
https://github.com/grin-compiler/grin.git
synced 2024-09-11 07:25:28 +03:00
switch keyword return to pure; color pure and function names
This commit is contained in:
parent
3a1de93b0f
commit
48af9f02d3
@ -7,8 +7,8 @@ sum n29 n30 n31 =
|
||||
if b2 then
|
||||
x <- do
|
||||
case CFalse of
|
||||
CFalse -> return ()
|
||||
return n29
|
||||
CFalse -> pure ()
|
||||
pure n29
|
||||
else
|
||||
n18 <- intAdd n30 1
|
||||
n28 <- intAdd n29 n30
|
||||
|
@ -5,7 +5,7 @@ main =
|
||||
sum n29 n30 n31 =
|
||||
b2 <- intGT n30 n31
|
||||
if b2 then
|
||||
return n29
|
||||
pure n29
|
||||
else
|
||||
n18 <- intAdd n30 1
|
||||
n28 <- intAdd n29 n30
|
||||
|
@ -9,29 +9,29 @@ upto m n = (CInt m') <- eval m
|
||||
(CInt n') <- eval n
|
||||
b' <- intGT m' n'
|
||||
if b' then
|
||||
return (CNil)
|
||||
pure (CNil)
|
||||
else
|
||||
m1' <- intAdd m' 1
|
||||
m1 <- store (CInt m1')
|
||||
p <- store (Fupto m1 n)
|
||||
return (CCons m p)
|
||||
pure (CCons m p)
|
||||
|
||||
sum l = l2 <- eval l
|
||||
case l2 of
|
||||
(CNil) -> return (CInt 0)
|
||||
(CNil) -> pure (CInt 0)
|
||||
(CCons x xs) -> (CInt x') <- eval x
|
||||
(CInt s') <- sum xs
|
||||
ax' <- intAdd x' s'
|
||||
return (CInt ax')
|
||||
pure (CInt ax')
|
||||
|
||||
eval q = v <- fetch q
|
||||
case v of
|
||||
(CInt x'1) -> return v
|
||||
(CNil) -> return v
|
||||
(CCons y ys) -> return v
|
||||
(CInt x'1) -> pure v
|
||||
(CNil) -> pure v
|
||||
(CCons y ys) -> pure v
|
||||
(Fupto a b) -> w <- upto a b
|
||||
update q w
|
||||
return w
|
||||
pure w
|
||||
(Fsum c) -> z <- sum c
|
||||
update q z
|
||||
return z
|
||||
pure z
|
||||
|
@ -12,7 +12,7 @@ import qualified Data.Set as Set
|
||||
import Grin
|
||||
import ReduceGrin
|
||||
|
||||
keywords = Set.fromList ["case","of","return","fetch","store","update","if","then","else","do"]
|
||||
keywords = Set.fromList ["case","of","pure","fetch","store","update","if","then","else","do"]
|
||||
|
||||
lineComment :: Parser ()
|
||||
lineComment = L.skipLineComment "--"
|
||||
@ -73,7 +73,7 @@ ifThenElse i = do
|
||||
, Alt (TagPat (Tag C "False" 0)) e
|
||||
]
|
||||
|
||||
simpleExp i = SReturn <$ kw "return" <*> value <|>
|
||||
simpleExp i = SReturn <$ kw "pure" <*> value <|>
|
||||
SStore <$ kw "store" <*> value <|>
|
||||
SFetch <$ kw "fetch" <*> var <|>
|
||||
SUpdate <$ kw "update" <*> var <*> value <|>
|
||||
|
@ -29,8 +29,8 @@ instance Pretty Exp where
|
||||
EBindF simpleexp lpat exp -> pretty lpat <+> text "<-" <+> pretty simpleexp <$$> pretty exp
|
||||
ECaseF val alts -> keyword "case" <+> pretty val <+> keyword "of" <$$> indent 2 (vsep (map pretty alts))
|
||||
-- Simple Expr
|
||||
SAppF name args -> hsep (text name : map pretty args)
|
||||
SReturnF val -> text "return" <+> pretty val
|
||||
SAppF name args -> hsep ((cyan $ text name) : map pretty args)
|
||||
SReturnF val -> keyword "pure" <+> pretty val
|
||||
SStoreF val -> keywordR "store" <+> pretty val
|
||||
SFetchF name -> keywordR "fetch" <+> text name
|
||||
SUpdateF name val -> keywordR "update" <+> text name <+> pretty val
|
||||
|
Loading…
Reference in New Issue
Block a user