aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJan Tuomi <jans.tuomi@gmail.com>2022-12-09 18:55:21 +0200
committerJan Tuomi <jans.tuomi@gmail.com>2022-12-09 18:55:21 +0200
commit8ba98a86805c886719057f9df0d5a74c58c6dabd (patch)
tree8bb5a0890f9a69c01ff219553750058b5da82476 /src
parentcff5a0dfa89ab3a7f95512382cedf88f8e1709d1 (diff)
Add do builtin
Diffstat (limited to 'src')
-rw-r--r--src/Interpreter.hs16
-rw-r--r--src/Utils.hs1
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