Changeset 16416

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

* Pugs.Parser: Each symbol is now exported exactly once -- the

old %EXPORT treatment of putting each multi variant into its
own array element is now replaced by simply exporting the
toplevel proto/multi sub.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • src/Pugs/Parser.hs

    r16392 r16416  
    389389            `finallyM` clearDynParsers 
    390390 
    391     -- XXX - Generate init pad for each of our params... 
    392  
     391    -- Generate init pad for each of our params, as well as for ourselves... 
    393392    paramsPad   <- genParamEntries styp signature 
    394393    modify $ \s -> s{ s_protoPad = paramsPad } 
     
    409408                , subOuterPads  = envLexPads env 
    410409                , subInnerPad   = bi_pad block 
     410                , subTraitBlocks= bi_traits block (subTraitBlocks template) 
    411411                } 
    412         sub = VCode (bi_traits block template') 
     412        sub = VCode template' 
    413413     
    414414    -- Don't add the sub if it's unsafe and we're in safemode. 
     
    436436                                , subParams = multiSig 
    437437                                } 
    438                     unsafeEvalExp $ Syn "|=" 
     438                    unsafeEvalExp $ Syn "=" 
    439439                        [ Syn "{}" [_Var ("%" ++ pkg ++ "::EXPORTS"), Val $ VStr exportedName] 
    440440                        , Val exportedSub 
     
    937937        fail "Closure traits take no formal parameters" 
    938938    env <- ask 
    939     let code = VCode mkSub 
     939    let code = mkSub 
    940940            { subName       = cast name 
    941             , subType       = SubRoutine -- XXX - This should be SubBlock - See Pugs.Monads.enterSub for "displaced" subs 
     941            , subType       = SubBlock 
    942942            , subBody       = fun 
     943            , subPackage    = envPackage env 
    943944            , subInnerPad   = (bi_pad block) 
    944945            , subOuterPads  = (PCompiling (fromJust $ envCompPad env):envLexPads env) 
     
    10111012possiblyExit x = return x 
    10121013 
    1013 vcode2startBlock :: Val -> RuleParser Exp 
    1014 vcode2startBlock (VCode code) = do 
     1014vcode2memoized :: VCode -> RuleParser VCode 
     1015vcode2memoized code = do 
    10151016    -- Ok. Now the tricky thing. 
    10161017    -- This is the general idea: 
     
    10291030        (_Sym SState "$?START_RUN" mempty emptyExp) $ emptyExp 
    10301031 
    1031     let code' = code{ subBody = body', subInnerPad = subInnerPad code `mappend` lexDiff } 
    1032         body' = Syn "if" 
     1032    let body' = Syn "if" 
    10331033                    [ App (_Var "&postfix:++") Nothing [_Var "$?START_RUN"] 
    10341034                    , _Var "$?START_RESULT" 
     
    10361036                    ]   --  { $?START_RUN++; $?START_RESULT = 42 }; 
    10371037 
     1038    return $ code 
     1039        { subBody     = body' 
     1040        , subInnerPad = subInnerPad code `mappend` lexDiff 
     1041        } 
     1042 
     1043vcode2startBlock :: Val -> RuleParser Exp 
     1044vcode2startBlock ~(VCode code) = do 
     1045    code'   <- vcode2memoized code 
    10381046    return $ App (Syn "sub" [Val (VCode code')]) Nothing [] 
    1039 vcode2startBlock _ = fail "impossible" 
    10401047 
    10411048vcode2initBlock :: Val -> RuleParser Exp 
     
    10471054 
    10481055vcode2checkBlock :: Val -> RuleParser Exp 
    1049 vcode2checkBlock code = do 
    1050     body    <- vcode2startBlock code 
    1051     let fstcode = Syn "sub" [ checkForIOLeak mkSub{ subBody = body } ] 
     1056vcode2checkBlock ~(VCode code) = do 
     1057    code'   <- vcode2memoized code 
    10521058    Val res <- unsafeEvalExp $ 
    10531059        App (_Var "&unshift") (Just $ _Var "@*CHECK") [ Val (VCode code') ] 
     
    12871293        fail "Cannot mix placeholder variables with formal parameters" 
    12881294    env <- ask 
    1289     let sub = bi_traits block $ mkCode 
     1295    let sub = mkCode 
    12901296            { isMulti       = False 
    12911297            , subName       = __"<anon>" 
     
    13261332    return $ (SubPointy, params, "rw" `elem` traits) 
    13271333 
     1334genNameTypeEntries :: Scope -> [(String, VType, EntryFlags, Exp)] -> RuleParser Pad 
    13281335genNameTypeEntries scope nameTypes = do 
    13291336    unsafeEvalLexDiff $ combine (map makeBinding nameTypes) emptyExp 
     
    13381345        bindSym     = Stmts (Syn "=" [_Var name, Val (VType typ)]) 
    13391346 
     1347paramsToNameTypes :: [Param] -> String -> [(String, Type, EntryFlags, Exp)] 
    13401348paramsToNameTypes params defType = [ (n, t, f, d) | n <- names | t <- types | f <- flags | d <- defs ] 
    13411349    where 
     
    13491357        | otherwise                     = t 
    13501358 
    1351 genParamEntries styp params 
    1352     | styp >= SubBlock  = genNameTypeEntries SMy nameTypes 
    1353     | otherwise         = genNameTypeEntries SMy (foldl' withImplicit nameTypes implicitNames) 
     1359genParamEntries :: SubType -> Params -> RuleParser Pad 
     1360genParamEntries styp params = genNameTypeEntries SMy (foldl' withImplicit nameTypes implicitNames) 
    13541361    where 
    1355     nameTypes       = paramsToNameTypes params "" 
     1362    params' 
     1363        | SubMethod <- styp = (defaultSelfParam:params) 
     1364        | otherwise         = params 
     1365    nameTypes       = paramsToNameTypes params' "" 
    13561366    names           = Set.fromList $ map (\(n, _, _, _) -> n) nameTypes 
    1357     implicitNames   = ["$_"] -- , "$/", "$!"] 
     1367    implicitNames   = case styp of 
     1368        SubPrim     -> [] 
     1369        SubPointy   -> ["&?BLOCK"] -- , "$/", "$!"] 
     1370        SubBlock    -> ["$_", "&?BLOCK"] -- , "$/", "$!"] 
     1371        _           -> ["$_", "&?BLOCK", "&?ROUTINE"] -- , "$/", "$!"] 
    13581372    withImplicit ntys name 
    13591373        | Set.member (cast name) names  = ntys 
    13601374        | otherwise                     = (((cast name), anyType, MkEntryFlags True, Noop):ntys) 
     1375    defaultSelfParam = buildParam "" "" "$__SELF__" (Val VUndef) 
    13611376 
    13621377ruleVarDecl :: RuleParser Exp 
     
    20632078        _ -> do 
    20642079            -- Plain and simple variable -- do a lexical check 
    2065             -- Algorithm: Navigate outerward to find the first one defined; 
    2066             --            record the  
     2080            -- First check if it's "known". 
     2081            --   If it is, then simply makeVar. 
     2082            --   If it is not, then it's "free"; add it to the list of freeVars 
     2083            --   for the final check. 
     2084 
    20672085            state <- get 
    20682086