diff options
| author | Matthew Hall <hallmatthew314@gmail.com> | 2023-02-22 21:42:36 +1300 |
|---|---|---|
| committer | Matthew Hall <hallmatthew314@gmail.com> | 2023-02-22 21:42:36 +1300 |
| commit | 0bde837174fcb9c17cb3adbf6bc3c7407cab10df (patch) | |
| tree | ed5c1d5f6c0a7526e6c0808ebc02f19366ce4a03 /DSL/Util.hs | |
| parent | 076364eb60b008e3ea9503049b5f0199273811cb (diff) | |
Proctables are now maps
Diffstat (limited to 'DSL/Util.hs')
| -rw-r--r-- | DSL/Util.hs | 18 |
1 files changed, 18 insertions, 0 deletions
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" |
