Changeset 16417
- Timestamp:
- 05/18/07 00:18:48 (18 months ago)
- Location:
- src/Pugs/Parser
- Files:
-
- 3 modified
Legend:
- Unmodified
- Added
- Removed
-
src/Pugs/Parser/Program.hs
r16383 r16417 174 174 block{ bi_body = mergeStmts emptyExp $ bi_body block } 175 175 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 176 182 -- S04: CHECK {...}* at compile time, ALAP 177 183 -- $_() for @*CHECK … … 190 196 possiblyExit rv 191 197 192 -- Force a reclose-pad evaluation here by way of unsafeEvalExp.193 main'@(Val (VCode vc)) <- unsafeEvalExp $ Syn "" [unwrap main]194 195 198 env' <- getRuleEnv 196 199 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"] 198 201 , envPackage = envPackage env 199 202 , envCompPad = Nothing -
src/Pugs/Parser/Types.hs
r16379 r16417 4 4 RuleParser, RuleState(..), CharClass(..), 5 5 DynParsers(..), ParensOption(..), FormalsOption(..), BracketLevel(..), OuterLevel, 6 CodeMutator,BlockInfo(..), emptyBlockInfo,6 BlockInfo(..), emptyBlockInfo, 7 7 8 8 RuleOperator, RuleOperatorTable, … … 28 28 data BlockInfo = MkBlockInfo 29 29 { bi_pad :: !Pad 30 , bi_traits :: ! CodeMutator30 , bi_traits :: !(TraitBlocks -> TraitBlocks) 31 31 , bi_body :: !Exp 32 32 } … … 140 140 { s_env :: Env 141 141 , 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 154 156 , s_closureTraits :: [TraitBlocks -> TraitBlocks] 155 157 -- ^ Closure traits: head is this block, tail is all outer blocks 156 158 } 157 158 type CodeMutator = VCode -> VCode159 159 160 160 data BracketLevel … … 250 250 addBlockPad :: Pad -> RuleParser () 251 251 addBlockPad 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) {} } }. 253 256 state <- get 254 257 let myVars = padKeys pad -
src/Pugs/Parser/Util.hs
r16379 r16417 24 24 state <- get 25 25 26 compPad <- return $! unsafePerformSTM $! newTVar emptyPad 26 -- XXX - Perhaps clone the protopad right here, for $_ etc? 27 compPad <- newMPad (s_protoPad state) 28 27 29 -- traceM $ "Gen:" ++ show compPad 28 30 let env = s_env state 29 lexPads = ( pad:envLexPads env)31 lexPads = (PCompiling compPad:envLexPads env) 30 32 31 33 put state … … 57 59 , s_closureTraits = outerTraits 58 60 , s_knownVars = outerKnownVars 59 , s_outerVars = Map.filter (/= compPad) (s_outerVars state') 61 , s_outerVars = outerOuterVars 62 , s_protoPad = emptyPad 60 63 } 61 64 … … 67 70 let newEntry = entry{ pe_proto = proto } 68 71 return (newEntry `seq` (var, newEntry)) 69 newPad <-listToPad (length entries `seq` entries)72 let newPad = listToPad (length entries `seq` entries) 70 73 writeMPad compPad newPad 71 74 return newPad
