not everything fixed though. some ugly things in the codegen hopefully disappears
sometimes (e.g. due to an awesome reg allocator ;))
import Data.List
import Data.List.Split
import qualified Data.ByteString.Lazy as B
+import Control.Monad
#ifdef DEBUG
import Text.Printf
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
parseArgs (('-':_):_) _ = error "Usage: mate [-cp|-classpath <cp1:cp2:..>] [<class-file> | -jar <jar-file>]"
-- 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
{-# LANGUAGE CPP #-}
{-# LANGUAGE OverloadedStrings #-}
-{-# LANGUAGE ForeignFunctionInterface #-}
#include "debug.h"
module Mate.ClassPool (
getClassInfo,
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
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)
{-# LANGUAGE OverloadedStrings #-}
-{-# LANGUAGE ForeignFunctionInterface #-}
module Mate.Types where
import Data.Word
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
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
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))