diff --git a/JHashMap.hs b/JHashMap.hs new file mode 100644 index 0000000000000000000000000000000000000000..9ae75ab2bd6d68f94ca6f7661e1bc67ae1ac2186 --- /dev/null +++ b/JHashMap.hs @@ -0,0 +1,33 @@ +import qualified Data.Map as Map +import Data.IORef + +main :: IO () +main = do + -- Create a new mutable map + julioHashMap <- newMap + + -- insertMap will be called whenever an EqualsToken is located + insertMap julioHashMap "tile1" "valuesLoadedIn1" + insertMap julioHashMap "tile2" "42" + + + -- When a variable name is seen and not an equals, use "lookupMap" + val1 <- lookupMap julioHashMap "tile1" + val2 <- lookupMap julioHashMap "tile2" + val3 <- lookupMap julioHashMap "tile3" --No tile3 currently + + -- Temporary just to check if working + putStrLn $ "tile1: " ++ show val1 + putStrLn $ "tile2: " ++ show val2 + + +type MutableMap a = IORef (Map.Map String a) + +newMap :: IO (MutableMap a) +newMap = newIORef Map.empty + +insertMap :: MutableMap a -> String -> a -> IO () +insertMap ref key value = modifyIORef' ref (Map.insert key value) + +lookupMap :: MutableMap a -> String -> IO (Maybe a) +lookupMap ref key = Map.lookup key <$> readIORef ref diff --git a/JHashtable.hs b/JHashtable.hs deleted file mode 100644 index a97352e5906073c0a0d7ce3b90c6676f39355b5e..0000000000000000000000000000000000000000 --- a/JHashtable.hs +++ /dev/null @@ -1,13 +0,0 @@ -import qualified Data.Map as Map -import Data.IORef - -type MutableMap a = IORef (Map.Map String a) - -newMap :: IO (MutableMap a) -newMap = newIORef Map.empty - -insertMap :: MutableMap a -> String -> a -> IO () -insertMap ref key value = modifyIORef' ref (Map.insert key value) - -lookupMap :: MutableMap a -> String -> IO (Maybe a) -lookupMap ref key = Map.lookup key <$> readIORef ref diff --git a/Julio.hs b/Julio.hs index 821ff6395ca745c129ea122c2d4851ced30aa6e7..58b46a069d60f125b1e5173d4c14dc610b6dca45 100644 --- a/Julio.hs +++ b/Julio.hs @@ -3,7 +3,6 @@ import Grammar import System.Environment import Control.Exception import System.IO -import JHashtable main :: IO ()