From 6ff145b50b2b56d610a16cc047c311d3f3552bf4 Mon Sep 17 00:00:00 2001 From: Lieuwe Rooijakkers Date: Thu, 14 Nov 2019 18:01:38 +0100 Subject: 'null?' builtin --- Compiler.hs | 2 +- VM.hs | 2 +- 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'" -- cgit v1.2.3-70-g09d2