Changeset 15095

Show
Ignore:
Timestamp:
01/19/07 17:22:04 (22 months ago)
Author:
audreyt
Message:

* Pugs.Class: Transplant the relevant parts of si.hs into newVal.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • src/Pugs/Class.hs

    r14725 r15095  
    1212-} 
    1313 
    14 module Pugs.Class where 
    15 import Pugs.AST 
     14module Pugs.Class 
     15    ( module Pugs.Class 
     16    , module MO.Run 
     17    , module MO.Compile 
     18    , module MO.Compile.Class 
     19    , module MO.Util 
     20    ) where 
     21import MO.Run 
     22import MO.Compile 
     23import MO.Compile.Class 
     24import MO.Util 
    1625import Pugs.Internals 
    1726 
     27class (Typeable a, Ord a, Typeable1 m, Monad m) => Boxable m a | a -> m where 
     28    classOfBox :: a -> MI m 
     29    fromObjBox :: Invocant m -> m a 
     30 
     31(...) :: forall t a b (m :: * -> *). (Show b, Boxable m b) => t -> (a -> b) -> (t, a -> m (Invocant m)) 
     32(...) x y = (x, mkObj . y) 
     33 
     34(!!!) :: forall t a1 (m :: * -> *) a. (Show a, Boxable m a) => t -> (a1 -> m a) -> (t, a1 -> m (Invocant m)) 
     35(!!!) x y = (x, mkObjM . y) 
     36 
     37mkObj :: (Show a, Boxable m a) => a -> m (Invocant m) 
     38mkObj x = return $ MkInvocant x (class_interface (classOfBox x)) 
     39 
     40mkObjM :: (Show a, Boxable m a) => m a -> m (Invocant m) 
     41mkObjM x = do 
     42    x' <- x 
     43    return $ MkInvocant x' (class_interface (classOfBox x')) 
     44 
     45mkBoxClass :: forall t (m :: * -> *) (m1 :: * -> *). 
     46    ( Method m1 (AnyMethod m1) 
     47    , Code m1 (HsCode m) 
     48    , Typeable t 
     49    , Typeable1 m 
     50    , Monad m 
     51    , Typeable1 m1 
     52    , Method m1 (SimpleMethod m1) 
     53    ) => String -> [(String, t -> m (Invocant m))] -> MI m1 
     54mkBoxClass cls methods = newMI MkMI 
     55    { clsParents        = [] 
     56    , clsRoles          = [] 
     57    , clsAttributes     = [] 
     58    , clsPublicMethods  = newCollection' methodName $ map mkBoxMethod methods 
     59    , clsPrivateMethods = newCollection [] 
     60    , clsName = cls 
     61    } 
     62 
     63mkBoxMethod :: forall t (m1 :: * -> *) (m :: * -> *). 
     64    ( Method m (SimpleMethod m) 
     65    , Code m (HsCode m1) 
     66    , Typeable t 
     67    , Typeable1 m1 
     68    , Monad m1 
     69    ) => (String, t -> m1 (Invocant m1)) -> AnyMethod m 
     70mkBoxMethod (meth, fun) = AnyMethod $ MkSimpleMethod 
     71    { smName = meth 
     72    , smDefinition = MkMethodCompiled $ HsCode $ \args -> do 
     73        str <- fromInvocant args 
     74        fun str   -- Note that we expect "fun" to be monadic 
     75    }