Skip to content

Commit

Permalink
Fix conditional parsing; implement NIL comparison operators
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan O'Rear committed Jul 13, 2010
1 parent 919c9fe commit ab166f7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
10 changes: 9 additions & 1 deletion CodeGen.pm
Expand Up @@ -196,6 +196,14 @@ use 5.010;
push @{ $self->buffer }, " if ($top) { goto case $n; }\n";
}

sub ncgoto {
my ($self, $n) = @_;
$n = ($self->labelname->{$n} //= $self->label) if $n < 0;
my $top = $self->_pop;
$self->_saveall;
push @{ $self->buffer }, " if (!$top) { goto case $n; }\n";
}

sub _cpscall {
my ($self, $rt, $expr) = @_;
$self->_saveall;
Expand Down Expand Up @@ -418,7 +426,7 @@ use 5.010;
my ($self, $op) = @_;
my $a2 = $self->_pop;
my $a1 = $self->_pop;
$self->_push('Bool', "$a1 $op $a2");
$self->_push('Boolean', "$a1 $op $a2");
}

sub clr_field_get {
Expand Down
9 changes: 9 additions & 0 deletions Niecza/Actions.pm
Expand Up @@ -486,6 +486,10 @@ sub insn__S_arith { my ($cl, $M) = @_;
$M->{_ast} = [[ clr_arith => $M->Str ]];
}

sub insn__S_compare { my ($cl, $M) = @_;
$M->{_ast} = [[ clr_compare => $M->Str ]];
}

sub insn__S_attr_get { my ($cl, $M) = @_;
$M->{_ast} = [[ attr_get => $M->{varid}{_ast} ]];
}
Expand Down Expand Up @@ -556,6 +560,11 @@ sub terminator__S_Thesis {}
sub terminator__S_Semi {}
sub terminator__S_Ket {}
sub terminator__S_Ly {}
sub terminator__S_then {}
sub terminator__S_again {}
sub terminator__S_repeat {}
sub terminator__S_while {}
sub terminator__S_else {}
sub stdstopper {}
sub unitstopper {}
sub eat_terminator {}
Expand Down
8 changes: 7 additions & 1 deletion Niecza/Grammar.pm6
Expand Up @@ -30,11 +30,17 @@ grammar NIL is STD {
rule nibbler {
[
|| <insn>
|| <?stopper>
|| <?stdstopper>
|| <.panic: "Malformed NIL instruction">
]*
}

token terminator:then { <sym> }
token terminator:else { <sym> }
token terminator:again { <sym> }
token terminator:while { <sym> }
token terminator:repeat { <sym> }

token category:insn { <sym> }
proto token insn { <...> }

Expand Down

0 comments on commit ab166f7

Please sign in to comment.