Changeset 7 for src/AST.hs

Show
Ignore:
Timestamp:
02/09/05 06:00:26 (4 years ago)
Author:
autrijus
svk:copy_cache_prev:
1041
Message:

* This be 6.0.2

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • src/AST.hs

    r4 r7  
    1515import Internals 
    1616 
     17import Context 
     18 
    1719type Ident = String 
    1820 
     
    2527    vCast (VPair _ v)   = vCast v 
    2628    vCast v             = doCast v 
     29    castV :: n -> Val 
     30    castV v = error $ "cannot cast into Val" 
    2731    doCast :: Val -> n 
    28     doCast v = error $ "cannot cast: " ++ (show v) 
     32    doCast v = error $ "cannot cast from Val: " ++ (show v) 
     33    fmapVal :: (n -> n) -> Val -> Val 
     34    fmapVal f = castV . f . vCast 
     35 
     36instance Context VSub where 
     37    castV = VSub 
     38    doCast (VSub b) = b 
    2939 
    3040instance Context VBool where 
     41    castV = VBool 
    3142    doCast (VJunc j l) = juncToBool j l 
    3243    doCast (VBool b)   = b 
     
    4758 
    4859instance Context VInt where 
     60    castV = VInt 
    4961    doCast (VInt i)     = i 
    5062    doCast (VStr s) 
     
    5466 
    5567instance Context VRat where 
     68    castV = VRat 
    5669    doCast (VInt i)     = i % 1 
    5770    doCast (VRat r)     = r 
     
    5972 
    6073instance Context VNum where 
     74    castV = VNum 
    6175    doCast VUndef       = 0 
    6276    doCast (VBool b)    = if b then 1 else 0 
     
    7185 
    7286instance Context VComplex where 
     87    castV = VComplex 
    7388    doCast x            = (vCast x :: VNum) :+ 0 
    7489 
    7590instance Context VStr where 
     91    castV = VStr 
    7692    vCast VUndef        = "" 
    7793    vCast (VStr s)      = s 
     
    93109 
    94110instance Context VList where 
     111    castV = VList 
    95112    vCast (VList l)     = l 
    96113    vCast (VPair k v)   = [k, v] 
     
    110127 
    111128instance Context VScalar where 
    112     vCast x             = x 
     129    vCast = id 
     130    castV = id 
    113131 
    114132strRangeInf s = (s:strRangeInf (strInc s)) 
     
    148166instance (Show a, Show b) => Show (FiniteMap a b) where 
    149167    show fm = show (fmToList fm) 
    150  
    151 instance (Ord a, Ord b) => Ord (FiniteMap a b) where 
    152  
    153 instance Ord VComplex where 
    154     {- ... -} 
    155168 
    156169data Val 
     
    167180    | VRef      Val 
    168181    | VPair     Val Val 
    169     | VSub      Exp 
     182    | VSub      VSub 
    170183    | VBlock    Exp 
    171184    | VJunc     JuncType [Val] 
    172185    | VError    VStr Exp 
    173     | VPoly     { polyScalar    :: Val 
    174                 , polyList      :: Val 
    175                 } 
     186    deriving (Show, Eq, Ord) 
     187 
     188data SubType = SubMethod | SubRoutine | SubMulti 
     189    deriving (Show, Eq, Ord) 
     190 
     191data VSub = Sub 
     192    { subType       :: SubType 
     193    , subAssoc      :: String 
     194    , subParams     :: [Cxt] 
     195    , subReturns    :: Cxt 
     196    , subFun        :: Exp 
     197    } 
    176198    deriving (Show, Eq, Ord) 
    177199 
     
    184206    deriving (Show, Eq, Ord) 
    185207 
     208instance Eq ([Val] -> Val) 
     209instance Ord ([Val] -> Val) 
     210instance Ord VComplex where {- ... -} 
     211instance (Ord a, Ord b) => Ord (FiniteMap a b) 
     212 
     213type Var = String 
     214 
    186215data Exp 
    187     = Op1 String Exp 
    188     | Op2 String Exp Exp 
    189     | Op3 String Exp Exp Exp 
    190     | OpCmp String Exp Exp 
     216    = App String [Exp] 
     217    | Syn String [Exp] 
     218    | Prim ([Val] -> Val) 
    191219    | Val Val 
     220    | Var Var SourcePos 
     221    | Parens Exp 
    192222    | NonTerm SourcePos 
    193223    deriving (Show, Eq, Ord) 
     224 
     225isTotalJunc (VJunc JAll _, b)   = not b 
     226isTotalJunc (VJunc JNone _, b)  = not b 
     227isTotalJunc _                   = False 
     228 
     229isPartialJunc (VJunc JOne _, b) = not b 
     230isPartialJunc (VJunc JAny _, b) = not b 
     231isPartialJunc _                 = False 
     232