Changeset 4873 for src/Pugs/Compile
- Timestamp:
- 06/20/05 18:38:20 (3 years ago)
- svk:copy_cache_prev:
- 6641
- Files:
-
- 1 modified
-
src/Pugs/Compile/PIR.hs (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Pugs/Compile/PIR.hs
r4871 r4873 37 37 PPad :: ![(VarName, PIL Expression)] -> !(PIL [Stmt]) -> PIL [Stmt] 38 38 39 PSub :: !SubName -> ! [TParam] -> !(PIL [Stmt]) -> PIL Decl39 PSub :: !SubName -> !SubType -> ![TParam] -> !(PIL [Stmt]) -> PIL Decl 40 40 #endif 41 41 … … 78 78 show (PBlock x) = "(PBlock " ++ show x ++ ")" 79 79 show (PRawName x) = "(PRawName " ++ show x ++ ")" 80 show (PSub x y z ) = "(PSub " ++ show x ++ " " ++ show y ++ " " ++ show z ++ ")"80 show (PSub x y z w) = unwords ["(PSub", show x, show y, show z, show w, ")"] 81 81 82 82 data TEnv = MkTEnv … … 141 141 compile ("&*END", concat decls) 142 142 canCompile _ = return [] 143 doCode name vsub = if subType vsub == SubPrim144 thenreturn []145 elsecompile (name, vsub)143 doCode name vsub = case subBody vsub of 144 Prim _ -> return [] 145 _ -> compile (name, vsub) 146 146 147 147 instance Compile ([Char], [PIL Decl]) [PIL Decl] where 148 148 compile (name, decls) = do 149 149 let bodyC = [ PStmts . PStmt . PExp $ PApp tcVoid (PExp (PVar sub)) [] 150 | PSub sub _ _ <- decls150 | PSub sub _ _ _ <- decls 151 151 ] 152 return (PSub name [] (combine bodyC PNil):decls)152 return (PSub name SubPrim [] (combine bodyC PNil):decls) 153 153 154 154 instance Compile ([Char], VCode) [PIL Decl] where 155 compile (name, MkCode{ sub Body = Syn "block" [body], subParams = params }) = do155 compile (name, MkCode{ subType = styp, subBody = Syn "block" [body], subParams = params }) = do 156 156 bodyC <- enter cxtItemAny $ compile body 157 157 paramsC <- mapM compile params 158 return [PSub name paramsC bodyC] 159 compile x = compError x 158 return [PSub name styp paramsC bodyC] 159 compile (name, code) = compile 160 (name, code{ subBody = Syn "block" [subBody code] }) 160 161 161 162 {- … … 274 275 compile exp@(Syn "while" _) = compLoop exp 275 276 compile exp@(Syn "until" _) = compLoop exp 277 compile (Syn "given" _) = compile (Var "$_") -- XXX 278 compile (Syn "when" _) = compile (Var "$_") -- XXX 276 279 compile (Syn "{}" (x:xs)) = compile (App (Var "&postcircumfix:{}") (Just x) xs) 277 280 compile (Syn "[]" (x:xs)) = do … … 328 331 compile (Syn "sub" [Val (VCode sub)]) = do 329 332 -- XXX I'd like to lambda lift... :-/ 330 cxt<- askTCxt333 _ <- askTCxt 331 334 bodyC <- compile (subBody sub) 332 return $ P Exp $ PApp cxt (PBlock bodyC) []335 return $ PBlock bodyC 333 336 compile (Syn "for" _) = compile Noop -- XXX TODO 334 337 compile (Syn "module" _) = compile Noop … … 342 345 343 346 compError :: forall a b. Compile a b => a -> Comp b 344 compError = die $ "Compile error -- invalid PIL"345 ++ ( drop 12 .show $ typeOf (undefined :: b))347 compError = die $ "Compile error -- invalid " 348 ++ (show $ typeOf (undefined :: b)) 346 349 347 350 transError :: forall a b. Translate a b => a -> Trans b … … 468 471 then "store_global" .- [tempSTR, bodyC] -- XXX HACK 469 472 else "set_args" .- [lit "(0b10)", bodyC] 470 tellIns $ "invoke" .- [reg cc]473 -- tellIns $ "invoke" .- [reg cc] 471 474 tellLabel endC 472 475 return (ExpLV this) … … 495 498 pmc <- genName name 496 499 return (ExpLV pmc) 497 trans (PSub name params body) = do500 trans (PSub name styp params body) = do 498 501 (_, stmts) <- listen $ do 499 502 let prms = map tpParam params … … 501 504 tellIns $ "get_params" .- sigList (map prmToSig prms) 502 505 tellIns $ "new_pad" .- [lit curPad] 503 mapM storeLex params 504 trans body 505 bodyC <- lastPMC 506 tellIns $ "set_returns" .- retSigList [bodyC] 507 tellIns $ "returncc" .- [] 506 507 508 wrapSub styp $ do 509 mapM storeLex params 510 trans body 511 bodyC <- lastPMC 512 tellIns $ "set_returns" .- retSigList [bodyC] 513 tellIns $ "returncc" .- [] 514 508 515 return (DeclSub name [] stmts) 509 516 where … … 531 538 tellLabel defC 532 539 tellIns $ "store_lex" .- [lit curPad, lit var, bare name] 540 -- XXX - slow way of implementing "return" 541 wrapSub SubPrim = id 542 wrapSub _ = \body -> do 543 [retL] <- genLabel ["returnHandler"] 544 tellIns $ "push_eh" .- [bare retL] 545 body 546 tellLabel retL 547 tellIns $ tempPMC <:= ExpLV (KEYED (VAR "P5") (lit False)) 548 tellIns $ "set_returns" .- sigList [tempPMC] 549 tellIns $ "returncc" .- [] 533 550 trans x = transError x 534 551 … … 553 570 name' <- liftIO $ liftSTM $ do 554 571 (cur, name) <- readTVar tvar 555 return $ "P" ++ show cur ++ "_" ++ name572 return $ "P" ++ show cur ++ (if null name then name else ('_':name)) 556 573 return $ reg (VAR name') 557 574
