Changeset 26 for src/AST.hs
- Timestamp:
- 02/14/05 06:02:18 (4 years ago)
- svk:copy_cache_prev:
- 1041
- Files:
-
- 1 modified
-
src/AST.hs (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/AST.hs
r25 r26 18 18 type Ident = String 19 19 20 class Contextn where20 class Value n where 21 21 vCast :: Val -> n 22 22 vCast (VRef v) = vCast v … … 31 31 fmapVal f = castV . f . vCast 32 32 33 instance Context(Val, Val) where33 instance Value (Val, Val) where 34 34 castV (x, y) = VPair x y 35 35 vCast (VPair x y) = (x, y) … … 39 39 other -> error $ "cannot cast into (Val, Val): " ++ (show v) 40 40 41 instance ContextVHash where41 instance Value VHash where 42 42 castV = VHash 43 43 vCast x = MkHash $ listToFM (map vCast $ vCast x) 44 44 45 instance ContextVSub where45 instance Value VSub where 46 46 castV = VSub 47 47 doCast (VSub b) = b 48 48 49 instance ContextVBool where49 instance Value VBool where 50 50 castV = VBool 51 51 doCast (VJunc j) = juncToBool j … … 70 70 = (1 ==) . length . filter vCast $ setToList vs 71 71 72 instance ContextVInt where72 instance Value VInt where 73 73 castV = VInt 74 74 doCast (VInt i) = i … … 78 78 doCast x = round (vCast x :: VNum) 79 79 80 instance ContextVRat where80 instance Value VRat where 81 81 castV = VRat 82 82 doCast (VInt i) = i % 1 … … 84 84 doCast x = approxRational (vCast x :: VNum) 1 85 85 86 instance ContextVNum where86 instance Value VNum where 87 87 castV = VNum 88 88 doCast VUndef = 0 … … 97 97 doCast x = error $ "cannot cast: " ++ (show x) 98 98 99 instance ContextVComplex where99 instance Value VComplex where 100 100 castV = VComplex 101 101 doCast x = (vCast x :: VNum) :+ 0 102 102 103 instance ContextVStr where103 instance Value VStr where 104 104 castV = VStr 105 105 vCast VUndef = "" … … 121 121 str = show x 122 122 123 instance ContextVArray where123 instance Value VArray where 124 124 castV = VArray 125 125 vCast x = MkArray (vCast x) 126 126 127 127 {- 128 instance ContextVJunc where128 instance Value VJunc where 129 129 castV = JAny . castV 130 130 vCast x = JAny $ mkSet (vCast x) 131 131 -} 132 132 133 instance ContextVList where133 instance Value VList where 134 134 castV = VList 135 135 vCast (VList l) = l … … 139 139 vCast v = [v] 140 140 141 instance Context(Maybe a) where141 instance Value (Maybe a) where 142 142 vCast VUndef = Nothing 143 143 vCast _ = Just undefined 144 144 145 instance ContextInt where doCast = intCast146 instance ContextWord where doCast = intCast147 instance ContextWord8 where doCast = intCast148 instance Context[Word8] where doCast = map (toEnum . ord) . vCast145 instance Value Int where doCast = intCast 146 instance Value Word where doCast = intCast 147 instance Value Word8 where doCast = intCast 148 instance Value [Word8] where doCast = map (toEnum . ord) . vCast 149 149 150 150 type VScalar = Val 151 151 -- type VJunc = Set Val 152 152 153 instance ContextVScalar where153 instance Value VScalar where 154 154 vCast = id 155 155 castV = id … … 239 239 , subName :: String 240 240 , subType :: SubType 241 , subPad :: Symbols241 , subPad :: Pad 242 242 , subAssoc :: String 243 243 , subParams :: Params … … 257 257 -} 258 258 259 instance Ord ([Val] -> StateEnv Val) where260 compare _ _ = LT261 259 instance (Ord a) => Ord (Set a) where 262 260 compare x y = compare (setToList x) (setToList y) … … 272 270 | Syn String [Exp] 273 271 | Sym Scope Var 274 | Prim ([Val] -> StateEnvVal)272 | Prim ([Val] -> Eval Val) 275 273 | Val Val 276 274 | Var Var SourcePos … … 326 324 defaultScalarParam = buildParam "" "*" "$_" (Val VUndef) 327 325 328 -- The eval monad!329 type StateEnv a = State Env a330 331 326 data Env = Env { envContext :: Cxt 332 , envPad :: Symbols327 , envPad :: Pad 333 328 , envClasses :: ClassTree 334 329 , envEval :: Exp -> Eval Val … … 339 334 } deriving (Show, Eq) 340 335 341 type Symbols= [Symbol]336 type Pad = [Symbol] 342 337 data Symbol = Symbol { symScope :: Scope 343 338 , symName :: String
