From 7e3cda1c8cfe2f1e91816277969391c6d91bfb6a Mon Sep 17 00:00:00 2001 From: Bernhard Urban Date: Tue, 12 Jun 2012 12:06:05 +0200 Subject: [PATCH] hlint: more fixes not everything fixed though. some ugly things in the codegen hopefully disappears sometimes (e.g. due to an awesome reg allocator ;)) --- Mate.hs | 5 +++-- Mate/ClassPool.hs | 7 +++---- Mate/Strings.hs | 2 +- Mate/Types.hs | 1 - Mate/X86TrapHandling.hs | 7 +++---- 5 files changed, 10 insertions(+), 12 deletions(-) diff --git a/Mate.hs b/Mate.hs index 1c229e3..eb3c873 100644 --- a/Mate.hs +++ b/Mate.hs @@ -8,6 +8,7 @@ import Data.Char import Data.List import Data.List.Split import qualified Data.ByteString.Lazy as B +import Control.Monad #ifdef DEBUG import Text.Printf @@ -29,7 +30,7 @@ main = do parseArgs :: [String] -> Bool -> IO () parseArgs ("-jar":jarpath:_) stdcp = do - if not stdcp then addClassPath "./" else return () + unless stdcp $ addClassPath "./" addClassPathJAR jarpath res <- readMainClass jarpath case res of @@ -52,7 +53,7 @@ parseArgs ("-classpath":xs) _ = parseArgs ("-":xs) True -- usage parseArgs (('-':_):_) _ = error "Usage: mate [-cp|-classpath ] [ | -jar ]" -- first argument which isn't prefixed by '-' should be a class file parseArgs (clspath:_) stdcp = do - if not stdcp then addClassPath "./" else return () + unless stdcp $ addClassPath "./" let bclspath = B.pack $ map (fromIntegral . ord) clspath cls <- getClassFile bclspath executeMain bclspath cls diff --git a/Mate/ClassPool.hs b/Mate/ClassPool.hs index e476c8b..cb38b28 100644 --- a/Mate/ClassPool.hs +++ b/Mate/ClassPool.hs @@ -1,6 +1,5 @@ {-# LANGUAGE CPP #-} {-# LANGUAGE OverloadedStrings #-} -{-# LANGUAGE ForeignFunctionInterface #-} #include "debug.h" module Mate.ClassPool ( getClassInfo, @@ -284,15 +283,15 @@ readClassFile path' = readIORef classPaths >>= rcf where path = replace "." "/" path' rcf :: [MClassPath] -> IO (Class Direct) - rcf [] = error $ "readClassFile: Class \"" ++ (show path) ++ "\" not found." - rcf ((Directory pre):xs) = do + rcf [] = error $ "readClassFile: Class \"" ++ show path ++ "\" not found." + rcf (Directory pre:xs) = do let cf = pre ++ path ++ ".class" printfCp "rcf: searching @ %s for %s\n" (show pre) (show path) b <- doesFileExist cf if b then parseClassFile cf else rcf xs - rcf ((JAR p):xs) = do + rcf (JAR p:xs) = do printfCp "rcf: searching %s in JAR\n" (show path) entry <- getEntry p path case entry of diff --git a/Mate/Strings.hs b/Mate/Strings.hs index 2ebda14..3ac7f99 100644 --- a/Mate/Strings.hs +++ b/Mate/Strings.hs @@ -62,7 +62,7 @@ allocateJavaString str = do poke ptr $ fromIntegral mtbl -- build array layout - let strlen = (fromIntegral $ B.length str) + let strlen = fromIntegral $ B.length str -- (+1) for \0, (+4) for length newstr <- mallocString (strlen + 5) BI.memset newstr 0 (fromIntegral $ strlen + 5) diff --git a/Mate/Types.hs b/Mate/Types.hs index f49e040..71b0857 100644 --- a/Mate/Types.hs +++ b/Mate/Types.hs @@ -1,5 +1,4 @@ {-# LANGUAGE OverloadedStrings #-} -{-# LANGUAGE ForeignFunctionInterface #-} module Mate.Types where import Data.Word diff --git a/Mate/X86TrapHandling.hs b/Mate/X86TrapHandling.hs index ef75314..f383c2d 100644 --- a/Mate/X86TrapHandling.hs +++ b/Mate/X86TrapHandling.hs @@ -45,7 +45,7 @@ mateHandler eip eax ebx esp = do 4 -> invokeHandler eax ebx esp True 8 -> invokeHandler eax ebx esp False 2 -> staticFieldHandler eip - x -> error $ "wtf: " ++ (show x) + x -> error $ "wtf: " ++ show x staticCallHandler :: CUInt -> IO CUInt staticCallHandler eip = do @@ -86,7 +86,7 @@ invokeHandler method_table table2patch esp imm8 = do callerAddr <- callerAddrFromStack esp offset <- if imm8 then offsetOfCallInsn8 esp else offsetOfCallInsn32 esp entryAddr <- getMethodEntry callerAddr method_table - let call_insn = intPtrToPtr (fromIntegral $ table2patch + (fromIntegral offset)) + let call_insn = intPtrToPtr (fromIntegral $ table2patch + fromIntegral offset) poke call_insn entryAddr return entryAddr @@ -105,5 +105,4 @@ offsetOfCallInsn32 :: CUInt -> IO CUInt offsetOfCallInsn32 esp = do let ret_ptr = intPtrToPtr (fromIntegral esp) :: Ptr CUInt ret <- peek ret_ptr - retval <- peek (intPtrToPtr $ fromIntegral (ret - 4)) - return retval + peek (intPtrToPtr $ fromIntegral (ret - 4)) -- 2.25.1