diff options
author | Lieuwe Rooijakkers <lieuwerooijakkers@gmail.com> | 2019-11-14 18:01:38 +0100 |
---|---|---|
committer | Tom Smeding <tom.smeding@gmail.com> | 2019-11-14 18:13:47 +0100 |
commit | 6ff145b50b2b56d610a16cc047c311d3f3552bf4 (patch) | |
tree | 584aae71a51d46f6fc4fcb9b17e38f3ffbd46459 | |
parent | aa160950ef426bc959ddce12bd45d2af0cf8dc72 (diff) |
'null?' builtin
-rw-r--r-- | Compiler.hs | 2 | ||||
-rw-r--r-- | 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 @@ -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'" |