summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLieuwe Rooijakkers <lieuwerooijakkers@gmail.com>2019-11-14 18:01:38 +0100
committerTom Smeding <tom.smeding@gmail.com>2019-11-14 18:13:47 +0100
commit6ff145b50b2b56d610a16cc047c311d3f3552bf4 (patch)
tree584aae71a51d46f6fc4fcb9b17e38f3ffbd46459
parentaa160950ef426bc959ddce12bd45d2af0cf8dc72 (diff)
'null?' builtin
-rw-r--r--Compiler.hs2
-rw-r--r--VM.hs2
2 files changed, 2 insertions, 2 deletions
diff --git a/Compiler.hs b/Compiler.hs
index a5a1f3d..913d568 100644
--- a/Compiler.hs
+++ b/Compiler.hs
@@ -83,7 +83,7 @@ newtype CM a = CM {unCM :: StateT CompState (Except String) a}
builtinMap :: Map.Map Name ()
builtinMap = Map.fromList [
("+", ()), ("-", ()), ("<=", ()), ("=", ()), ("print", ()),
- ("list", ()), ("car", ()), ("cdr", ()),
+ ("list", ()), ("car", ()), ("cdr", ()), ("null?", ()),
("sys-open-file", ()), ("sys-close-file", ()), ("sys-get-char", ()), ("sys-put-string", ())]
bbId :: BB -> Int
diff --git a/VM.hs b/VM.hs
index 7baea0d..a272829 100644
--- a/VM.hs
+++ b/VM.hs
@@ -112,7 +112,7 @@ vmRunBuiltin state "=" [a, b] = return (if equalOp a b then RVNum 1 else RVNum 0
vmRunBuiltin state "<=" [RVNum a, RVNum b] = return (RVNum (fromEnum (a <= b)), state)
vmRunBuiltin state "+" [RVNum a, RVNum b] = return (RVNum (a + b), state)
vmRunBuiltin state "-" [RVNum a, RVNum b] = return (RVNum (a - b), state)
--- TODO: null?
+vmRunBuiltin state "null?" [v] = return (RVNum (case v of { RVList [] -> 1; _ -> 0 }), state)
vmRunBuiltin state "car" [RVList l] = case l of
a : _ -> return (a, state)
_ -> throw "Empty list in 'car'"