aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Tuomi <jans.tuomi@gmail.com>2022-09-27 10:20:05 +0300
committerJan Tuomi <jans.tuomi@gmail.com>2022-12-05 14:21:53 +0200
commit83ae25fe87e3a56d169ae8cfc5bf20423d3ec4a5 (patch)
tree922febad90ffa863c9e244dffbdb44957c5df273
parent18c241ff7a53625c6f3c4e6f20ee8df5bb37ddf3 (diff)
Add fatal builtin
-rw-r--r--examples/maybe.lisp18
-rw-r--r--src/Builtins.hs11
2 files changed, 19 insertions, 10 deletions
diff --git a/examples/maybe.lisp b/examples/maybe.lisp
index c72e114..0447139 100644
--- a/examples/maybe.lisp
+++ b/examples/maybe.lisp
@@ -8,7 +8,7 @@
(let unsafe-at (\[n seq]
(match seq
[]
- (error "unsafe-at out of bounds")
+ (fatal "unsafe-at out of bounds")
(match n
0
(head seq)
@@ -39,11 +39,11 @@
"nothing"
(print-line! "found nothing!"))
-;; (export [
-;; just
-;; nothing
-;; unpack-just
-;; kind
-;; map
-;; and-then
-;; ]) \ No newline at end of file
+(let exports [
+ just
+ nothing
+ unpack-just
+ kind
+ map
+ and-then
+])
diff --git a/src/Builtins.hs b/src/Builtins.hs
index 8dc96b2..d35ce17 100644
--- a/src/Builtins.hs
+++ b/src/Builtins.hs
@@ -18,7 +18,8 @@ builtinEnv = M.fromList [
builtinPrint,
builtinConcat,
builtinFmt,
- ("unit", ASTUnit)
+ ("unit", ASTUnit),
+ builtinFatal
]
argError1 :: Show a => String -> a -> String
@@ -147,3 +148,11 @@ builtinFmt = (name, ASTFunction outer) where
replaceAll n (x:xs) text =
let text' = T.replace (T.pack $ "{" ++ show n ++ "}") (T.pack $ show x) text
in replaceAll (n + 1) xs text'
+
+builtinFatal :: (String, AST)
+builtinFatal = (name, ASTFunction outer) where
+ name = "fatal"
+ outer _ (ASTString str) =
+ throwL $ str
+ outer _ ast =
+ throwL $ argError1 name ast