AST representation of functions shouldn't use a list as they only contain one expression
This commit is contained in:
parent
700c5be701
commit
6d904fdfc4
2
ast.hs
2
ast.hs
|
@ -13,7 +13,7 @@ data AST = Add AST AST
|
||||||
| Defun String AST
|
| Defun String AST
|
||||||
| Def String AST
|
| Def String AST
|
||||||
| Var String
|
| Var String
|
||||||
| Lambda [(Pattern, [AST])]
|
| Lambda [(Pattern, AST)]
|
||||||
| Call String [AST]
|
| Call String [AST]
|
||||||
| UnitConst
|
| UnitConst
|
||||||
| Cons AST AST
|
| Cons AST AST
|
||||||
|
|
|
@ -22,7 +22,7 @@ data Value = IntV Integer
|
||||||
| StreamV Int
|
| StreamV Int
|
||||||
| ListV [Value]
|
| ListV [Value]
|
||||||
| Builtin BIF
|
| Builtin BIF
|
||||||
| FnV [(Pattern, [AST])] -- pattern->body bindings
|
| FnV [(Pattern, AST)] -- pattern->body bindings
|
||||||
deriving (Eq)
|
deriving (Eq)
|
||||||
|
|
||||||
type Env = M.Map String Value -- an environment
|
type Env = M.Map String Value -- an environment
|
||||||
|
@ -85,7 +85,7 @@ _itos (IntV i) = return $ StrV $ show i
|
||||||
_itos v = error $ "itos: not an int: " ++ show v
|
_itos v = error $ "itos: not an int: " ++ show v
|
||||||
|
|
||||||
initialState = ([stdout, stdin],
|
initialState = ([stdout, stdin],
|
||||||
M.fromList [("id", FnV [(VarP "x", [Var "x"])]),
|
M.fromList [("id", FnV [(VarP "x", Var "x")]),
|
||||||
("stdout", StreamV 0),
|
("stdout", StreamV 0),
|
||||||
("putstr", Builtin $ BIF _putstr),
|
("putstr", Builtin $ BIF _putstr),
|
||||||
("putstrln", Builtin $ BIF (\x -> _putstr $ x +$ StrV "\n")),
|
("putstrln", Builtin $ BIF (\x -> _putstr $ x +$ StrV "\n")),
|
||||||
|
@ -205,7 +205,7 @@ apply (FnV pats) arg =
|
||||||
do
|
do
|
||||||
(s,env) <- get
|
(s,env) <- get
|
||||||
put (s, M.union env' env)
|
put (s, M.union env' env)
|
||||||
foldr1 (>>) $ map eval body
|
eval body
|
||||||
Nothing -> -- doesn't satisfy this pattern
|
Nothing -> -- doesn't satisfy this pattern
|
||||||
apply' xs
|
apply' xs
|
||||||
|
|
||||||
|
|
|
@ -99,7 +99,7 @@ rewriteFun (FunDef name (patterns, body)) =
|
||||||
Defun name lam
|
Defun name lam
|
||||||
where
|
where
|
||||||
-- curry it
|
-- curry it
|
||||||
lam = foldr (\pat lam -> Lambda [(pat, [lam])]) body patterns
|
lam = foldr (\pat lam -> Lambda [(pat, lam)]) body patterns
|
||||||
|
|
||||||
call = do
|
call = do
|
||||||
name <- identifier
|
name <- identifier
|
||||||
|
|
Loading…
Reference in New Issue