Changeset 4879 for src/Pugs/Compile
- Timestamp:
- 06/20/05 20:52:17 (3 years ago)
- svk:copy_cache_prev:
- 6641
- Files:
-
- 1 modified
-
src/Pugs/Compile/PIR.hs (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Pugs/Compile/PIR.hs
r4878 r4879 38 38 PStmt :: !(PIL Expression) -> PIL Stmt 39 39 PThunk :: !(PIL Expression) -> PIL Expression 40 P Block ::!(PIL [Stmt]) -> PIL Expression40 PCode :: !SubType -> !(PIL [Stmt]) -> PIL Expression 41 41 42 42 PVal :: !Val -> PIL Literal … … 88 88 show (PPad x y) = "(PPad " ++ show x ++ " " ++ show y ++ ")" 89 89 show (PThunk x) = "(PThunk " ++ show x ++ ")" 90 show (P Block x) = "(PBlock " ++ show x ++ ")"90 show (PCode x y) = unwords ["(PCode", show x, show y, ")"] 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, ")"] … … 242 242 postC <- compile post 243 243 funC <- compile (Var "&statement_control:loop") 244 return $ PStmt $ PExp $ PApp TCxtVoid funC [preC, PBlock condC, PBlock bodyC, PBlock postC] 244 return $ PStmt $ PExp $ PApp TCxtVoid funC 245 [preC, pBlock condC, pBlock bodyC, pBlock postC] 245 246 compile exp = fmap PStmt $ compile exp 247 248 pBlock :: PIL [Stmt] -> PIL Expression 249 pBlock = PCode SubBlock 246 250 247 251 {- … … 325 329 bodyC <- compile body 326 330 funC <- compile (Var $ "&statement_control:" ++ name) 327 return $ PApp cxt funC [ PBlock condC, PBlock bodyC]331 return $ PApp cxt funC [pBlock condC, pBlock bodyC] 328 332 compLoop exp = compError exp 329 333 … … 350 354 cxt <- askTCxt 351 355 bodyC <- compile body 352 return $ PExp $ PApp cxt ( PBlock bodyC) []356 return $ PExp $ PApp cxt (pBlock bodyC) [] 353 357 compile (Syn "sub" [Val (VCode sub)]) = do 354 358 -- XXX I'd like to lambda lift... :-/ … … 356 360 Syn "block" [exp] -> exp 357 361 exp -> exp 358 return $ P BlockbodyC362 return $ PCode (subType sub) bodyC 359 363 compile (Syn "for" _) = compile Noop -- XXX TODO 360 364 compile (Syn "module" _) = compile Noop … … 443 447 tell [thisC] 444 448 trans rest 445 trans (PApp _ exp@(P Block_) []) = do449 trans (PApp _ exp@(PCode _ _) []) = do 446 450 blockC <- trans exp 447 451 tellIns $ [reg tempPMC] <-& blockC $ [] … … 480 484 return ([], (StmtPad (map fst pad `zip` valsC) expsC:)) 481 485 trans (PExp exp) = fmap ExpLV $ trans exp 482 trans (P Blockbody) = do486 trans (PCode styp body) = do 483 487 [begC, endC] <- genLabel ["blockBegin", "blockEnd"] 484 488 this <- genPMC "block" … … 486 490 tellIns $ "goto" .- [bare endC] 487 491 tellLabel begC 488 trans body -- XXX - consistency check 489 bodyC <- lastPMC 490 tellIns $ "set_returns" .- retSigList [bodyC] 491 tellIns $ "returncc" .- [] 492 tellIns $ "new_pad" .- [lit curPad] 493 wrapSub styp $ do 494 trans body -- XXX - consistency check 495 bodyC <- lastPMC 496 tellIns $ "set_returns" .- retSigList [bodyC] 497 tellIns $ "returncc" .- [] 492 498 tellLabel endC 493 499 return (ExpLV this) … … 522 528 tellIns $ "get_params" .- sigList (map prmToSig prms) 523 529 tellIns $ "new_pad" .- [lit curPad] 524 525 526 530 wrapSub styp $ do 527 531 mapM storeLex params … … 530 534 tellIns $ "set_returns" .- retSigList [bodyC] 531 535 tellIns $ "returncc" .- [] 532 533 536 return (DeclSub name [] stmts) 534 537 where … … 556 559 tellLabel defC 557 560 tellIns $ "store_lex" .- [lit curPad, lit var, bare name] 558 -- XXX - slow way of implementing "return"559 wrapSub SubPrim = id560 wrapSub _ = \body -> do561 [retL] <- genLabel ["returnHandler"]562 tellIns $ "push_eh" .- [bare retL]563 body564 tellLabel retL565 tellIns $ tempPMC <:= ExpLV (KEYED (VAR "P5") (lit False))566 tellIns $ "set_returns" .- sigList [tempPMC]567 tellIns $ "returncc" .- []568 561 trans x = transError x 569 562 … … 575 568 fetchCC cc _ = do 576 569 tellIns $ "get_params" .- sigList [reg cc] 570 571 -- XXX - slow way of implementing "return" 572 wrapSub :: SubType -> Trans () -> Trans () 573 wrapSub SubPrim = id 574 wrapSub SubBlock = id -- XXX not really 575 wrapSub _ = \body -> do 576 [retL] <- genLabel ["returnHandler"] 577 tellIns $ "push_eh" .- [bare retL] 578 body 579 tellLabel retL 580 tellIns $ tempPMC <:= ExpLV (KEYED (VAR "P5") (lit False)) 581 tellIns $ "set_returns" .- sigList [tempPMC] 582 tellIns $ "returncc" .- [] 577 583 578 584 tellIns :: Ins -> Trans ()
