Changeset 4885

Show
Ignore:
Timestamp:
06/20/05 21:50:09 (4 years ago)
Author:
autrijus
svk:copy_cache_prev:
6641
Message:

* iteration!

for 1..10 -> $x { say $x }

Location:
src
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • src/Emit/PIR.hs

    r4882 r4885  
    219219(<-&) :: [Sig] -> Expression -> [Expression] -> Ins 
    220220{-| Calls an user-defined sub, ignoring any return values. -} 
    221 (.&) :: String -> [Expression] -> Ins 
     221(.&) :: Expression -> [Expression] -> Ins 
    222222 
    223223namespace = DeclNS 
     
    229229(.-)  = InsPrim Nothing 
    230230(<-&) = InsFun 
    231 (.&)  = InsFun [] . lit 
     231(.&)  = InsFun [] 
    232232 
    233233{-| @$P0@ register -} 
     
    606606    , sub "&leave" [slurpy arg0] 
    607607        [] --> [arg0] 
    608     , sub "&statement_control:loop" [arg0, arg1, arg2, arg3] $ 
     608    , sub "&statement_control:for" [arg0, arg1] 
     609        [ tempPMC   <-- "iter" $ [arg0] 
     610        , InsLabel "sc_for_next" 
     611        , "unless"  .- [tempPMC, bare "sc_for_last"] 
     612        , tempPMC2  <-- "shift" $ [tempPMC] 
     613        , arg1      .& [tempPMC2] 
     614        , "goto"    .- [bare "sc_for_next"] 
     615        , InsLabel "sc_for_last" 
     616        , "returncc" .- [] 
     617        ] 
     618    , sub "&statement_control:loop" [arg0, arg1, arg2, arg3] 
    609619        [ InsLabel "sc_loop_next" 
    610620        , [reg tempPMC] <-& arg1 $ [] 
    611621        , "unless" .- [tempPMC, bare "sc_loop_last"] 
    612         , [] <-& arg2 $ [] -- throw away the result of body... 
    613         , [] <-& arg3 $ [] -- ...and the post-condition 
     622        , arg2 .& [] -- throw away the result of body... 
     623        , arg3 .& [] -- ...and the post-condition 
    614624        , "goto" .- [bare "sc_loop_next"] 
    615625        , InsLabel "sc_loop_last" 
     
    645655        ] --> [lit True] 
    646656    , sub "&Pugs::Internals::exit" [arg0] 
    647         [ "&*END" .& [] 
     657        [ lit "&*END" .& [] 
    648658        , tempINT <:= arg0 
    649659        , "exit" .- [tempINT] 
  • src/Pugs/Compile/PIR.hs

    r4882 r4885  
    244244        return $ PStmt $ PExp $ PApp TCxtVoid funC 
    245245            [preC, pBlock condC, pBlock bodyC, pBlock postC] 
     246    compile exp@(Syn "unless" _) = fmap (PStmt . PExp) $ compConditional exp 
     247    compile exp@(Syn "while" _) = compLoop exp 
     248    compile exp@(Syn "until" _) = compLoop exp 
     249    compile (Syn "for" [exp, body]) = do 
     250        expC    <- compile exp 
     251        bodyC   <- compile body 
     252        funC    <- compile (Var "&statement_control:for") 
     253        return $ PStmt $ PExp $ PApp TCxtVoid funC [expC, bodyC] 
     254    compile (Syn "given" _) = compile (Var "$_") -- XXX 
     255    compile (Syn "when" _) = compile (Var "$_") -- XXX 
    246256    compile exp = fmap PStmt $ compile exp 
    247257 
     
    297307        return $ PApp cxt funC argsC 
    298308    compile exp@(Syn "if" _) = compConditional exp 
    299     compile exp@(Syn "unless" _) = compConditional exp 
    300     compile exp@(Syn "while" _) = compLoop exp 
    301     compile exp@(Syn "until" _) = compLoop exp 
    302     compile (Syn "given" _) = compile (Var "$_") -- XXX 
    303     compile (Syn "when" _) = compile (Var "$_") -- XXX 
    304309    compile (Syn "{}" (x:xs)) = compile (App (Var "&postcircumfix:{}") (Just x) xs) 
    305310    compile (Syn "[]" (x:xs)) = do 
     
    323328    compile exp = compError exp 
    324329 
    325 compLoop :: Exp -> Comp (PIL LValue) 
     330compLoop :: Exp -> Comp (PIL Stmt) 
    326331compLoop (Syn name [cond, body]) = do 
    327332    cxt     <- askTCxt 
     
    329334    bodyC   <- compile body 
    330335    funC    <- compile (Var $ "&statement_control:" ++ name) 
    331     return $ PApp cxt funC [pBlock condC, pBlock bodyC] 
     336    return . PStmt . PExp $ PApp cxt funC [pBlock condC, pBlock bodyC] 
    332337compLoop exp = compError exp 
    333338 
     
    362367        paramsC <- compile $ subParams sub 
    363368        return $ PCode (subType sub) paramsC bodyC 
    364     compile (Syn "for" _) = compile Noop -- XXX TODO 
    365369    compile (Syn "module" _) = compile Noop 
    366370    compile (Syn "match" exp) = compile $ Syn "rx" exp -- wrong