Changeset 16417

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

* Pugs.Parser.*: More cleanups; fake a compPad so CHECK blocks

still thinks they are running in compile time, even though
nothing really is under compilation.

Location:
src/Pugs/Parser
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • src/Pugs/Parser/Program.hs

    r16383 r16417  
    174174        block{ bi_body = mergeStmts emptyExp $ bi_body block } 
    175175 
     176    -- We are still in the compile time. 
     177    modify $ \s -> s{ s_env = (s_env s){ envCompPad = Just (error "no comp pad") } } 
     178 
     179    -- Force a reclose-pad evaluation here by way of unsafeEvalExp. 
     180    main'@(Val (VCode vc)) <- unsafeEvalExp $ Syn "" [unwrap main] 
     181 
    176182    -- S04: CHECK {...}*      at compile time, ALAP 
    177183    --  $_() for @*CHECK 
     
    190196    possiblyExit rv 
    191197 
    192     -- Force a reclose-pad evaluation here by way of unsafeEvalExp. 
    193     main'@(Val (VCode vc)) <- unsafeEvalExp $ Syn "" [unwrap main] 
    194  
    195198    env' <- getRuleEnv 
    196199    return $ env' 
    197         { envBody       = App (Syn "block" [main']) Nothing (replicate (length $ subParams vc) (_Var "$*_")) -- _Var "@*ARGS"] 
     200        { envBody       = App (Syn "block" [main']) Nothing (replicate (length $ subParams vc) (_Var "$_")) -- _Var "@*ARGS"] 
    198201        , envPackage    = envPackage env 
    199202        , envCompPad    = Nothing 
  • src/Pugs/Parser/Types.hs

    r16379 r16417  
    44    RuleParser, RuleState(..), CharClass(..), 
    55    DynParsers(..), ParensOption(..), FormalsOption(..), BracketLevel(..), OuterLevel, 
    6     CodeMutator, BlockInfo(..), emptyBlockInfo, 
     6    BlockInfo(..), emptyBlockInfo, 
    77 
    88    RuleOperator, RuleOperatorTable, 
     
    2828data BlockInfo = MkBlockInfo 
    2929    { bi_pad    :: !Pad 
    30     , bi_traits :: !CodeMutator 
     30    , bi_traits :: !(TraitBlocks -> TraitBlocks) 
    3131    , bi_body   :: !Exp 
    3232    } 
     
    140140    { s_env           :: Env 
    141141    , s_parseProgram  :: (Env -> FilePath -> String -> Env) 
    142     , s_dynParsers    :: DynParsers     -- ^ Cache for dynamically-generated 
    143                                         --     parsers 
    144     , s_bracketLevel  :: !BracketLevel  -- ^ The kind of "bracket" we are in 
    145                                         --     part and has to suppress {..} literals 
    146 --  , s_char          :: Char           -- ^ What the previous character contains 
    147 --  , s_name          :: !ID            -- ^ Capture name 
    148 --  , s_pos           :: !Int           -- ^ Capture position 
    149     , s_wsLine        :: !Line          -- ^ Last whitespace position 
    150     , s_wsColumn      :: !Column        -- ^ Last whitespace position 
    151 --  , s_blockPads     :: Map Scope Pad  -- ^ Hoisted pad for this block 
    152     , s_outerVars     :: Map Var (TVar Pad) -- ^ OUTER symbols we remembers, and the scope it associates with 
    153                                         
     142    , s_dynParsers    :: DynParsers         -- ^ Cache for dynamically-generated 
     143                                            --     parsers 
     144    , s_bracketLevel  :: !BracketLevel      -- ^ The kind of "bracket" we are in 
     145                                            --     part and has to suppress {..} literals 
     146--  , s_char          :: Char               -- ^ What the previous character contains 
     147--  , s_name          :: !ID                -- ^ Capture name 
     148--  , s_pos           :: !Int               -- ^ Capture position 
     149    , s_wsLine        :: !Line              -- ^ Last whitespace position 
     150    , s_wsColumn      :: !Column            -- ^ Last whitespace position 
     151--  , s_blockPads     :: Map Scope Pad      -- ^ Hoisted pad for this block 
     152    , s_knownVars     :: !(Map Var MPad)        -- ^ Map from variables to its associated scope 
     153    , s_outerVars     :: !(Map MPad (Set Var))  -- ^ Map from scopes to vars that must not be declared in it 
     154    , s_freeVars      :: !(Set (Var, LexPads))  -- ^ Set of free vars and the mpadlist to check with 
     155    , s_protoPad      :: !Pad                   -- ^ Pad that's part of all scopes; used in param init 
    154156    , s_closureTraits :: [TraitBlocks -> TraitBlocks] 
    155157                                       -- ^ Closure traits: head is this block, tail is all outer blocks 
    156158    } 
    157  
    158 type CodeMutator = VCode -> VCode 
    159159 
    160160data BracketLevel 
     
    250250addBlockPad :: Pad -> RuleParser () 
    251251addBlockPad pad = do 
    252     -- First we check that our pad does not contain shadows OUTER symbols. 
     252    -- To add a Pad to the COMPILING block, we do two things: 
     253    -- First, we check that our pad does not contain shadowed OUTER symbols. 
     254    -- XXX TODO: it should be fine for two identical padEntry to shadow each other, 
     255    --     as is the case with { our multi f () {}; { &f(); our multi f ($x) {} } }. 
    253256    state <- get 
    254257    let myVars          = padKeys pad 
  • src/Pugs/Parser/Util.hs

    r16379 r16417  
    2424    state   <- get 
    2525 
    26     compPad <- return $! unsafePerformSTM $! newTVar emptyPad 
     26    -- XXX - Perhaps clone the protopad right here, for $_ etc? 
     27    compPad <- newMPad (s_protoPad state) 
     28 
    2729    -- traceM $ "Gen:" ++ show compPad 
    2830    let env     = s_env state 
    29         lexPads = (pad:envLexPads env) 
     31        lexPads = (PCompiling compPad:envLexPads env) 
    3032 
    3133    put state 
     
    5759        , s_closureTraits = outerTraits 
    5860        , s_knownVars     = outerKnownVars 
    59         , s_outerVars     = Map.filter (/= compPad) (s_outerVars state') 
     61        , s_outerVars     = outerOuterVars 
     62        , s_protoPad      = emptyPad 
    6063        } 
    6164 
     
    6770            let newEntry = entry{ pe_proto = proto } 
    6871            return (newEntry `seq` (var, newEntry)) 
    69         newPad <- listToPad (length entries `seq` entries) 
     72        let newPad = listToPad (length entries `seq` entries) 
    7073        writeMPad compPad newPad 
    7174        return newPad