From 0bde837174fcb9c17cb3adbf6bc3c7407cab10df Mon Sep 17 00:00:00 2001 From: Matthew Hall Date: Wed, 22 Feb 2023 21:42:36 +1300 Subject: Proctables are now maps --- DSL/Util.hs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'DSL/Util.hs') diff --git a/DSL/Util.hs b/DSL/Util.hs index 7767b4b..75d38af 100644 --- a/DSL/Util.hs +++ b/DSL/Util.hs @@ -1,5 +1,7 @@ module DSL.Util where +import Data.Map.Strict (empty, member, insert, toList) + import DSL.Types tAny :: TypeCheck @@ -26,6 +28,22 @@ runChecks fs s hcf :: Machine -> String -> IO Machine hcf m msg = putStrLn msg >> return m{ ok=False } +appendProcTable :: [ProcSpec] -> ProcTable -> Maybe ProcTable +appendProcTable x y = go x + where + go [] = Just y + go ((n, bs):ps) = go ps >>= f + where + f acc + | member n acc = Nothing + | otherwise = Just $ insert n bs acc + +mergeProcTables :: ProcTable -> ProcTable -> Maybe ProcTable +mergeProcTables x = appendProcTable $ toList x + +buildProcTable :: [ProcSpec] -> Maybe ProcTable +buildProcTable ps = appendProcTable ps empty + unreachable :: a unreachable = error "this branch should be unreachable" -- cgit v1.2.1