Changeset 6424

Show
Ignore:
Timestamp:
08/23/05 22:18:24 (3 years ago)
Author:
iblech
Message:

* Pugs.PIL1: Added pSubLValue/pLValue to PSub and PCode, indicating the

difference between "sub foo {...}" and "sub foo is rw {...}".

* Pugs.Compile: Extract the (subLValue vcode) and put in in the appropriate

field of PSub/PCode.

* Pugs.CodeGen?.PIR: Accomodate for the above changes.
* Pugs.Parser: Parse traits for anonymous subs, too (i.e. "sub () is rw

{...}" parses and works now).

Location:
src/Pugs
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • src/Pugs/CodeGen/PIR.hs

    r6248 r6424  
    106106        tellLabel endL 
    107107        return (ExpLV this) 
    108     trans (PCode styp params body) = do 
     108    trans (PCode styp params _ body) = do 
    109109        [begL, endL] <- genLabel ["blockBegin", "blockEnd"] 
    110110        this    <- genPMC "block" 
     
    126126 
    127127instance Translate PIL_Decl Decl where 
    128     trans (PSub name styp params body) | Just (pkg, name') <- isQualified name = do 
    129         declC <- trans $ PSub name' styp params body 
     128    trans (PSub name styp params lvalue body) | Just (pkg, name') <- isQualified name = do 
     129        declC <- trans $ PSub name' styp params lvalue body 
    130130        return $ DeclNS pkg [declC] 
    131     trans (PSub name styp params body) = do 
     131    trans (PSub name styp params _ body) = do 
    132132        (_, stmts)  <- listen $ do 
    133133            let prms = map tpParam params 
     
    186186        tellIns $ lhsC <:= rhsC 
    187187        return lhsC 
    188     trans (PApp _ exp@(PCode _ _ _) Nothing []) = do 
     188    trans (PApp _ exp@(PCode _ _ _ _) Nothing []) = do 
    189189        blockC  <- trans exp 
    190190        tellIns $ [reg tempPMC] <-& blockC $ [] 
     
    383383            , InsNew tempPMC PerlScalar 
    384384            , "store_global"    .- [lit "$_", tempPMC] 
    385             ]) ++ [ StmtRaw (text (name ++ "()")) | PSub name@('_':'_':_) _ _ _ <- pilGlob penv ] ++ 
     385            ]) ++ [ StmtRaw (text (name ++ "()")) | PSub name@('_':'_':_) _ _ _ _ <- pilGlob penv ] ++ 
    386386            [ StmtRaw (text "main()") 
    387387            , StmtIns $ tempPMC  <-- "find_global" $ [lit "Perl6::Internals", lit "&exit"] 
  • src/Pugs/Compile.hs

    r6248 r6424  
    105105                name' | ':' `elem` name = name 
    106106                      | otherwise = "main::" ++ name -- XXX wrong 
    107             return [PSub initL SubPrim [] bodyC] 
     107            return [PSub initL SubPrim [] False bodyC] 
    108108        canCompile _ = return [] 
    109109        doCode name vsub = case subBody vsub of 
     
    117117    compile (name, decls) = do 
    118118        let bodyC = [ PStmts . PStmt . PExp $ PApp tcVoid (PExp (PVar sub)) Nothing [] 
    119                     | PSub sub _ _ _ <- decls 
     119                    | PSub sub _ _ _ _ <- decls 
    120120                    ] 
    121         return (PSub name SubPrim [] (combine bodyC PNil):decls) 
     121        return (PSub name SubPrim [] False (combine bodyC PNil):decls) 
    122122 
    123123instance Compile (SubName, VCode) [PIL_Decl] where 
     
    126126            bodyC   = PStmts (PStmt . PExp $ storeC) PNil 
    127127            exportL = "__export_" ++ (render $ varText name) 
    128         return [PSub exportL SubPrim [] bodyC] 
     128        return [PSub exportL SubPrim [] False bodyC] 
    129129    compile (name, vsub) = do 
    130130        bodyC   <- enter cxtItemAny . compile $ case subBody vsub of 
     
    132132            body                -> body 
    133133        paramsC <- compile $ subParams vsub 
    134         return [PSub name (subType vsub) paramsC bodyC] 
     134        return [PSub name (subType vsub) paramsC (subLValue vsub) bodyC] 
    135135 
    136136instance Compile (String, [(TVar Bool, TVar VRef)]) PIL_Expr where 
     
    228228 
    229229pBlock :: PIL_Stmts -> PIL_Expr 
    230 pBlock = PCode SubBlock [] 
     230pBlock = PCode SubBlock [] False 
    231231 
    232232{- 
     
    356356            exp                 -> exp 
    357357        paramsC <- compile $ subParams sub 
    358         return $ PCode (subType sub) paramsC bodyC 
     358        return $ PCode (subType sub) paramsC (subLValue sub) bodyC 
    359359    compile (Syn "module" _) = compile Noop 
    360360    compile (Syn "match" exp) = compile $ Syn "rx" exp -- wrong 
  • src/Pugs/PIL1.hs

    r6385 r6424  
    7272        { pType    :: !SubType 
    7373        , pParams  :: ![TParam] 
     74        , pLValue  :: !Bool 
    7475        , pBody    :: !PIL_Stmts 
    7576        } 
     
    8081    , pSubType      :: !SubType 
    8182    , pSubParams    :: ![TParam] 
     83    , pSubLValue    :: !Bool 
    8284    , pSubBody      :: !PIL_Stmts 
    8385    } 
     
    256258            putByte bh 3 
    257259            put_ bh ad 
    258     put_ bh (PCode ae af ag) = do 
     260    put_ bh (PCode ae af ag ah) = do 
    259261            putByte bh 4 
    260262            put_ bh ae 
    261263            put_ bh af 
    262264            put_ bh ag 
     265            put_ bh ah 
    263266    get bh = do 
    264267            h <- getByte bh 
     
    280283                    af <- get bh 
    281284                    ag <- get bh 
    282                     return (PCode ae af ag) 
     285                    ah <- get bh 
     286                    return (PCode ae af ag ah) 
    283287 
    284288instance Perl5 PIL_Expr where 
     
    289293    showPerl5 (PThunk aa) = showP5HashObj "PThunk" 
    290294              [("pThunk", showPerl5 aa)] 
    291     showPerl5 (PCode aa ab ac) = showP5HashObj "PCode" 
     295    showPerl5 (PCode aa ab ac ad) = showP5HashObj "PCode" 
    292296              [("pType", showPerl5 aa) , ("pParams", showPerl5 ab) , 
    293                ("pBody", showPerl5 ac)] 
     297               ("pLValue", showPerl5 ac) , ("pBody", showPerl5 ad)] 
    294298 
    295299instance JSON PIL_Expr where 
     
    300304    showJSON (PThunk aa) = showJSHashObj "PThunk" 
    301305             [("pThunk", showJSON aa)] 
    302     showJSON (PCode aa ab ac) = showJSHashObj "PCode" 
     306    showJSON (PCode aa ab ac ad) = showJSHashObj "PCode" 
    303307             [("pType", showJSON aa) , ("pParams", showJSON ab) , 
    304               ("pBody", showJSON ac)] 
     308              ("pLValue", showJSON ac) , ("pBody", showJSON ad)] 
    305309 
    306310instance Binary PIL_Decl where 
    307     put_ bh (PSub aa ab ac ad) = do 
    308             put_ bh aa 
    309             put_ bh ab 
    310             put_ bh ac 
    311             put_ bh ad 
     311    put_ bh (PSub aa ab ac ad ae) = do 
     312            put_ bh aa 
     313            put_ bh ab 
     314            put_ bh ac 
     315            put_ bh ad 
     316            put_ bh ae 
    312317    get bh = do 
    313318    aa <- get bh 
     
    315320    ac <- get bh 
    316321    ad <- get bh 
    317     return (PSub aa ab ac ad) 
     322    ae <- get bh 
     323    return (PSub aa ab ac ad ae) 
    318324 
    319325instance Perl5 PIL_Decl where 
    320     showPerl5 (PSub aa ab ac ad) = showP5HashObj "PSub" 
     326    showPerl5 (PSub aa ab ac ad ae) = showP5HashObj "PSub" 
    321327              [("pSubName", showPerl5 aa) , ("pSubType", showPerl5 ab) , 
    322                ("pSubParams", showPerl5 ac) , ("pSubBody", showPerl5 ad)] 
     328               ("pSubParams", showPerl5 ac) , ("pSubLValue", showPerl5 ad) , 
     329               ("pSubBody", showPerl5 ae)] 
    323330 
    324331instance JSON PIL_Decl where 
    325     showJSON (PSub aa ab ac ad) = showJSHashObj "PSub" 
     332    showJSON (PSub aa ab ac ad ae) = showJSHashObj "PSub" 
    326333             [("pSubName", showJSON aa) , ("pSubType", showJSON ab) , 
    327               ("pSubParams", showJSON ac) , ("pSubBody", showJSON ad)] 
     334              ("pSubParams", showJSON ac) , ("pSubLValue", showJSON ad) , 
     335              ("pSubBody", showJSON ae)] 
    328336 
    329337instance Binary PIL_Literal where 
  • src/Pugs/PIL1.hs-drift

    r6379 r6424  
    7070        { pType    :: !SubType 
    7171        , pParams  :: ![TParam] 
     72        , pLValue  :: !Bool 
    7273        , pBody    :: !PIL_Stmts 
    7374        } 
     
    7879    , pSubType      :: !SubType 
    7980    , pSubParams    :: ![TParam] 
     81    , pSubLValue    :: !Bool 
    8082    , pSubBody      :: !PIL_Stmts 
    8183    } 
  • src/Pugs/Parser.hs

    r6396 r6424  
    9898ruleStandaloneBlock = tryRule "standalone block" $ do 
    9999    body <- bracesAlone ruleBlockBody 
    100     retBlock SubBlock Nothing body 
     100    retBlock SubBlock Nothing False body 
    101101    where 
    102102    bracesAlone p  = between (symbol "{") closingBrace p 
     
    10171017    exp <- ruleExpression 
    10181018    return $ \body -> do 
    1019         block <- retBlock SubBlock Nothing body 
     1019        block <- retBlock SubBlock Nothing False body 
    10201020        retSyn cond [exp, block] 
    10211021 
    10221022ruleBlockLiteral :: RuleParser Exp 
    10231023ruleBlockLiteral = rule "block construct" $ do 
    1024     (typ, formal) <- option (SubBlock, Nothing) $ choice 
     1024    (typ, formal, lvalue) <- option (SubBlock, Nothing, False) $ choice 
    10251025        [ ruleBlockFormalPointy 
    10261026        , ruleBlockFormalStandard 
    10271027        ] 
    10281028    body <- ruleBlock 
    1029     retBlock typ formal body 
     1029    retBlock typ formal lvalue body 
    10301030 
    10311031extractHash :: Exp -> Maybe Exp 
     
    10371037extractHash _ = Nothing 
    10381038 
    1039 retBlock :: SubType -> Maybe [Param] -> Exp -> RuleParser Exp 
    1040 retBlock SubBlock Nothing exp | Just hashExp <- extractHash (unwrap exp) = return $ Syn "\\{}" [hashExp] 
    1041 retBlock typ formal body = retVerbatimBlock typ formal body 
    1042  
    1043 retVerbatimBlock :: SubType -> Maybe [Param] -> Exp -> RuleParser Exp 
    1044 retVerbatimBlock styp formal body = expRule $ do 
     1039retBlock :: SubType -> Maybe [Param] -> Bool -> Exp -> RuleParser Exp 
     1040retBlock SubBlock Nothing _ exp | Just hashExp <- extractHash (unwrap exp) = return $ Syn "\\{}" [hashExp] 
     1041retBlock typ formal lvalue body = retVerbatimBlock typ formal lvalue body 
     1042 
     1043retVerbatimBlock :: SubType -> Maybe [Param] -> Bool -> Exp -> RuleParser Exp 
     1044retVerbatimBlock styp formal lvalue body = expRule $ do 
    10451045    let (fun, names, params) = doExtract styp formal body 
    10461046    -- Check for placeholder vs formal parameters 
     
    10551055            , subAssoc      = "pre" 
    10561056            , subReturns    = anyType 
    1057             , subLValue     = False -- XXX "is rw" 
     1057            , subLValue     = lvalue 
    10581058            , subParams     = paramsFor styp formal params 
    10591059            , subBindings   = [] 
     
    10761076defaultParamFor _           = [defaultArrayParam] 
    10771077 
    1078 ruleBlockFormalStandard :: RuleParser (SubType, Maybe [Param]) 
     1078ruleBlockFormalStandard :: RuleParser (SubType, Maybe [Param], Bool) 
    10791079ruleBlockFormalStandard = rule "standard block parameters" $ do 
    10801080    styp <- choice 
     
    10841084        ] 
    10851085    params <- option Nothing $ ruleSubParameters ParensMandatory 
    1086     return $ (styp, params) 
    1087  
    1088 ruleBlockFormalPointy :: RuleParser (SubType, Maybe [Param]) 
     1086    traits <- many $ ruleTrait 
     1087    return $ (styp, params, "rw" `elem` traits) 
     1088 
     1089ruleBlockFormalPointy :: RuleParser (SubType, Maybe [Param], Bool) 
    10891090ruleBlockFormalPointy = rule "pointy block parameters" $ do 
    10901091    symbol "->" 
    10911092    params <- ruleSubParameters ParensOptional 
    1092     return $ (SubPointy, params) 
     1093    traits <- many $ ruleTrait 
     1094    return $ (SubPointy, params, "rw" `elem` traits) 
    10931095 
    10941096