mirror of
https://github.com/carp-lang/Carp.git
synced 2024-11-04 19:26:10 +03:00
Implemented the while
structure in the evaluator.
This commit is contained in:
parent
4c08c68513
commit
5410b38375
19
src/Eval.hs
19
src/Eval.hs
@ -247,6 +247,8 @@ eval ctx xobj@(XObj o i t) =
|
||||
case acc of
|
||||
err@(Left _) -> return (ctx, err)
|
||||
Right _ -> eval ctx x
|
||||
[XObj While _ _, cond, body] ->
|
||||
specialCommandWhile ctx cond body
|
||||
[] -> return (ctx, dynamicNil)
|
||||
x -> do
|
||||
return (evalError ctx ("I did not understand the form `" ++ pretty xobj ++ "`") (info xobj))
|
||||
@ -471,6 +473,23 @@ specialCommandDefine ctx xobj =
|
||||
Left err ->
|
||||
return (ctx, Left err)
|
||||
|
||||
specialCommandWhile :: Context -> XObj -> XObj -> IO (Context, Either EvalError XObj)
|
||||
specialCommandWhile ctx cond body = do
|
||||
(newCtx, evd) <- eval ctx cond
|
||||
case evd of
|
||||
Right c ->
|
||||
case obj c of
|
||||
Bol b -> if b
|
||||
then do
|
||||
(newCtx, _) <- eval newCtx body
|
||||
specialCommandWhile newCtx cond body
|
||||
else
|
||||
return (newCtx, dynamicNil)
|
||||
_ ->
|
||||
return (evalError ctx ("This `while` condition contains the non-boolean value '" ++
|
||||
pretty c ++ "`") (info c))
|
||||
Left e -> return (newCtx, Left e)
|
||||
|
||||
getSigFromDefnOrDef :: Context -> Env -> FilePathPrintLength -> XObj -> (Either EvalError (Maybe (Ty, XObj)))
|
||||
getSigFromDefnOrDef ctx globalEnv fppl xobj =
|
||||
let metaData = existingMeta globalEnv xobj
|
||||
|
Loading…
Reference in New Issue
Block a user