instanceOf: make decision at runtime
[mate.git] / Mate / ClassHierarchy.hs
1 module Mate.ClassHierarchy
2   ( isInstanceOf
3   ) where
4
5 import qualified Data.ByteString.Lazy as B
6 import Control.Applicative
7 import Text.Printf
8
9 import Mate.NativeSizes
10 import Mate.ClassPool
11
12
13 data Class
14   = Class
15     { clMtable :: NativeWord
16     , clSuperClass :: Class
17     , clInterfaces :: [Interface]
18     }
19   | JavaLangObject
20     { clMtable :: NativeWord
21     }
22
23 data Interface
24   = Interface
25     { ifSuperInterfaces :: [Interface]
26     }
27
28 isInstanceOf :: NativeWord -> B.ByteString -> IO Bool
29 isInstanceOf obj_mtable classname = do
30   (== obj_mtable) <$> getMethodTable classname