instanceOf: make decision at runtime
[mate.git] / Mate / X86TrapHandling.hs
index 7a5c5494a57f6011b8b9ad45622b3e95a22210c3..0df63b866479fac4d2a8d0bcedc508c067dc8d76 100644 (file)
@@ -12,7 +12,7 @@ import qualified Data.ByteString.Lazy as B
 import Foreign
 import Foreign.C.Types
 
-import Harpy
+import Harpy hiding (fst)
 
 import Mate.Types
 import Mate.NativeSizes
@@ -38,8 +38,8 @@ mateHandler reip reax rebx resi = do
         staticFieldHandler reip >>= delTrue
     (Just (ObjectField patcher)) ->
         patchWithHarpy patcher reip >>= delTrue
-    (Just (InstanceOf cn))  ->
-        patchWithHarpy (`patchInstanceOf` cn) reip >>= delFalse
+    (Just (InstanceOf patcher))  ->
+        patchWithHarpy (patcher reax) reip >>= delFalse
     (Just (NewObject patcher))   ->
         patchWithHarpy patcher reip >>= delTrue
     (Just (VirtualCall False mi io_offset)) ->
@@ -72,7 +72,7 @@ patchWithHarpy patcher reip = do
   if mateDEBUG
     then mapM_ (printfJit . printf "patched: %s\n" . showAtt) $ snd right
     else return ()
-  return reip
+  return $ fst right
 
 withDisasm :: CodeGen e s CPtrdiff -> CodeGen e s (CPtrdiff, [Instruction])
 withDisasm patcher = do
@@ -91,12 +91,6 @@ staticFieldHandler reip = do
       return reip
     else error "staticFieldHandler: something is wrong here. abort.\n"
 
-patchInstanceOf :: CPtrdiff -> B.ByteString -> CodeGen e s CPtrdiff
-patchInstanceOf reip classname = do
-  mtable <- liftIO $ getMethodTable classname
-  mov edx mtable
-  return reip
-
 patchInvoke :: MethodInfo -> CPtrdiff -> CPtrdiff -> IO NativeWord -> CPtrdiff -> CodeGen e s CPtrdiff
 patchInvoke (MethodInfo methname _ msig)  method_table table2patch io_offset reip = do
   vmap <- liftIO $ getVirtualMap