diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/Interpreter.hs | 16 | ||||
| -rw-r--r-- | src/Utils.hs | 1 |
2 files changed, 17 insertions, 0 deletions
diff --git a/src/Interpreter.hs b/src/Interpreter.hs index 9395ec1..6be5c71 100644 --- a/src/Interpreter.hs +++ b/src/Interpreter.hs @@ -394,6 +394,20 @@ evaluateSymbol ast@AST { an = ASTSymbol sym } = do Nothing -> throwL (astPos ast, "symbol " ++ sym ++ " not defined in environment") evaluateSymbol ast = throwL (astPos ast, "unreachable: evaluateSymbol, ast: " ++ show ast) +evaluateDo :: [AST] -> LContext AST +evaluateDo children = do + let fnAst = head children + args = tail children + + when (length args == 0) $ throwL (astPos fnAst, "do called with 0 arguments") + + let nonRetExprs = init args + let retExpr = last args + + mapM_ evaluate nonRetExprs + + evaluate retExpr + evaluate :: AST -> LContext AST evaluate ast@AST { an = fnc@(ASTFunctionCall args@(x:_)) } = do config <- getConfig @@ -418,6 +432,8 @@ evaluate ast@AST { an = fnc@(ASTFunctionCall args@(x:_)) } = evaluateImport args ASTSymbol "record" -> evaluateRecord args + ASTSymbol "do" -> + evaluateDo args _ -> evaluateFunctionCall args diff --git a/src/Utils.hs b/src/Utils.hs index 379740d..76b3830 100644 --- a/src/Utils.hs +++ b/src/Utils.hs @@ -188,6 +188,7 @@ instance (Eq ASTNode) where ASTVector a == ASTVector b = a == b ASTFunctionCall a == ASTFunctionCall b = a == b ASTHashMap a == ASTHashMap b = a == b + ASTRecord ah _ hma == ASTRecord bh _ hmb = ah == bh && hma == hmb ASTUnit == ASTUnit = True ASTHole == _ = True _ == ASTHole = True |
