Changeset 5667

Show
Ignore:
Timestamp:
07/18/05 17:53:32 (3 years ago)
Author:
iblech
svk:copy_cache_prev:
7648
Message:

* Pugs.Compile -- loop foo; ; bar {baz} should be compiled as loop foo;

bool::true; bar {baz}.

* PIL2JS: jspugs.pl -- Empty lines don't cause a compile now.
* PIL2JS: PIL::Nodes, PIL::Parser -- Support for VBool.

Files:
4 modified

Legend:

Unmodified
Added
Removed
  • perl5/PIL2JS/jspugs.pl

    r5664 r5667  
    4040 
    4141while(defined($_ = $term->readline($prompt))) { 
    42   $term->addhistory($_) if /\S/; 
     42  next unless /\S/; 
     43  $term->addhistory($_); 
    4344  s/\s*$//; 
    4445 
  • perl5/PIL2JS/lib/PIL/Nodes.pm

    r5665 r5667  
    151151  sub as_js { 
    152152    my $self = shift; 
    153  
    154153    die unless @$self == 0; 
    155     return ""; 
     154 
     155    return "" unless $IN_SUBLIKE; 
     156    return "return(new PIL2JS.Box.Constant(undefined));"; 
    156157  } 
    157158} 
     
    338339    die if     ref $self->[0]; 
    339340    return sprintf "new PIL2JS.Box.Constant(%s)", PIL::Nodes::doublequote $self->[0]; 
     341  } 
     342} 
     343 
     344{ 
     345  package PIL::VBool; 
     346  our @ISA = qw<PIL::PVal>; 
     347 
     348  sub as_js { 
     349    my $self = shift; 
     350    die unless @$self == 1; 
     351 
     352    return sprintf "new PIL2JS.Box.Constant(%s)", 
     353      $self->[0]->isa("PIL::True")  ? "true"  : 
     354      $self->[0]->isa("PIL::False") ? "false" : die; 
    340355  } 
    341356} 
  • perl5/PIL2JS/lib/PIL/Parser.pm

    r5644 r5667  
    184184 
    185185        VInt    => 1, VRat   => 1, 
    186         VStr    => 1, VUndef => 0, 
     186        VStr    => 1, VUndef => 0, VBool => 1, 
    187187        SubPrim => 0, SubRoutine => 0, SubBlock => 0, SubPointy => 0, SubMethod => 0, 
    188188        True    => 0, False => 0, 
  • src/Pugs/Compile.hs

    r5662 r5667  
    261261    compile (Syn "loop" [pre, cond, post, (Syn "block" [body])]) = do 
    262262        preC    <- compile pre 
    263         condC   <- compile cond 
     263        -- loop ...; ; ... {...} -> 
     264        -- loop ...; bool::true; ... {...} 
     265        let cond' | unwrap cond == Noop 
     266                  = return $ PStmts (PStmt . PLit . PVal $ VBool True) PNil 
     267                  | otherwise 
     268                  = compile cond 
     269        condC   <- cond' 
    264270        bodyC   <- compile body 
    265271        postC   <- compile post