+-}
+
+-- better solutions for a global map hack are welcome! (typeclasses, TH, ...?)
+
+data MateCtx = MateCtx {
+ ctxMethodMap :: MethodMap,
+ ctxTrapMap :: TrapMap,
+ ctxClassMap :: ClassMap,
+ ctxVirtualMap :: VirtualMap,
+ ctxStringMap :: StringMap,
+ ctxInterfaceMap :: InterfaceMap,
+ ctxInterfaceMethodMap :: InterfaceMethodMap }
+
+emptyMateCtx :: MateCtx
+emptyMateCtx = MateCtx M.empty M.empty M.empty M.empty M.empty M.empty M.empty
+
+mateCtx :: IORef MateCtx
+{-# NOINLINE mateCtx #-}
+mateCtx = unsafePerformIO $ newIORef emptyMateCtx
+
+-- TODO(bernhard): if we ever have thread support, don't forget MVars
+#define SETMAP(name) set##name :: name -> IO (); \
+ set##name m = do ctx <- readIORef mateCtx; \
+ writeIORef mateCtx $ ctx { ctx##name = m };
+
+#define GETMAP(name) get##name :: IO name ; \
+ get##name = do ctx <- readIORef mateCtx; \
+ return $ ctx##name ctx;
+
+SETMAP(MethodMap);
+GETMAP(MethodMap)
+
+SETMAP(TrapMap)
+GETMAP(TrapMap)
+
+SETMAP(ClassMap)
+GETMAP(ClassMap)
+
+SETMAP(VirtualMap)
+GETMAP(VirtualMap)
+
+SETMAP(StringMap)
+GETMAP(StringMap)
+
+SETMAP(InterfaceMap)
+GETMAP(InterfaceMap)
+
+SETMAP(InterfaceMethodMap)
+GETMAP(InterfaceMethodMap)