datins = printf "%s;%08x;%08x;%s;%s;%s\n"
-type DictLabel = (String,Word32)
+-- datastructure for managing labels and defines
+type Dict = (Address,[DictElem])
+type DictElem = (String,Word32)
-get_label :: String -> [DictLabel] -> Maybe Word32
-get_label = lookup
+get_elem :: String -> [DictElem] -> Word32
+get_elem s dict = case (lookup s dict) of
+ Nothing -> error ("unknown label or define: \"" ++ s ++ "\"")
+ Just z -> z
-add_label :: [DictLabel] -> (String,Word32) -> [DictLabel]
-add_label dic (s,w)
+add_elem :: [DictElem] -> (String,Word32) -> [DictElem]
+add_elem dic (s,w)
| s == "" = dic -- ignore empty string
- | already_in = error ("Label " ++ s ++ " already exists")
+ | already_in = error ("Label or define \"" ++ s ++ "\" already exists")
| otherwise = (s,w):dic
where
- already_in = case (get_label s dic) of
+ already_in = case (lookup s dic) of
Just _ -> True
Nothing -> False