Changeset 22860 for v6

Show
Ignore:
Timestamp:
11/03/08 20:24:50 (2 months ago)
Author:
ruoso
Message:

[mildew] starting the implementation of "if"

Location:
v6/mildew
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • v6/mildew/mildew

    r22859 r22860  
    323323        AST::Label->new(label=>label($m->{label}),stmt=>statement($m->{statement})); 
    324324    } elsif ($m->{statement_control}) { 
    325         XXX('statement_control') 
     325        my $stm = $m->{statement_control}; 
     326        if ($stm->{sym} eq 'if') { 
     327            AST::If->new( 
     328                         cond => $stm->{xblock}{EXPR}->emit_m0ld, 
     329                         then => $stm->{xblock}{pblock}{block}->emit_m0ld 
     330                        ); 
     331        } else { 
     332            XXX('unkown sym in statement_control') 
     333        } 
    326334    } elsif ($m->{EXPR}) { 
    327335        $m->{EXPR}->emit_m0ld; 
  • v6/mildew/src/AST.pm

    r22621 r22860  
    44sub unique_id { 
    55    '$id'.$id++; 
     6} 
     7my $lab = 0; 
     8sub unique_label { 
     9    'lab'.$lab++; 
    610} 
    711sub indent { 
     
    3337    $yaml; 
    3438} 
     39 
     40package AST::If; 
     41use Moose; 
     42extends 'AST::Base'; 
     43has 'cond' => (is => 'ro'); 
     44has 'then' => (is => 'ro'); 
     45sub m0ld { 
     46    my ($self) = @_; 
     47    my $id_cond = AST::unique_id; 
     48    my $id_then = AST::unique_id; 
     49    my $label_then = AST::unique_label; 
     50    my $label_else = AST::unique_label; 
     51    my $cond = $self->cond->m0ld($id_cond); 
     52    my $then = $self->then->m0ld($id_then); 
     53 
     54    $cond.$/. 
     55    'my '.$id_cond.'_val = '.$id_cond.'."FETCH"();'.$/. 
     56    'my '.$id_cond.'_bool = '.$id_cond.'_val."bool"();'.$/. 
     57    'if '.$id_cond.'_bool { goto '.$label_then.'; } else { goto '.$label_else.'; };'.$/. 
     58    $label_then.':'.$/. 
     59    $then.$/. 
     60    $label_else.':'.$/; 
     61} 
     62 
    3563package AST::Block; 
    3664use Moose; 
  • v6/mildew/t/if.t

    r22808 r22860  
    22if True { 
    33    $OUT.print("ok 1\n"); 
    4 } else { 
    5     $OUT.print("not ok 1\n"); 
    64}