Changeset 7 for src/AST.hs
- Timestamp:
- 02/09/05 06:00:26 (4 years ago)
- svk:copy_cache_prev:
- 1041
- Files:
-
- 1 modified
-
src/AST.hs (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/AST.hs
r4 r7 15 15 import Internals 16 16 17 import Context 18 17 19 type Ident = String 18 20 … … 25 27 vCast (VPair _ v) = vCast v 26 28 vCast v = doCast v 29 castV :: n -> Val 30 castV v = error $ "cannot cast into Val" 27 31 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 36 instance Context VSub where 37 castV = VSub 38 doCast (VSub b) = b 29 39 30 40 instance Context VBool where 41 castV = VBool 31 42 doCast (VJunc j l) = juncToBool j l 32 43 doCast (VBool b) = b … … 47 58 48 59 instance Context VInt where 60 castV = VInt 49 61 doCast (VInt i) = i 50 62 doCast (VStr s) … … 54 66 55 67 instance Context VRat where 68 castV = VRat 56 69 doCast (VInt i) = i % 1 57 70 doCast (VRat r) = r … … 59 72 60 73 instance Context VNum where 74 castV = VNum 61 75 doCast VUndef = 0 62 76 doCast (VBool b) = if b then 1 else 0 … … 71 85 72 86 instance Context VComplex where 87 castV = VComplex 73 88 doCast x = (vCast x :: VNum) :+ 0 74 89 75 90 instance Context VStr where 91 castV = VStr 76 92 vCast VUndef = "" 77 93 vCast (VStr s) = s … … 93 109 94 110 instance Context VList where 111 castV = VList 95 112 vCast (VList l) = l 96 113 vCast (VPair k v) = [k, v] … … 110 127 111 128 instance Context VScalar where 112 vCast x = x 129 vCast = id 130 castV = id 113 131 114 132 strRangeInf s = (s:strRangeInf (strInc s)) … … 148 166 instance (Show a, Show b) => Show (FiniteMap a b) where 149 167 show fm = show (fmToList fm) 150 151 instance (Ord a, Ord b) => Ord (FiniteMap a b) where152 153 instance Ord VComplex where154 {- ... -}155 168 156 169 data Val … … 167 180 | VRef Val 168 181 | VPair Val Val 169 | VSub Exp182 | VSub VSub 170 183 | VBlock Exp 171 184 | VJunc JuncType [Val] 172 185 | VError VStr Exp 173 | VPoly { polyScalar :: Val 174 , polyList :: Val 175 } 186 deriving (Show, Eq, Ord) 187 188 data SubType = SubMethod | SubRoutine | SubMulti 189 deriving (Show, Eq, Ord) 190 191 data VSub = Sub 192 { subType :: SubType 193 , subAssoc :: String 194 , subParams :: [Cxt] 195 , subReturns :: Cxt 196 , subFun :: Exp 197 } 176 198 deriving (Show, Eq, Ord) 177 199 … … 184 206 deriving (Show, Eq, Ord) 185 207 208 instance Eq ([Val] -> Val) 209 instance Ord ([Val] -> Val) 210 instance Ord VComplex where {- ... -} 211 instance (Ord a, Ord b) => Ord (FiniteMap a b) 212 213 type Var = String 214 186 215 data 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) 191 219 | Val Val 220 | Var Var SourcePos 221 | Parens Exp 192 222 | NonTerm SourcePos 193 223 deriving (Show, Eq, Ord) 224 225 isTotalJunc (VJunc JAll _, b) = not b 226 isTotalJunc (VJunc JNone _, b) = not b 227 isTotalJunc _ = False 228 229 isPartialJunc (VJunc JOne _, b) = not b 230 isPartialJunc (VJunc JAny _, b) = not b 231 isPartialJunc _ = False 232
