Changeset 16415

Show
Ignore:
Timestamp:
05/18/07 00:16:09 (18 months ago)
Author:
audreyt
Message:

* Misc. stylistic cleanups in Pugs.AST and Pugs.Eval.

Location:
src/Pugs
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • src/Pugs/AST.hs

    r16383 r16415  
    375375    { isMulti       = True 
    376376    , subName       = cast name 
    377     , subLexPads    = [] 
     377    , subOuterPads  = [] 
     378    , subInnerPad   = emptyPad 
     379--  , subLexical    = emptyPad 
     380    , subStarted    = Nothing 
    378381    , subPackage    = emptyPkg 
    379382    , subType       = SubMacro 
  • src/Pugs/Eval.hs

    r16383 r16415  
    415415reduceSyn "" [Syn "block" [Val (VCode code)]] = do  
    416416    -- Reclose all global pads! 
    417     glob <- asks envGlobal 
     417    glob    <- asks envGlobal 
    418418    stm $ do 
    419419        pad     <- readMPad glob 
     
    13591359        _                       -> return [] 
    13601360    -} 
    1361     let withInv | styp <= SubMethod = (ApplyArg (cast "&self") (argValue arg) False:) 
     1361    let withInv | styp <= SubMethod = (ApplyArg (cast "$__SELF__") (argValue arg) False:) 
    13621362                | otherwise         = id 
    13631363    sequence_ [ bindVar var val 
     
    13701370bindVar :: Var -> Val -> Eval () 
    13711371bindVar var val 
    1372     | isLexicalVar var  = doBindVar (asks envLexical) 
    1373     | otherwise         = doBindVar askGlobal 
     1372    | isLexicalVar var  = do 
     1373        -- warn "Binding lexical" var 
     1374        doBindVar (asks envLexical) 
     1375    | otherwise         = do 
     1376        -- warn "Binding global" var 
     1377        doBindVar askGlobal 
    13741378    where 
    13751379    doBindVar askPad = do 
     
    13781382            Just PEConstant{} -> fail $ "Cannot rebind constant: " ++ show var 
    13791383            Just c -> do 
     1384                -- warn "Binding lexical on" (var, c) 
    13801385                ref <- fromVal val 
    13811386                stm $ writeTVar (pe_store c) ref 
     
    14201425        -> [Exp]       -- ^ List of arguments (not including explicit invocant) 
    14211426        -> Eval Val 
    1422 doApply appKind sub@MkCode{ subCont = cont, subBody = fun, subType = typ } invs args = do 
     1427doApply appKind origSub@MkCode{ subCont = cont, subBody = fun, subType = typ } invs args = do 
    14231428    realInvs <- fmapM reduceNamedArg invs 
    14241429    realArgs <-  mapM reduceNamedArg args   
     
    14351440            bound <- mapM doBind (subBindings sub) 
    14361441            -- trace (show bound) $ return () 
    1437             val <- local fixEnv $ do 
     1442            val <- localEnv $ do 
    14381443                (`juncApply` bound) $ \realBound -> do 
    1439                     enterSub appKind sub $ case cont of 
    1440                         Just tvar   -> do 
    1441                             thunk <- stm $ readTVar tvar 
    1442                             applyThunk (subType sub) realBound thunk 
    1443                         Nothing     -> applyExp (subType sub) realBound fun 
     1444                    enterSub appKind sub $ do 
     1445                        lex     <- asks envLexical 
     1446                        recRef  <- fromVal (VCode origSub) 
     1447                        let tryRecBind var 
     1448                                | Just{} <- lookupPad var (subInnerPad sub) 
     1449                                , Just c <- lookupPad var lex 
     1450                                = writePadEntry c recRef  
     1451                                | otherwise = return () 
     1452                        tryRecBind (cast "&?BLOCK") 
     1453                        tryRecBind (cast "&?ROUTINE") 
     1454                        case cont of 
     1455                            Just tvar   -> do 
     1456                                thunk <- stm $ readTVar tvar 
     1457                                applyThunk (subType sub) realBound thunk 
     1458                            Nothing     -> applyExp (subType sub) realBound fun 
    14441459            case typ of  
    14451460                SubMacro    -> applyMacroResult val  
     
    14611476    applyMacroResult VUndef         = retEmpty 
    14621477    applyMacroResult _              = fail "Macro did not return an AST, a Str or a Code!" 
     1478    localEnv = case appKind of 
     1479        AKDisplaced  -> enterCaller 
     1480        _            -> id 
    14631481    fixSub sub env = env 
    14641482        { envPackage = subPackage sub 
    14651483        , envLexPads = subOuterPads sub 
    14661484        } 
    1467     fixEnv :: Env -> Env 
    1468     fixEnv | typ >= SubBlock = id 
    1469            | otherwise       = envEnterCaller 
    14701485    doBind :: (Param, Exp) -> Eval ApplyArg -- ([PadMutator], [ApplyArg]) 
    14711486    doBind (prm, exp) = do 
     
    14741489        (val, coll) <- enterContext cxt $ case exp of 
    14751490            Syn "param-default" [exp, Val (VCode sub)] -> do 
    1476                 local (fixEnv . fixSub sub) $ expToVal prm exp 
     1491                localEnv . local (fixSub sub) $ expToVal prm exp 
    14771492            _  -> expToVal prm exp 
    14781493        -- traceM ("==> " ++ (show val))