summaryrefslogtreecommitdiff
path: root/DSL/Util.hs
diff options
context:
space:
mode:
authorMatthew Hall <hallmatthew314@gmail.com>2023-02-16 23:05:24 +1300
committerMatthew Hall <hallmatthew314@gmail.com>2023-02-16 23:05:24 +1300
commitb83325c4b5c324a42acfe366cf58b455f8aa941f (patch)
tree7c78add5c12970ebd3f3c50f08808a4d6a636778 /DSL/Util.hs
parentea59151d80958f14c69105ba6b40162b8e191597 (diff)
Big file-structure refactor
Diffstat (limited to 'DSL/Util.hs')
-rw-r--r--DSL/Util.hs27
1 files changed, 27 insertions, 0 deletions
diff --git a/DSL/Util.hs b/DSL/Util.hs
new file mode 100644
index 0000000..67435a2
--- /dev/null
+++ b/DSL/Util.hs
@@ -0,0 +1,27 @@
+module DSL.Util where
+
+import DSL.Types
+
+tAny :: TypeCheck
+tAny = const True
+
+tBool :: TypeCheck
+tBool (StackBool _) = True
+tBool _ = False
+
+tInt :: TypeCheck
+tInt (StackInt _) = True
+tInt _ = False
+
+runChecks :: [TypeCheck] -> Stack -> Maybe String
+runChecks fs s
+ | length fs > length s = Just "stack underflow"
+ | not (and $ zipWith id fs s) = Just "type mis-match"
+ | otherwise = Nothing
+
+hcf :: Machine -> String -> IO Machine
+hcf m msg = putStrLn msg >> return m{ ok=False }
+
+unreachable :: a
+unreachable = error "this branch should be unreachable"
+