Changeset 5646
- Timestamp:
- 07/17/05 21:22:32 (3 years ago)
- Author:
- iblech
- svk:copy_cache_prev:
- 7648
- Message:
-
* Pugs.Compile -- &infix:<
>(foo, bar) is compiled as &infix:< >(foo,
PThunk(bar)) now.
* Pugs.CodeGen?.PIR -- So Pugs.CodeGen?.PIR doesn't have to do this change, as
Pugs.Compile does it now.
* Pugs.Parser -- Filtered out &infix:<,> from list of user-overridable subs, as
else even basic arglists use &infix:<,> if a &infix:<,> is defined (see
comment).
* PIL2JS: Prelude::JS -- Proper support for
, &&, etc.
* PIL2JS: README -- Minor cleanup.
- Files:
- 5 modified
-
perl5/PIL2JS/README (modified) (1 diff)
-
perl5/PIL2JS/lib6/Prelude/JS.pm (modified) (3 diffs)
-
src/Pugs/CodeGen/PIR.hs (modified) (2 diffs)
-
src/Pugs/Compile.hs (modified) (1 diff)
-
src/Pugs/Parser.hs (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
perl5/PIL2JS/README
r5644 r5646 24 24 =head1 WHAT'S WORKING YET? 25 25 26 Variables, subroutine declarations (with support for C<is rw>, C<is copy>, and 27 default values for optional arguments), subroutine invocations, method 28 invocations, method declarations (simplified), basic operators (C<< &infix:<==> 29 >>, C<< &infix:<eq> >>, C<< &prefix:<+> >>, ...), basic builtins (C<say>, 30 C<defined>, ...), C<if>, C<loop>. 26 =over 27 28 =item * 29 30 Variables (scalars and arrays) 31 32 =item * 33 34 Subroutine and (slightly simplified) method declaration (with support for C<is 35 rw>, C<is copy>, and default values for optional arguments), 36 37 =item * 38 39 Subroutine and method invocation 40 41 =item * 42 43 Basic operators (C<< &infix:<==> >>, C<< &infix:<eq> >>, C<< &prefix:<+> >>, 44 ...) 45 46 =item * 47 48 Basic builtins (C<say>, C<defined>, C<if>, C<loop>, C<while>, C<until>) 49 50 =item * 51 52 Global C<JS> namespace to use JavaScript's classes (e.g. 53 C<$*JS::document.write>, C<JS::alert "Pugs rocks">) 54 55 =back 31 56 32 57 =head1 TODO 33 58 34 59 =over 35 36 =item *37 38 Global C<JS> namespace to use JavaScript's classes (e.g. C<$*JS::document.write>)39 60 40 61 =item * -
perl5/PIL2JS/lib6/Prelude/JS.pm
r5644 r5646 124 124 } 125 125 ').($text); 126 ?1; 126 127 } 127 128 … … 146 147 "infix:«%»", "Number(a) % Number(b)", 147 148 "infix:«~»", "String(a) + String(b)", 148 "infix:«||»", "a || b ? a : b",149 "infix:«&&»", "a && b ? b : a",150 149 "prefix:«+»", "Number(a)", 151 150 "prefix:«~»", "String(a)", … … 182 181 die $! if $!; 183 182 184 sub infix:<//>($a, $b) { defined($a) ?? $a :: $b } 185 sub prefix:<++>($a is rw) { $a = $a + 1 } 186 sub postfix:<++>($a is rw) { my $cur = $a; $a = $a + 1; $cur } 187 sub prefix:<-->($a is rw) { $a = $a - 1 } 188 sub postfix:<-->($a is rw) { my $cur = $a; $a = $a - 1; $cur } 189 # sub infix:<,>($a, $b) { JS::inline("function (a, b) \{ 190 # return new Array(a, b); 191 # \}")($a, $b) } 183 sub infix:<//> ($a, Code $b) { defined($a) ?? $a :: $b() } 184 sub infix:<||> ($a, Code $b) { $a ?? $a :: $b() } 185 sub infix:<&&> ($a, Code $b) { $a ?? $b() :: $a } 186 sub infix:<err> ($a, Code $b) { infix:<//>($a, $b()) } # XXX! hack 187 sub infix:<or> ($a, Code $b) { infix:<||>($a, $b()) } # XXX! hack 188 sub infix:<and> ($a, Code $b) { infix:<&&>($a, $b()) } # XXX! hack 189 sub prefix:<++> ($a is rw) { $a = $a + 1 } 190 sub postfix:<++> ($a is rw) { my $cur = $a; $a = $a + 1; $cur } 191 sub prefix:<--> ($a is rw) { $a = $a - 1 } 192 sub postfix:<--> ($a is rw) { my $cur = $a; $a = $a - 1; $cur } 193 sub infix:<,>(*@xs) { @xs } 192 194 193 195 sub die(Str $msg) { $JS::PIL2JS.die($msg) } -
src/Pugs/CodeGen/PIR.hs
r5644 r5646 123 123 _ -> trans fun 124 124 -} 125 argsC <- if isLogicalLazy fun 126 then mapM trans (head args : map PThunk (tail args)) 127 else mapM trans args 125 argsC <- mapM trans args 128 126 -- XXX WORKAROUND PARROT BUG (see below) 129 127 pmc <- genLV "app" … … 142 140 return pmc 143 141 -} 144 where145 -- XXX HACK146 isLogicalLazy (PExp (PVar "&infix:or")) = True147 isLogicalLazy (PExp (PVar "&infix:and")) = True148 isLogicalLazy (PExp (PVar "&infix:||")) = True149 isLogicalLazy (PExp (PVar "&infix:&&")) = True150 isLogicalLazy _ = False151 142 trans (PPad SMy pad exps) = do 152 143 valsC <- mapM trans (map snd pad) -
src/Pugs/Compile.hs
r5644 r5646 329 329 invC <- maybeM (return inv) compile 330 330 argsC <- enter cxtItemAny $ compile args 331 return $ PApp cxt funC invC argsC 331 if isLogicalLazy funC 332 then return $ PApp cxt funC invC (head argsC:map PThunk (tail argsC)) 333 else return $ PApp cxt funC invC argsC 334 where 335 -- XXX HACK 336 isLogicalLazy (PExp (PVar "&infix:or")) = True 337 isLogicalLazy (PExp (PVar "&infix:and")) = True 338 isLogicalLazy (PExp (PVar "&infix:||")) = True 339 isLogicalLazy (PExp (PVar "&infix:&&")) = True 340 isLogicalLazy (PExp (PVar "&infix://")) = True 341 isLogicalLazy (PExp (PVar "&infix:err")) = True 342 isLogicalLazy _ = False 332 343 compile exp@(Syn "if" _) = compConditional exp 333 344 compile (Syn "{}" (x:xs)) = compile $ App (Var "&postcircumfix:{}") (Just x) xs -
src/Pugs/Parser.hs
r5644 r5646 1091 1091 -- Finally, we return the names of the ops. 1092 1092 -- But we've to s/^infix://, as we've to return (say) "+" instead of "infix:+". 1093 return $ map (encodeUTF8 . unwords . nub) 1093 -- Hack: Filter out &infix:<,> (which are most Preludes for PIL -> * 1094 -- compilers required to define), because else basic function application 1095 -- (foo(1,2,3) will get parsed as foo(&infix:<,>(1,&infix:<,>(2,3))) (bad). 1096 return $ map (encodeUTF8 . unwords . filter (/= ",") . nub) $ 1094 1097 [nullary, optionary, namedUnary, preUnary, postUnary, infixOps] 1095 1098
Download in other formats:
