hs-java: upgrade to 0.3.1
[mate.git] / Mate / ClassPool.hs
index b7c394c8f8b54b65df9975a6dd835a54064adaba..f9f103829bbb3117affd5d06c7a8ebb814c5b296 100644 (file)
@@ -38,18 +38,17 @@ import JVM.Converter
 import Mate.BasicBlocks
 import {-# SOURCE #-} Mate.MethodPool
 import Mate.Types
-import Mate.Utilities
 import Mate.Debug
 import Mate.GarbageAlloc
 
 getClassInfo :: B.ByteString -> IO ClassInfo
 getClassInfo path = do
-  class_map <- get_classmap >>= ptr2classmap
+  class_map <- getClassMap
   case M.lookup path class_map of
     Nothing -> loadAndInitClass path
     Just ci -> return ci
 
-getClassFile :: B.ByteString -> IO (Class Resolved)
+getClassFile :: B.ByteString -> IO (Class Direct)
 getClassFile path = do
   ci <- getClassInfo path
   return $ ciFile ci
@@ -84,10 +83,9 @@ getObjectSize path = do
   -- one slot for "method-table-ptr"
   return $ (1 + fsize) * 4
 
-foreign export ccall getStaticFieldAddr :: CUInt -> IO CUInt
 getStaticFieldAddr :: CUInt -> IO CUInt
 getStaticFieldAddr from = do
-  trapmap <- get_trapmap >>= ptr2trapmap
+  trapmap <- getTrapMap
   let w32_from = fromIntegral from
   let sfi = trapmap M.! w32_from
   case sfi of
@@ -98,7 +96,7 @@ getStaticFieldAddr from = do
 getInterfaceMethodOffset :: B.ByteString -> B.ByteString -> B.ByteString -> IO Word32
 getInterfaceMethodOffset ifname meth sig = do
   loadInterface ifname
-  ifmmap <- get_interfacemethodmap >>= ptr2interfacemethodmap
+  ifmmap <- getInterfaceMethodMap
   let k = ifname `B.append` meth `B.append` sig
   case M.lookup k ifmmap of
     Just w32 -> return $ w32 + 4
@@ -122,7 +120,7 @@ loadClass path = do
 
   (staticmap, fieldmap) <- calculateFields cfile superclass
   (methodmap, mbase) <- calculateMethodMap cfile superclass
-  immap <- get_interfacemethodmap >>= ptr2interfacemethodmap
+  immap <- getInterfaceMethodMap
 
   -- allocate interface offset table for this class
   -- TODO(bernhard): we have some duplicates in immap (i.e. some
@@ -138,20 +136,18 @@ loadClass path = do
   printfCp "mbase: 0x%08x\n" mbase
   printfCp "interfacemethod: %s @ %s\n" (show immap) (toString path)
   printfCp "iftable: 0x%08x\n" w32_iftable
-  virtual_map <- get_virtualmap >>= ptr2virtualmap
-  let virtual_map' = M.insert mbase path virtual_map
-  virtualmap2ptr virtual_map' >>= set_virtualmap
+  virtual_map <- getVirtualMap
+  setVirtualMap $ M.insert mbase path virtual_map
 
-  class_map <- get_classmap >>= ptr2classmap
+  class_map <- getClassMap
   let new_ci = ClassInfo path cfile staticmap fieldmap methodmap mbase False
-  let class_map' = M.insert path new_ci class_map
-  classmap2ptr class_map' >>= set_classmap
+  setClassMap $ M.insert path new_ci class_map
   return new_ci
 
 
 loadInterface :: B.ByteString -> IO ()
 loadInterface path = do
-  imap <- get_interfacesmap >>= ptr2interfacesmap
+  imap <- getInterfaceMap
   -- interface already loaded?
   case M.lookup path imap of
     Just _ -> return ()
@@ -161,11 +157,11 @@ loadInterface path = do
       cfile <- parseClassFile ifpath
       -- load "superinterfaces" first
       sequence_ [ loadInterface i | i <- interfaces cfile ]
-      immap <- get_interfacemethodmap >>= ptr2interfacemethodmap
+      immap <- getInterfaceMethodMap
 
       -- load map again, because there could be new entries now
       -- due to loading superinterfaces
-      imap' <- get_interfacesmap >>= ptr2interfacesmap
+      imap' <- getInterfaceMap
       let max_off = fromIntegral $ M.size immap * 4
       -- create index of methods by this interface
       let mm = zipbase max_off (classMethods cfile)
@@ -178,17 +174,15 @@ loadInterface path = do
       let sm = zipWith (\x y -> (entry y, immap M.! getname x y)) ifnames methodnames
 
       -- merge all offset tables
-      let methodmap = M.fromList sm `M.union` M.fromList mm `M.union` immap
-      interfacemethodmap2ptr methodmap >>= set_interfacemethodmap
-
-      interfacesmap2ptr (M.insert path cfile imap') >>= set_interfacesmap
+      setInterfaceMethodMap $ M.fromList sm `M.union` M.fromList mm `M.union` immap
+      setInterfaceMap $ M.insert path cfile imap'
   where
   zipbase base = zipWith (\x y -> (entry y, x + base)) [0,4..]
   entry = getname path
   getname p y = p `B.append` methodName y `B.append` encode (methodSignature y)
 
 
-calculateFields :: Class Resolved -> Maybe ClassInfo -> IO (FieldMap, FieldMap)
+calculateFields :: Class Direct -> Maybe ClassInfo -> IO (FieldMap, FieldMap)
 calculateFields cf superclass = do
     -- TODO(bernhard): correct sizes. int only atm
 
@@ -217,7 +211,7 @@ getsupermap :: Maybe ClassInfo -> (ClassInfo -> FieldMap) -> FieldMap
 getsupermap superclass getter = case superclass of Just x -> getter x; Nothing -> M.empty
 
 
-calculateMethodMap :: Class Resolved -> Maybe ClassInfo -> IO (FieldMap, Word32)
+calculateMethodMap :: Class Direct -> Maybe ClassInfo -> IO (FieldMap, Word32)
 calculateMethodMap cf superclass = do
     let methods = filter
                   (\x -> (not . S.member ACC_STATIC . methodAccessFlags) x &&
@@ -237,7 +231,7 @@ calculateMethodMap cf superclass = do
 
 loadAndInitClass :: B.ByteString -> IO ClassInfo
 loadAndInitClass path = do
-  class_map <- get_classmap >>= ptr2classmap
+  class_map <- getClassMap
   ci <- case M.lookup path class_map of
     Nothing -> loadClass path
     Just x -> return x
@@ -260,8 +254,7 @@ loadAndInitClass path = do
         Nothing -> error "loadClass: static initializer not found (WTF?). abort"
     Nothing -> return ()
 
-  class_map' <- get_classmap >>= ptr2classmap
+  class_map' <- getClassMap
   let new_ci = ci { ciInitDone = True }
-  let class_map'' = M.insert path new_ci class_map'
-  classmap2ptr class_map'' >>= set_classmap
+  setClassMap $ M.insert path new_ci class_map'
   return new_ci