Changeset 6424
- Timestamp:
- 08/23/05 22:18:24 (3 years ago)
- Location:
- src/Pugs
- Files:
-
- 5 modified
-
CodeGen/PIR.hs (modified) (4 diffs)
-
Compile.hs (modified) (6 diffs)
-
PIL1.hs (modified) (7 diffs)
-
PIL1.hs-drift (modified) (2 diffs)
-
Parser.hs (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Pugs/CodeGen/PIR.hs
r6248 r6424 106 106 tellLabel endL 107 107 return (ExpLV this) 108 trans (PCode styp params body) = do108 trans (PCode styp params _ body) = do 109 109 [begL, endL] <- genLabel ["blockBegin", "blockEnd"] 110 110 this <- genPMC "block" … … 126 126 127 127 instance Translate PIL_Decl Decl where 128 trans (PSub name styp params body) | Just (pkg, name') <- isQualified name = do129 declC <- trans $ PSub name' styp params body128 trans (PSub name styp params lvalue body) | Just (pkg, name') <- isQualified name = do 129 declC <- trans $ PSub name' styp params lvalue body 130 130 return $ DeclNS pkg [declC] 131 trans (PSub name styp params body) = do131 trans (PSub name styp params _ body) = do 132 132 (_, stmts) <- listen $ do 133 133 let prms = map tpParam params … … 186 186 tellIns $ lhsC <:= rhsC 187 187 return lhsC 188 trans (PApp _ exp@(PCode _ _ _ ) Nothing []) = do188 trans (PApp _ exp@(PCode _ _ _ _) Nothing []) = do 189 189 blockC <- trans exp 190 190 tellIns $ [reg tempPMC] <-& blockC $ [] … … 383 383 , InsNew tempPMC PerlScalar 384 384 , "store_global" .- [lit "$_", tempPMC] 385 ]) ++ [ StmtRaw (text (name ++ "()")) | PSub name@('_':'_':_) _ _ _ <- pilGlob penv ] ++385 ]) ++ [ StmtRaw (text (name ++ "()")) | PSub name@('_':'_':_) _ _ _ _ <- pilGlob penv ] ++ 386 386 [ StmtRaw (text "main()") 387 387 , StmtIns $ tempPMC <-- "find_global" $ [lit "Perl6::Internals", lit "&exit"] -
src/Pugs/Compile.hs
r6248 r6424 105 105 name' | ':' `elem` name = name 106 106 | otherwise = "main::" ++ name -- XXX wrong 107 return [PSub initL SubPrim [] bodyC]107 return [PSub initL SubPrim [] False bodyC] 108 108 canCompile _ = return [] 109 109 doCode name vsub = case subBody vsub of … … 117 117 compile (name, decls) = do 118 118 let bodyC = [ PStmts . PStmt . PExp $ PApp tcVoid (PExp (PVar sub)) Nothing [] 119 | PSub sub _ _ _ <- decls119 | PSub sub _ _ _ _ <- decls 120 120 ] 121 return (PSub name SubPrim [] (combine bodyC PNil):decls)121 return (PSub name SubPrim [] False (combine bodyC PNil):decls) 122 122 123 123 instance Compile (SubName, VCode) [PIL_Decl] where … … 126 126 bodyC = PStmts (PStmt . PExp $ storeC) PNil 127 127 exportL = "__export_" ++ (render $ varText name) 128 return [PSub exportL SubPrim [] bodyC]128 return [PSub exportL SubPrim [] False bodyC] 129 129 compile (name, vsub) = do 130 130 bodyC <- enter cxtItemAny . compile $ case subBody vsub of … … 132 132 body -> body 133 133 paramsC <- compile $ subParams vsub 134 return [PSub name (subType vsub) paramsC bodyC]134 return [PSub name (subType vsub) paramsC (subLValue vsub) bodyC] 135 135 136 136 instance Compile (String, [(TVar Bool, TVar VRef)]) PIL_Expr where … … 228 228 229 229 pBlock :: PIL_Stmts -> PIL_Expr 230 pBlock = PCode SubBlock [] 230 pBlock = PCode SubBlock [] False 231 231 232 232 {- … … 356 356 exp -> exp 357 357 paramsC <- compile $ subParams sub 358 return $ PCode (subType sub) paramsC bodyC358 return $ PCode (subType sub) paramsC (subLValue sub) bodyC 359 359 compile (Syn "module" _) = compile Noop 360 360 compile (Syn "match" exp) = compile $ Syn "rx" exp -- wrong -
src/Pugs/PIL1.hs
r6385 r6424 72 72 { pType :: !SubType 73 73 , pParams :: ![TParam] 74 , pLValue :: !Bool 74 75 , pBody :: !PIL_Stmts 75 76 } … … 80 81 , pSubType :: !SubType 81 82 , pSubParams :: ![TParam] 83 , pSubLValue :: !Bool 82 84 , pSubBody :: !PIL_Stmts 83 85 } … … 256 258 putByte bh 3 257 259 put_ bh ad 258 put_ bh (PCode ae af ag ) = do260 put_ bh (PCode ae af ag ah) = do 259 261 putByte bh 4 260 262 put_ bh ae 261 263 put_ bh af 262 264 put_ bh ag 265 put_ bh ah 263 266 get bh = do 264 267 h <- getByte bh … … 280 283 af <- get bh 281 284 ag <- get bh 282 return (PCode ae af ag) 285 ah <- get bh 286 return (PCode ae af ag ah) 283 287 284 288 instance Perl5 PIL_Expr where … … 289 293 showPerl5 (PThunk aa) = showP5HashObj "PThunk" 290 294 [("pThunk", showPerl5 aa)] 291 showPerl5 (PCode aa ab ac ) = showP5HashObj "PCode"295 showPerl5 (PCode aa ab ac ad) = showP5HashObj "PCode" 292 296 [("pType", showPerl5 aa) , ("pParams", showPerl5 ab) , 293 ("p Body", showPerl5 ac)]297 ("pLValue", showPerl5 ac) , ("pBody", showPerl5 ad)] 294 298 295 299 instance JSON PIL_Expr where … … 300 304 showJSON (PThunk aa) = showJSHashObj "PThunk" 301 305 [("pThunk", showJSON aa)] 302 showJSON (PCode aa ab ac ) = showJSHashObj "PCode"306 showJSON (PCode aa ab ac ad) = showJSHashObj "PCode" 303 307 [("pType", showJSON aa) , ("pParams", showJSON ab) , 304 ("p Body", showJSON ac)]308 ("pLValue", showJSON ac) , ("pBody", showJSON ad)] 305 309 306 310 instance 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 312 317 get bh = do 313 318 aa <- get bh … … 315 320 ac <- get bh 316 321 ad <- get bh 317 return (PSub aa ab ac ad) 322 ae <- get bh 323 return (PSub aa ab ac ad ae) 318 324 319 325 instance Perl5 PIL_Decl where 320 showPerl5 (PSub aa ab ac ad ) = showP5HashObj "PSub"326 showPerl5 (PSub aa ab ac ad ae) = showP5HashObj "PSub" 321 327 [("pSubName", showPerl5 aa) , ("pSubType", showPerl5 ab) , 322 ("pSubParams", showPerl5 ac) , ("pSubBody", showPerl5 ad)] 328 ("pSubParams", showPerl5 ac) , ("pSubLValue", showPerl5 ad) , 329 ("pSubBody", showPerl5 ae)] 323 330 324 331 instance JSON PIL_Decl where 325 showJSON (PSub aa ab ac ad ) = showJSHashObj "PSub"332 showJSON (PSub aa ab ac ad ae) = showJSHashObj "PSub" 326 333 [("pSubName", showJSON aa) , ("pSubType", showJSON ab) , 327 ("pSubParams", showJSON ac) , ("pSubBody", showJSON ad)] 334 ("pSubParams", showJSON ac) , ("pSubLValue", showJSON ad) , 335 ("pSubBody", showJSON ae)] 328 336 329 337 instance Binary PIL_Literal where -
src/Pugs/PIL1.hs-drift
r6379 r6424 70 70 { pType :: !SubType 71 71 , pParams :: ![TParam] 72 , pLValue :: !Bool 72 73 , pBody :: !PIL_Stmts 73 74 } … … 78 79 , pSubType :: !SubType 79 80 , pSubParams :: ![TParam] 81 , pSubLValue :: !Bool 80 82 , pSubBody :: !PIL_Stmts 81 83 } -
src/Pugs/Parser.hs
r6396 r6424 98 98 ruleStandaloneBlock = tryRule "standalone block" $ do 99 99 body <- bracesAlone ruleBlockBody 100 retBlock SubBlock Nothing body100 retBlock SubBlock Nothing False body 101 101 where 102 102 bracesAlone p = between (symbol "{") closingBrace p … … 1017 1017 exp <- ruleExpression 1018 1018 return $ \body -> do 1019 block <- retBlock SubBlock Nothing body1019 block <- retBlock SubBlock Nothing False body 1020 1020 retSyn cond [exp, block] 1021 1021 1022 1022 ruleBlockLiteral :: RuleParser Exp 1023 1023 ruleBlockLiteral = rule "block construct" $ do 1024 (typ, formal ) <- option (SubBlock, Nothing) $ choice1024 (typ, formal, lvalue) <- option (SubBlock, Nothing, False) $ choice 1025 1025 [ ruleBlockFormalPointy 1026 1026 , ruleBlockFormalStandard 1027 1027 ] 1028 1028 body <- ruleBlock 1029 retBlock typ formal body1029 retBlock typ formal lvalue body 1030 1030 1031 1031 extractHash :: Exp -> Maybe Exp … … 1037 1037 extractHash _ = Nothing 1038 1038 1039 retBlock :: SubType -> Maybe [Param] -> Exp -> RuleParser Exp1040 retBlock SubBlock Nothing exp | Just hashExp <- extractHash (unwrap exp) = return $ Syn "\\{}" [hashExp]1041 retBlock typ formal body = retVerbatimBlock typ formalbody1042 1043 retVerbatimBlock :: SubType -> Maybe [Param] -> Exp -> RuleParser Exp1044 retVerbatimBlock styp formal body = expRule $ do1039 retBlock :: SubType -> Maybe [Param] -> Bool -> Exp -> RuleParser Exp 1040 retBlock SubBlock Nothing _ exp | Just hashExp <- extractHash (unwrap exp) = return $ Syn "\\{}" [hashExp] 1041 retBlock typ formal lvalue body = retVerbatimBlock typ formal lvalue body 1042 1043 retVerbatimBlock :: SubType -> Maybe [Param] -> Bool -> Exp -> RuleParser Exp 1044 retVerbatimBlock styp formal lvalue body = expRule $ do 1045 1045 let (fun, names, params) = doExtract styp formal body 1046 1046 -- Check for placeholder vs formal parameters … … 1055 1055 , subAssoc = "pre" 1056 1056 , subReturns = anyType 1057 , subLValue = False -- XXX "is rw"1057 , subLValue = lvalue 1058 1058 , subParams = paramsFor styp formal params 1059 1059 , subBindings = [] … … 1076 1076 defaultParamFor _ = [defaultArrayParam] 1077 1077 1078 ruleBlockFormalStandard :: RuleParser (SubType, Maybe [Param] )1078 ruleBlockFormalStandard :: RuleParser (SubType, Maybe [Param], Bool) 1079 1079 ruleBlockFormalStandard = rule "standard block parameters" $ do 1080 1080 styp <- choice … … 1084 1084 ] 1085 1085 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 1089 ruleBlockFormalPointy :: RuleParser (SubType, Maybe [Param], Bool) 1089 1090 ruleBlockFormalPointy = rule "pointy block parameters" $ do 1090 1091 symbol "->" 1091 1092 params <- ruleSubParameters ParensOptional 1092 return $ (SubPointy, params) 1093 traits <- many $ ruleTrait 1094 return $ (SubPointy, params, "rw" `elem` traits) 1093 1095 1094 1096
