Changeset 5644

Show
Ignore:
Timestamp:
07/17/05 19:41:27 (3 years ago)
Author:
iblech
svk:copy_cache_prev:
7648
Message:

PIL -> JavaScript? compiler.
* Pugs.Compile: Modified the declaration of PApp to accept an invocant.
* Pugs.CodeGen?.PIR: Minor changes because of change #1, pugs -BPIR still passes

the sanity tests.

* New directory perl5/PIL2JS, containing various modules, a README, and

pil2js.pl:
$ pugs -CPIL -Ilib6 -MPrelude::JS -we 'say 2 + 3' | \

./pil2js.pl -html > /tmp/t.html

* t/01-sanity mostly pass! (see

http://m19s28.vlinux.de/iblech/stuff/not_perm/pil2js-demo/)

* t/01-sanity/03-equal.t doesn't pass because of a bug in Pugs.Compile

("3 4" is compiled to "&infix:<>(3, 4)" instead of "&infix:<>(3, {4})"
or something similar.

* See perl5/PIL2JS/README for a list of things which already work.

Files:
10 added
3 modified

Legend:

Unmodified
Added
Removed
  • src/Pugs/CodeGen/PIR.hs

    r5413 r5644  
    108108        tell [thisC] 
    109109        trans rest 
    110     trans (PApp _ exp@(PCode _ _ _) []) = do 
     110    trans (PApp _ exp@(PCode _ _ _) Nothing []) = do 
    111111        blockC  <- trans exp 
    112112        tellIns $ [reg tempPMC] <-& blockC $ [] 
    113113        return tempPMC 
    114     trans (PApp (TCxtLValue _) (PExp (PVar "&postcircumfix:[]")) [PExp lhs, rhs]) = do 
     114    trans (PApp (TCxtLValue _) (PExp (PVar "&postcircumfix:[]")) Nothing [PExp lhs, rhs]) = do 
    115115        lhsC    <- trans lhs 
    116116        rhsC    <- trans rhs 
    117117        return $ lhsC `KEYED` rhsC 
    118     trans (PApp _ fun args) = do 
     118    trans (PApp ctx fun (Just inv) args) = 
     119        trans (PApp ctx fun Nothing (inv:args))  -- XXX wrong 
     120    trans (PApp _ fun Nothing args) = do 
    119121        funC    <- trans fun {- case fun of 
    120122            PExp (PVar name) -> return $ lit name 
  • src/Pugs/Compile.hs

    r5410 r5644  
    4747    PStmts      :: !(PIL Stmt) -> !(PIL [Stmt]) -> PIL [Stmt] 
    4848 
    49     PApp        :: !TCxt -> !(PIL Expression) -> ![PIL Expression] -> PIL LValue 
     49    PApp        :: !TCxt -> !(PIL Expression) -> !(Maybe (PIL Expression)) -> ![PIL Expression] -> PIL LValue 
    5050    PAssign     :: ![PIL LValue] -> !(PIL Expression) -> PIL LValue 
    5151    PBind       :: ![PIL LValue] -> !(PIL Expression) -> PIL LValue 
     
    9090    show PNoop = "PNoop" 
    9191    show (PPos x y z) = "(PPos " ++ show x ++ " " ++ show y ++ " " ++ show z ++ ")" 
    92     show (PApp x y z) = "(PApp " ++ show x ++ " " ++ show y ++ " " ++ show z ++ ")" 
     92    show (PApp x y i z) = "(PApp " ++ show x ++ " " ++ show y ++ " " ++ show i ++ " " ++ show z ++ ")" 
    9393    show (PExp x) = "(PExp " ++ show x ++ ")" 
    9494    show (PStmt x) = "(PStmt " ++ show x ++ ")" 
     
    176176instance Compile (SubName, [PIL Decl]) [PIL Decl] where 
    177177    compile (name, decls) = do 
    178         let bodyC = [ PStmts . PStmt . PExp $ PApp tcVoid (PExp (PVar sub)) [] 
     178        let bodyC = [ PStmts . PStmt . PExp $ PApp tcVoid (PExp (PVar sub)) Nothing [] 
    179179                    | PSub sub _ _ _ <- decls 
    180180                    ] 
     
    223223        return $ PStmts (tailCall thisC) PNil 
    224224        where 
    225         tailCall (PStmt (PExp (PApp cxt fun args))) 
    226             = PStmt $ PExp $ PApp (TTailCall cxt) fun args 
     225        tailCall (PStmt (PExp (PApp cxt fun inv args))) 
     226            = PStmt $ PExp $ PApp (TTailCall cxt) fun inv args 
    227227        tailCall (PPos pos exp x) = PPos pos exp (tailCall x) 
    228228        tailCall x = x 
     
    265265        postC   <- compile post 
    266266        funC    <- compile (Var "&statement_control:loop") 
    267         return . PStmt . PExp $ PApp TCxtVoid funC 
     267        return . PStmt . PExp $ PApp TCxtVoid funC Nothing 
    268268            [preC, pBlock condC, pBlock bodyC, pBlock postC] 
    269269    compile exp@(Syn "unless" _) = fmap (PStmt . PExp) $ compConditional exp 
     
    276276        bodyC   <- compile body 
    277277        funC    <- compile (Var "&statement_control:for") 
    278         return . PStmt . PExp $ PApp TCxtVoid funC [expC, bodyC] 
     278        return . PStmt . PExp $ PApp TCxtVoid funC Nothing [expC, bodyC] 
    279279    compile (Syn "given" _) = compile (Var "$_") -- XXX 
    280280    compile (Syn "when" _) = compile (Var "$_") -- XXX 
     
    323323        funC    <- compile inv 
    324324        argsC   <- enter cxtItemAny $ compile args 
    325         return $ PApp (TTailCall cxt) funC argsC 
    326     compile (App fun (Just inv) args) = do 
    327         compile (App fun Nothing (inv:args)) -- XXX WRONG 
    328     compile (App fun Nothing args) = do 
     325        return $ PApp (TTailCall cxt) funC Nothing argsC 
     326    compile (App fun inv args) = do 
    329327        cxt     <- askTCxt 
    330328        funC    <- compile fun 
     329        invC    <- maybeM (return inv) compile 
    331330        argsC   <- enter cxtItemAny $ compile args 
    332         return $ PApp cxt funC argsC 
     331        return $ PApp cxt funC invC argsC 
    333332    compile exp@(Syn "if" _) = compConditional exp 
    334333    compile (Syn "{}" (x:xs)) = compile $ App (Var "&postcircumfix:{}") (Just x) xs 
     
    361360    bodyC   <- enter CxtVoid $ compile body 
    362361    funC    <- compile (Var $ "&statement_control:" ++ name) 
    363     return . PStmt . PExp $ PApp cxt funC [pBlock condC, pBlock bodyC] 
     362    return . PStmt . PExp $ PApp cxt funC Nothing [pBlock condC, pBlock bodyC] 
    364363compLoop exp = compError exp 
    365364 
     
    372371    funC    <- compile $ Var ("&statement_control:" ++ name) 
    373372    cxt     <- askTCxt 
    374     return $ PApp cxt funC [condC, PThunk trueC, PThunk falseC] 
     373    return $ PApp cxt funC Nothing [condC, PThunk trueC, PThunk falseC] 
    375374compConditional exp = compError exp 
    376375 
     
    386385        cxt     <- askTCxt 
    387386        bodyC   <- compile body 
    388         return $ PExp $ PApp cxt (pBlock bodyC) [] 
     387        return $ PExp $ PApp cxt (pBlock bodyC) Nothing [] 
    389388    compile (Syn "sub" [Val (VCode sub)]) = do 
    390389        bodyC   <- enter sub $ compile $ case subBody sub of 
  • src/Pugs/Parser.hs

    r5562 r5644  
    626626ruleDoBlock = rule "do block" $ try $ do 
    627627    symbol "do" 
    628     choice  
     628    choice 
    629629        [ ruleBlockDeclaration 
    630630        , ruleDeclaration