Changeset 15297 for src/Pugs/Eval.hs

Show
Ignore:
Timestamp:
02/18/07 15:59:02 (21 months ago)
Author:
audreyt
Message:

* Revert the previous patch; everything back to normal.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • src/Pugs/Eval.hs

    r15296 r15297  
    1 {-# OPTIONS_GHC -fglasgow-exts -cpp -fno-warn-deprecations -fallow-overlapping-instances -foverloaded-strings #-} 
     1{-# OPTIONS_GHC -fglasgow-exts -cpp -fno-warn-deprecations -fallow-overlapping-instances #-} 
    22 
    33{-| 
     
    6969        , envLValue  = False 
    7070        , envGlobal  = length (show (padKeys globPad)) `seq` glob -- force eval of all sym names 
    71         , envPackage = _cast "Main" 
     71        , envPackage = cast "Main" 
    7272        , envClasses = initTree 
    7373        , envEval    = evaluate 
     
    9595runWarn msg = do  
    9696    enterEvalContext CxtVoid $ 
    97         App (_Var "&warn") Nothing [Val (_VStr msg)] 
     97        App (_Var "&warn") Nothing [Val (VStr msg)] 
    9898    return () 
    9999 
     
    115115evaluateMain exp = do 
    116116    -- S04: INIT {...}*      at run time, ASAP 
    117     initAV   <- reduceVar $ _cast "@*INIT" 
     117    initAV   <- reduceVar $ cast "@*INIT" 
    118118    initSubs <- fromVals initAV 
    119119    enterContext CxtVoid $ do 
     
    123123    tryT (evaluate exp) `finallyM` do 
    124124        -- S04: END {...}       at run time, ALAP 
    125         endAV       <- reduceVar $ _cast "@*END" 
     125        endAV       <- reduceVar $ cast "@*END" 
    126126        endSubs     <- fromVals endAV 
    127         endMainAV   <- reduceVar $ _cast "@Main::END" 
     127        endMainAV   <- reduceVar $ cast "@Main::END" 
    128128        endMainSubs <- fromVals endMainAV 
    129129        enterContext CxtVoid $ do 
     
    143143        Just ref -> do 
    144144            want <- asks envWant 
    145             debug ref (_cast "indent") ('-':) (" Evl [" ++ want ++ "]:\n") exp 
     145            debug ref (cast "indent") ('-':) (" Evl [" ++ want ++ "]:\n") exp 
    146146            val <- local (\e -> e{ envBody = exp }) $ reduce exp 
    147             debug ref (_cast "indent") (\x -> if null x then [] else tail x) "- Ret: " val 
     147            debug ref (cast "indent") (\x -> if null x then [] else tail x) "- Ret: " val 
    148148            trapVal val (return val) 
    149149        Nothing -> do 
     
    270270 
    271271isStrict :: Eval Bool 
    272 isStrict = fromVal =<< readVar (_cast "$*STRICT") 
     272isStrict = fromVal =<< readVar (cast "$*STRICT") 
    273273 
    274274-- Reduction for variables 
     
    276276reduceVar var@MkVar{ v_sigil = sig, v_twigil = twi, v_name = name, v_package = pkg } 
    277277    | TAttribute <- twi 
    278     = reduceSyn (cast $ show sig ++ "{}") [ Syn "{}" [_Var "&self", Val (VStr $ cast name)] ] 
     278    = reduceSyn (show sig ++ "{}") [ Syn "{}" [_Var "&self", Val (VStr $ cast name)] ] 
    279279    | TPrivate <- twi 
    280     = reduceSyn (cast $ show sig ++ "{}") [ Syn "{}" [_Var "&self", Val (VStr $ cast name)] ] 
     280    = reduceSyn (show sig ++ "{}") [ Syn "{}" [_Var "&self", Val (VStr $ cast name)] ] 
    281281    | otherwise = do 
    282282        v <- findVar var 
     
    307307 
    308308-- XXX - Hack to get context propagating to "return" 
    309 reduceStmts this@(App (Var var) _ _) _ | var == _cast "&return" = reduce this 
    310 reduceStmts this@(Ann _ (App (Var var) _ _)) _ | var == _cast "&return" = reduce this 
     309reduceStmts this@(App (Var var) _ _) _ | var == cast "&return" = reduce this 
     310reduceStmts this@(Ann _ (App (Var var) _ _)) _ | var == cast "&return" = reduce this 
    311311 
    312312reduceStmts this rest = do 
    313313    let withCxt = case this of 
    314             App (Var var) _ _         | var == _cast "&yield" -> id 
    315             Ann _ (App (Var var) _ _) | var == _cast "&yield" -> id 
     314            App (Var var) _ _         | var == cast "&yield" -> id 
     315            Ann _ (App (Var var) _ _) | var == cast "&yield" -> id 
    316316            _  -> enterContext cxtVoid 
    317317    val <- withCxt (reduce this) 
     
    383383-- Special case: my (undef) is no-op 
    384384reduceSym scope var exp 
    385 --  | var == _cast "" = evalExp exp 
     385--  | var == cast "" = evalExp exp 
    386386    | scope <= SMy = do 
    387387        ref <- newObject (typeOfSigilVar var) 
     
    418418enough to make it redundant. 
    419419-} 
    420 reduceSyn :: ID -> [Exp] -> Eval Val 
     420reduceSyn :: String -> [Exp] -> Eval Val 
    421421 
    422422reduceSyn "()" [exp] = reduce exp 
     
    541541    readRef newAV `finallyM` liftSTM (modifyTVar globTV oldSym) 
    542542    where 
    543     takeVar = _cast "$*TAKE" 
     543    takeVar = cast "$*TAKE" 
    544544 
    545545reduceSyn "loop" exps = enterLoop $ do 
     
    643643        names <- forM vars $ \var -> case unwrap var of 
    644644            Var name -> return name 
    645             Syn syn [vexp] 
    646                 | [sigil,':',':','(',')'] <- cast syn 
    647                 , Val (VStr name) <- unwrap vexp 
    648                 -> return $ possiblyFixOperatorName (cast (sigil:cast name)) 
     645            Syn [sigil,':',':','(',')'] [vexp] 
     646                | Val (VStr name) <- unwrap vexp -> return $ possiblyFixOperatorName (cast (sigil:name)) 
    649647            _        -> retError "Cannot bind this as lhs" var 
    650648        bindings <- forM (names `zip` vexps) $ \(var, vexp) -> enterLValue $ do 
     
    729727    -- XXX evil hack for infinite slices 
    730728    | [lhs, App (Var var) invs args] <- unwrap exps 
    731     , var == _cast "&postfix:..." 
     729    , var == cast "&postfix:..." 
    732730    , [idx] <- maybeToList invs ++ args 
    733731--  , not (envLValue env) 
    734732    = reduce (Syn "[...]" [lhs, idx]) 
    735733    | [lhs, App (Var var) invs args] <- unwrap exps 
    736     , var == _cast "&infix:.." 
     734    , var == cast "&infix:.." 
    737735    , [idx, Val (VNum n)] <- maybeToList invs ++ args 
    738736    , n == 1/0 
     
    782780    evalRef ref 
    783781 
     782reduceSyn (sigil:"::()") exps = do 
     783    -- These are all parts of the name 
     784    parts   <- mapM fromVal =<< mapM evalExp exps 
     785    -- Now we only have to add the sigil in front of the string and join 
     786    -- the parts with "::". 
     787    let varname = sigil:(concat . (intersperse "::") $ parts) 
     788    -- Finally, eval the varname. 
     789    reduceVar (possiblyFixOperatorName (cast varname)) 
     790 
    784791reduceSyn "{}" [listExp, indexExp] = do 
    785792    varVal  <- enterLValue $ enterEvalContext (cxtItem "Hash") listExp 
     
    794801 
    795802reduceSyn "rx" [exp, adverbs] = do 
    796     hv      <- fromVal =<< evalExp adverbs :: Eval [(VStr, Val)] 
     803    hv      <- fromVal =<< evalExp adverbs 
    797804    val     <- enterEvalContext (cxtItem "Str") exp 
    798805    str     <- fromVal val 
     
    867874    langVal <- evalExp langExp 
    868875    lang    <- fromVal langVal 
    869     when (lang /= ("Haskell" :: String)) $ 
     876    when (lang /= "Haskell") $ 
    870877        retError "Inline: Unknown language" langVal 
    871878    pkg     <- asks envPackage -- full module name here 
     
    882889    retItem $ castV (key, val) 
    883890 
    884 reduceSyn name [lhsExp, rhsExp] 
    885     | syn <- cast name, last syn == '=' = do 
     891reduceSyn syn [lhsExp, rhsExp] 
     892    | last syn == '=' = do 
    886893        let op = "&infix:" ++ init syn 
    887894        lhs <- enterLValue $ evalExp lhsExp 
     
    929936                return (sub:rest) 
    930937            _         -> return [] 
    931  
    932 reduceSyn name exps | (sigil:"::()") <- cast name = do 
    933     -- These are all parts of the name 
    934     parts   <- mapM fromVal =<< mapM evalExp exps 
    935     -- Now we only have to add the sigil in front of the string and join 
    936     -- the parts with "::". 
    937     let varname = sigil:(concat . (intersperse "::") $ parts) 
    938     -- Finally, eval the varname. 
    939     reduceVar (possiblyFixOperatorName (_cast varname)) 
    940938 
    941939reduceSyn name exps = 
     
    11101108            af (Just (mconcat (resFeed:c_feeds cap))) args 
    11111109        | App (Var var) Nothing capExps <- unwrapN 
    1112         , var == _cast "&prefix:|<<" = do 
     1110        , var == cast "&prefix:|<<" = do 
    11131111            caps    <- mapM castVal =<< fromVals =<< (enterRValue $ enterEvalContext (cxtSlurpy "Capture") (Syn "," capExps)) 
    11141112            af (Just (mconcat (resFeed:concatMap c_feeds caps))) args 
     
    11261124 
    11271125dummyVar :: Var 
    1128 dummyVar = _cast "$" 
     1126dummyVar = cast "$" 
    11291127 
    11301128chainFun :: Params -> Exp -> Params -> Exp -> [Val] -> Eval Val 
     
    12821280        tryAnyComprehension pre (pivot:post) 
    12831281            | App (Var var') _ _    <- unwrap pivot 
    1284             , var' == _cast "&list" = do 
     1282            , var' == cast "&list" = do 
    12851283                -- List comprehension!  This: 
    12861284                --      1 < list(@x) < 2 
     
    13021300applyExp :: SubType -> [ApplyArg] -> Exp -> Eval Val 
    13031301applyExp _ bound (Prim f) = 
    1304     f [ argValue arg | arg <- bound, (argName arg) /= _cast "%_" ] 
     1302    f [ argValue arg | arg <- bound, (argName arg) /= cast "%_" ] 
    13051303applyExp styp [] body = do 
    13061304    applyThunk styp [] $ MkThunk (evalExp body) anyType 
     
    13121310        let name  = dropWhile (not . isAlpha) (cast $ argName arg) 
    13131311            value = argValue arg 
    1314         evalExp $ Syn "=" [Syn "{}" [Val invocant, Val (_VStr name)], Val value] 
     1312        evalExp $ Syn "=" [Syn "{}" [Val invocant, Val (VStr name)], Val value] 
    13151313    applyThunk styp normal $ MkThunk (evalExp body) anyType 
    13161314    where 
     
    13251323    -- introduce self and $_ as the first invocant. 
    13261324    inv     <- case styp of 
    1327         SubPointy               -> aliased [_cast "$_"] 
    1328         _ | styp <= SubMethod   -> aliased [_cast "&self"] -- , "$_"] 
     1325        SubPointy               -> aliased [cast "$_"] 
     1326        _ | styp <= SubMethod   -> aliased [cast "&self"] -- , "$_"] 
    13291327        _                       -> return [] 
    13301328    pad <- formal