Changeset 5646

Show
Ignore:
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

Legend:

Unmodified
Added
Removed
  • perl5/PIL2JS/README

    r5644 r5646  
    2424=head1 WHAT'S WORKING YET? 
    2525 
    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 
     30Variables (scalars and arrays) 
     31 
     32=item * 
     33 
     34Subroutine and (slightly simplified) method declaration (with support for C<is 
     35rw>, C<is copy>, and default values for optional arguments), 
     36 
     37=item * 
     38 
     39Subroutine and method invocation 
     40 
     41=item * 
     42 
     43Basic operators (C<< &infix:<==> >>, C<< &infix:<eq> >>, C<< &prefix:<+> >>, 
     44...) 
     45 
     46=item * 
     47 
     48Basic builtins (C<say>, C<defined>, C<if>, C<loop>, C<while>, C<until>) 
     49 
     50=item * 
     51 
     52Global C<JS> namespace to use JavaScript's classes (e.g. 
     53C<$*JS::document.write>, C<JS::alert "Pugs rocks">) 
     54 
     55=back 
    3156 
    3257=head1 TODO 
    3358 
    3459=over 
    35  
    36 =item * 
    37  
    38 Global C<JS> namespace to use JavaScript's classes (e.g. C<$*JS::document.write>) 
    3960 
    4061=item * 
  • perl5/PIL2JS/lib6/Prelude/JS.pm

    r5644 r5646  
    124124    } 
    125125  ').($text); 
     126  ?1; 
    126127} 
    127128 
     
    146147  "infix:«%»",    "Number(a)  % Number(b)", 
    147148  "infix:«~»",    "String(a)  + String(b)", 
    148   "infix:«||»",   "a || b ? a : b", 
    149   "infix:«&&»",   "a && b ? b : a", 
    150149  "prefix:«+»",   "Number(a)", 
    151150  "prefix:«~»",   "String(a)", 
     
    182181die $! if $!; 
    183182 
    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) } 
     183sub infix:<//>   ($a, Code $b) { defined($a) ?? $a :: $b() } 
     184sub infix:<||>   ($a, Code $b) { $a ?? $a :: $b() } 
     185sub infix:<&&>   ($a, Code $b) { $a ?? $b() :: $a } 
     186sub infix:<err>  ($a, Code $b) { infix:<//>($a, $b()) } # XXX! hack 
     187sub infix:<or>   ($a, Code $b) { infix:<||>($a, $b()) } # XXX! hack 
     188sub infix:<and>  ($a, Code $b) { infix:<&&>($a, $b()) } # XXX! hack 
     189sub prefix:<++>  ($a is rw)    { $a = $a + 1 } 
     190sub postfix:<++> ($a is rw)    { my $cur = $a; $a = $a + 1; $cur } 
     191sub prefix:<-->  ($a is rw)    { $a = $a - 1 } 
     192sub postfix:<--> ($a is rw)    { my $cur = $a; $a = $a - 1; $cur } 
     193sub infix:<,>(*@xs)            { @xs } 
    192194 
    193195sub die(Str $msg) { $JS::PIL2JS.die($msg) } 
  • src/Pugs/CodeGen/PIR.hs

    r5644 r5646  
    123123            _           -> trans fun 
    124124        -} 
    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 
    128126        -- XXX WORKAROUND PARROT BUG (see below) 
    129127        pmc     <- genLV "app" 
     
    142140                return pmc 
    143141        -} 
    144         where 
    145         -- XXX HACK 
    146         isLogicalLazy (PExp (PVar "&infix:or"))     = True 
    147         isLogicalLazy (PExp (PVar "&infix:and"))    = True 
    148         isLogicalLazy (PExp (PVar "&infix:||"))     = True 
    149         isLogicalLazy (PExp (PVar "&infix:&&"))     = True 
    150         isLogicalLazy _ = False 
    151142    trans (PPad SMy pad exps) = do 
    152143        valsC   <- mapM trans (map snd pad) 
  • src/Pugs/Compile.hs

    r5644 r5646  
    329329        invC    <- maybeM (return inv) compile 
    330330        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 
    332343    compile exp@(Syn "if" _) = compConditional exp 
    333344    compile (Syn "{}" (x:xs)) = compile $ App (Var "&postcircumfix:{}") (Just x) xs 
  • src/Pugs/Parser.hs

    r5644 r5646  
    10911091    -- Finally, we return the names of the ops. 
    10921092    -- 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) $ 
    10941097        [nullary, optionary, namedUnary, preUnary, postUnary, infixOps] 
    10951098