Changeset 4882 for src/Pugs/Compile
- Timestamp:
- 06/20/05 21:18:37 (3 years ago)
- svk:copy_cache_prev:
- 6641
- Files:
-
- 1 modified
-
src/Pugs/Compile/PIR.hs (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Pugs/Compile/PIR.hs
r4879 r4882 35 35 PExp :: !(PIL LValue) -> PIL Expression 36 36 PLit :: !(PIL Literal) -> PIL Expression 37 PPos :: !Pos -> !Exp -> PIL a-> PIL a37 PPos :: !Pos -> !Exp -> !(PIL a) -> PIL a 38 38 PStmt :: !(PIL Expression) -> PIL Stmt 39 39 PThunk :: !(PIL Expression) -> PIL Expression 40 PCode :: !SubType -> ! (PIL [Stmt]) -> PIL Expression40 PCode :: !SubType -> ![TParam] -> !(PIL [Stmt]) -> PIL Expression 41 41 42 42 PVal :: !Val -> PIL Literal 43 43 PVar :: !VarName -> PIL LValue 44 44 45 PStmts :: !(PIL Stmt) -> PIL [Stmt]-> PIL [Stmt]45 PStmts :: !(PIL Stmt) -> !(PIL [Stmt]) -> PIL [Stmt] 46 46 PApp :: !TCxt -> !(PIL Expression) -> ![PIL Expression] -> PIL LValue 47 47 PAssign :: ![PIL LValue] -> !(PIL Expression) -> PIL LValue … … 88 88 show (PPad x y) = "(PPad " ++ show x ++ " " ++ show y ++ ")" 89 89 show (PThunk x) = "(PThunk " ++ show x ++ ")" 90 show (PCode x y ) = unwords ["(PCode", show x, show y, ")"]90 show (PCode x y z) = unwords ["(PCode", show x, show y, show z, ")"] 91 91 show (PRawName x) = "(PRawName " ++ show x ++ ")" 92 92 show (PSub x y z w) = unwords ["(PSub", show x, show y, show z, show w, ")"] … … 167 167 compile (name, MkCode{ subType = styp, subBody = Syn "block" [body], subParams = params }) = do 168 168 bodyC <- enter cxtItemAny $ compile body 169 paramsC <- mapMcompile params169 paramsC <- compile params 170 170 return [PSub name styp paramsC bodyC] 171 171 compile (name, code) = compile … … 247 247 248 248 pBlock :: PIL [Stmt] -> PIL Expression 249 pBlock = PCode SubBlock 249 pBlock = PCode SubBlock [] 250 250 251 251 {- … … 360 360 Syn "block" [exp] -> exp 361 361 exp -> exp 362 return $ PCode (subType sub) bodyC 362 paramsC <- compile $ subParams sub 363 return $ PCode (subType sub) paramsC bodyC 363 364 compile (Syn "for" _) = compile Noop -- XXX TODO 364 365 compile (Syn "module" _) = compile Noop … … 447 448 tell [thisC] 448 449 trans rest 449 trans (PApp _ exp@(PCode _ _ ) []) = do450 trans (PApp _ exp@(PCode _ _ _) []) = do 450 451 blockC <- trans exp 451 452 tellIns $ [reg tempPMC] <-& blockC $ [] … … 484 485 return ([], (StmtPad (map fst pad `zip` valsC) expsC:)) 485 486 trans (PExp exp) = fmap ExpLV $ trans exp 486 trans (PCode styp body) = do487 trans (PCode styp params body) = do 487 488 [begC, endC] <- genLabel ["blockBegin", "blockEnd"] 488 489 this <- genPMC "block" … … 490 491 tellIns $ "goto" .- [bare endC] 491 492 tellLabel begC 493 let prms = map tpParam params 494 mapM_ (tellIns . InsLocal RegPMC . prmToIdent) prms 495 tellIns $ "get_params" .- sigList (map prmToSig prms) 492 496 tellIns $ "new_pad" .- [lit curPad] 493 497 wrapSub styp $ do 498 mapM storeLex params 494 499 trans body -- XXX - consistency check 495 500 bodyC <- lastPMC … … 535 540 tellIns $ "returncc" .- [] 536 541 return (DeclSub name [] stmts) 537 where538 -- XXX - slurpiness539 prmToSig prm = MkSig (prmToArgs prm) . bare $ prmToIdent prm540 prmToArgs prm = combine541 [ if isSlurpy prm then (MkArgSlurpyArray:) else id542 , if isOptional prm then (MkArgOptional:) else id543 ] []544 prmToIdent = render . varText . paramName545 storeLex param = do546 let var = paramName prm547 name = prmToIdent prm548 prm = tpParam param549 -- deal with defaults550 when (isOptional prm) $ do551 [defC] <- genLabel ["defaultDone"]552 tellIns $ "unless_null" .- [bare name, bare defC]553 case tpDefault param of554 Nothing -> tellIns $ InsNew (VAR name) PerlScalar555 (Just exp) -> do556 expC <- trans exp557 -- compile it away558 tellIns $ VAR name <:= expC559 tellLabel defC560 tellIns $ "store_lex" .- [lit curPad, lit var, bare name]561 542 trans x = transError x 562 543 … … 581 562 tellIns $ "set_returns" .- sigList [tempPMC] 582 563 tellIns $ "returncc" .- [] 564 565 -- XXX - slurpiness 566 prmToSig prm = MkSig (prmToArgs prm) . bare $ prmToIdent prm 567 prmToArgs prm = combine 568 [ if isSlurpy prm then (MkArgSlurpyArray:) else id 569 , if isOptional prm then (MkArgOptional:) else id 570 ] [] 571 prmToIdent = render . varText . paramName 572 storeLex param = do 573 let var = paramName prm 574 name = prmToIdent prm 575 prm = tpParam param 576 -- deal with defaults 577 when (isOptional prm) $ do 578 [defC] <- genLabel ["defaultDone"] 579 tellIns $ "unless_null" .- [bare name, bare defC] 580 case tpDefault param of 581 Nothing -> tellIns $ InsNew (VAR name) PerlScalar 582 (Just exp) -> do 583 expC <- trans exp 584 -- compile it away 585 tellIns $ VAR name <:= expC 586 tellLabel defC 587 tellIns $ "store_lex" .- [lit curPad, lit var, bare name] 583 588 584 589 tellIns :: Ins -> Trans ()
