Changeset 5644
- 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
* 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
-
perl5/PIL2JS (added)
-
perl5/PIL2JS/README (added)
-
perl5/PIL2JS/lib (added)
-
perl5/PIL2JS/lib/PIL (added)
-
perl5/PIL2JS/lib/PIL/Nodes.pm (added)
-
perl5/PIL2JS/lib/PIL/Parser.pm (added)
-
perl5/PIL2JS/lib6 (added)
-
perl5/PIL2JS/lib6/Prelude (added)
-
perl5/PIL2JS/lib6/Prelude/JS.pm (added)
-
perl5/PIL2JS/pil2js.pl (added)
-
src/Pugs/CodeGen/PIR.hs (modified) (1 diff)
-
src/Pugs/Compile.hs (modified) (10 diffs)
-
src/Pugs/Parser.hs (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
src/Pugs/CodeGen/PIR.hs
r5413 r5644 108 108 tell [thisC] 109 109 trans rest 110 trans (PApp _ exp@(PCode _ _ _) []) = do110 trans (PApp _ exp@(PCode _ _ _) Nothing []) = do 111 111 blockC <- trans exp 112 112 tellIns $ [reg tempPMC] <-& blockC $ [] 113 113 return tempPMC 114 trans (PApp (TCxtLValue _) (PExp (PVar "&postcircumfix:[]")) [PExp lhs, rhs]) = do114 trans (PApp (TCxtLValue _) (PExp (PVar "&postcircumfix:[]")) Nothing [PExp lhs, rhs]) = do 115 115 lhsC <- trans lhs 116 116 rhsC <- trans rhs 117 117 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 119 121 funC <- trans fun {- case fun of 120 122 PExp (PVar name) -> return $ lit name -
src/Pugs/Compile.hs
r5410 r5644 47 47 PStmts :: !(PIL Stmt) -> !(PIL [Stmt]) -> PIL [Stmt] 48 48 49 PApp :: !TCxt -> !(PIL Expression) -> ! [PIL Expression] -> PIL LValue49 PApp :: !TCxt -> !(PIL Expression) -> !(Maybe (PIL Expression)) -> ![PIL Expression] -> PIL LValue 50 50 PAssign :: ![PIL LValue] -> !(PIL Expression) -> PIL LValue 51 51 PBind :: ![PIL LValue] -> !(PIL Expression) -> PIL LValue … … 90 90 show PNoop = "PNoop" 91 91 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 ++ ")" 93 93 show (PExp x) = "(PExp " ++ show x ++ ")" 94 94 show (PStmt x) = "(PStmt " ++ show x ++ ")" … … 176 176 instance Compile (SubName, [PIL Decl]) [PIL Decl] where 177 177 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 [] 179 179 | PSub sub _ _ _ <- decls 180 180 ] … … 223 223 return $ PStmts (tailCall thisC) PNil 224 224 where 225 tailCall (PStmt (PExp (PApp cxt fun args)))226 = PStmt $ PExp $ PApp (TTailCall cxt) fun args225 tailCall (PStmt (PExp (PApp cxt fun inv args))) 226 = PStmt $ PExp $ PApp (TTailCall cxt) fun inv args 227 227 tailCall (PPos pos exp x) = PPos pos exp (tailCall x) 228 228 tailCall x = x … … 265 265 postC <- compile post 266 266 funC <- compile (Var "&statement_control:loop") 267 return . PStmt . PExp $ PApp TCxtVoid funC 267 return . PStmt . PExp $ PApp TCxtVoid funC Nothing 268 268 [preC, pBlock condC, pBlock bodyC, pBlock postC] 269 269 compile exp@(Syn "unless" _) = fmap (PStmt . PExp) $ compConditional exp … … 276 276 bodyC <- compile body 277 277 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] 279 279 compile (Syn "given" _) = compile (Var "$_") -- XXX 280 280 compile (Syn "when" _) = compile (Var "$_") -- XXX … … 323 323 funC <- compile inv 324 324 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 329 327 cxt <- askTCxt 330 328 funC <- compile fun 329 invC <- maybeM (return inv) compile 331 330 argsC <- enter cxtItemAny $ compile args 332 return $ PApp cxt funC argsC331 return $ PApp cxt funC invC argsC 333 332 compile exp@(Syn "if" _) = compConditional exp 334 333 compile (Syn "{}" (x:xs)) = compile $ App (Var "&postcircumfix:{}") (Just x) xs … … 361 360 bodyC <- enter CxtVoid $ compile body 362 361 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] 364 363 compLoop exp = compError exp 365 364 … … 372 371 funC <- compile $ Var ("&statement_control:" ++ name) 373 372 cxt <- askTCxt 374 return $ PApp cxt funC [condC, PThunk trueC, PThunk falseC]373 return $ PApp cxt funC Nothing [condC, PThunk trueC, PThunk falseC] 375 374 compConditional exp = compError exp 376 375 … … 386 385 cxt <- askTCxt 387 386 bodyC <- compile body 388 return $ PExp $ PApp cxt (pBlock bodyC) []387 return $ PExp $ PApp cxt (pBlock bodyC) Nothing [] 389 388 compile (Syn "sub" [Val (VCode sub)]) = do 390 389 bodyC <- enter sub $ compile $ case subBody sub of -
src/Pugs/Parser.hs
r5562 r5644 626 626 ruleDoBlock = rule "do block" $ try $ do 627 627 symbol "do" 628 choice 628 choice 629 629 [ ruleBlockDeclaration 630 630 , ruleDeclaration
Download in other formats:
