Changeset 4888

Show
Ignore:
Timestamp:
06/20/05 22:13:19 (4 years ago)
Author:
autrijus
svk:copy_cache_prev:
6641
Message:

* while loop and until loop

Location:
src
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • src/Emit/PIR.hs

    r4886 r4888  
    22 
    33module Emit.PIR where 
    4 import Text.PrettyPrint 
    54import Data.Char 
     5import Data.List 
    66import Data.Typeable 
    77import Emit.Common 
     8import Text.PrettyPrint 
    89 
    910{-| PIR code consists of declarations. -} 
     
    540541    , "invoke" .- [fun] 
    541542    ] 
     543 
     544{-| Creates appropriate @&statement_control:foo@ subroutines. -} 
     545stmtControlLoop :: VarName     -- ^ Perl 6 name of the new sub 
     546                -> PrimName    -- ^ PIR opcode to use for branching 
     547                -> Decl        -- ^ Final declaration of the sub 
     548stmtControlLoop name comp = sub ("&statement_control:" ++ name) [arg0, arg1] $ 
     549    if isPost then ["goto" .- [bare redoL]] else [] ++ 
     550    [ InsLabel nextL 
     551    , [reg tempPMC] <-& arg0 $ [] 
     552    , comp      .- [tempPMC, bare lastL] 
     553    , InsLabel redoL 
     554    , arg1      .& [] 
     555    , "goto"    .- [bare nextL] 
     556    , InsLabel lastL 
     557    , "returncc" .- [] 
     558    ] 
     559    where 
     560    nextL = ("sc_" ++ name ++ "_next") 
     561    lastL = ("sc_" ++ name ++ "_last") 
     562    redoL = ("sc_" ++ name ++ "_redo") 
     563    isPost = "post" `isPrefixOf` name 
    542564 
    543565{-| Creates appropriate @&statement_control:foo@ subroutines. -} 
     
    614636        , "returncc" .- [] 
    615637        ] 
     638    , stmtControlLoop "while" "unless" 
     639    , stmtControlLoop "until" "if" 
    616640    , stmtControlCond "if" "unless" 
    617641    , stmtControlCond "unless" "if" 
  • src/Pugs/Compile/PIR.hs

    r4886 r4888  
    247247    compile exp@(Syn "while" _) = compLoop exp 
    248248    compile exp@(Syn "until" _) = compLoop exp 
     249    compile exp@(Syn "postwhile" _) = compLoop exp 
     250    compile exp@(Syn "postuntil" _) = compLoop exp 
    249251    compile (Syn "for" [exp, body]) = do 
    250252        expC    <- compile exp 
     
    331333compLoop (Syn name [cond, body]) = do 
    332334    cxt     <- askTCxt 
    333     condC   <- compile cond 
    334     bodyC   <- compile body 
     335    condC   <- enter (CxtItem $ mkType "Bool") $ compile cond 
     336    bodyC   <- enter CxtVoid $ compile body 
    335337    funC    <- compile (Var $ "&statement_control:" ++ name) 
    336338    return . PStmt . PExp $ PApp cxt funC [pBlock condC, pBlock bodyC]