From: Bernhard Urban Date: Sun, 22 Apr 2012 23:14:45 +0000 (+0200) Subject: types: oops, we don't want the index at this point (MethodInfo) X-Git-Url: http://wien.tomnetworks.com/gitweb/?p=mate.git;a=commitdiff_plain;h=d41300b14108d0fb6d478050852af46bc19069fa types: oops, we don't want the index at this point (MethodInfo) it would be valid just for one certain class anyway... and we don't need it really --- diff --git a/Mate.hs b/Mate.hs index 05754be..35182cc 100644 --- a/Mate.hs +++ b/Mate.hs @@ -32,12 +32,11 @@ main = do case hmap of Just hmap' -> do let methods = classMethods cls; methods :: [Method Resolved] - let idx = findIndex (\x -> (methodName x) == "main") methods - case idx of - Just idx' -> do - let (Just m) = find (\x -> (methodName x) == "main") methods + let method = find (\x -> (methodName x) == "main") methods + case method of + Just m -> do let bclspath = B.pack $ map (fromIntegral . ord) (replace ".class" "" clspath) - entry <- compileBB hmap' (MethodInfo "main" bclspath (methodSignature m) (fromIntegral idx')) + entry <- compileBB hmap' (MethodInfo "main" bclspath (methodSignature m)) printf "executing `main' now:\n" executeFuncPtr entry Nothing -> error "main not found" diff --git a/Mate/MethodPool.hs b/Mate/MethodPool.hs index 762e787..1a9d360 100644 --- a/Mate/MethodPool.hs +++ b/Mate/MethodPool.hs @@ -12,7 +12,6 @@ import Foreign.Ptr import Foreign.C.Types import Foreign.StablePtr -import JVM.ClassFile import JVM.Converter import Harpy @@ -36,16 +35,13 @@ getMethodEntry signal_from ptr_mmap ptr_cmap = do cmap <- ptr2cmap ptr_cmap let w32_from = fromIntegral signal_from - let mi@(MethodInfo method cm _ cpidx) = cmap M.! w32_from + let mi@(MethodInfo method cm _) = cmap M.! w32_from -- TODO(bernhard): replace parsing with some kind of classpool cls <- parseClassFile $ toString $ cm `B.append` ".class" case M.lookup mi mmap of Nothing -> do printf "getMethodEntry(from 0x%08x): no method \"%s\" found. compile it\n" w32_from (show mi) - -- TODO(bernhard): maybe we have to load the class first? - -- (Or better in X86CodeGen?) - let (CMethod _ nt) = (constsPool cls) M.! cpidx - hmap <- parseMethod cls (ntName nt) + hmap <- parseMethod cls method printMapBB hmap case hmap of Just hmap' -> do diff --git a/Mate/Types.hs b/Mate/Types.hs index 95ae4e4..cf4bc78 100644 --- a/Mate/Types.hs +++ b/Mate/Types.hs @@ -35,12 +35,11 @@ type MMap = M.Map MethodInfo Word32 data MethodInfo = MethodInfo { methName :: B.ByteString, cName :: B.ByteString, - mSignature :: MethodSignature, - cpIndex :: Word16 } + mSignature :: MethodSignature} instance Eq MethodInfo where - (MethodInfo m_a c_a s_a i_a) == (MethodInfo m_b c_b s_b i_b) = - (m_a == m_b) && (c_a == c_b) && (s_a == s_b) && (i_a == i_b) + (MethodInfo m_a c_a s_a) == (MethodInfo m_b c_b s_b) = + (m_a == m_b) && (c_a == c_b) && (s_a == s_b) -- TODO(bernhard): not really efficient. also, outsource that to hs-java instance Ord MethodSignature where @@ -51,19 +50,17 @@ instance Ord MethodSignature where cmp_args = (show args_a) `compare` (show args_b) instance Ord MethodInfo where - compare (MethodInfo m_a c_a s_a i_a) (MethodInfo m_b c_b s_b i_b) + compare (MethodInfo m_a c_a s_a) (MethodInfo m_b c_b s_b) | cmp_m /= EQ = cmp_m | cmp_c /= EQ = cmp_c - | cmp_s /= EQ = cmp_s - | otherwise = i_a `compare` i_b + | otherwise = s_a `compare` s_b where cmp_m = m_a `compare` m_b cmp_c = c_a `compare` c_b - cmp_s = s_a `compare` s_b instance Show MethodInfo where - show (MethodInfo method c sig idx) = - (toString c) ++ "." ++ (toString method) ++ "." ++ (show sig) ++ "@" ++ (show idx) + show (MethodInfo method c sig) = + (toString c) ++ "." ++ (toString method) ++ "." ++ (show sig) toString :: B.ByteString -> String diff --git a/Mate/Utilities.hs b/Mate/Utilities.hs index 7002d19..54d32d3 100644 --- a/Mate/Utilities.hs +++ b/Mate/Utilities.hs @@ -20,7 +20,7 @@ lookupMethod name cls = look (classMethods cls) | otherwise = look fs buildMethodID :: Class Resolved -> Word16 -> MethodInfo -buildMethodID cls idx = MethodInfo (ntName nt) rc (ntSignature nt) idx +buildMethodID cls idx = MethodInfo (ntName nt) rc (ntSignature nt) where (CMethod rc nt) = (constsPool cls) M.! idx