Skip to content

Commit

Permalink
Implement Num literals
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan O'Rear committed Jul 12, 2010
1 parent 7d05860 commit 440f8e2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CodeGen.pm
Expand Up @@ -390,6 +390,11 @@ use 5.010;
$self->_push('System.Int32', $val);
}

sub clr_double {
my ($self, $val) = @_;
$self->_push('System.Double', "((Double)$val)");
}

sub clr_field_get {
my ($self, $f) = @_;
my $ty = $typedata{$self->stacktype->[-1]}{$f};
Expand Down
3 changes: 2 additions & 1 deletion Niecza/Actions.pm
Expand Up @@ -52,7 +52,8 @@ sub number { my ($cl, $M) = @_;
# Value :: Op
sub value { }
sub value__S_number { my ($cl, $M) = @_;
$M->sorry("Num is NYI");
# TODO: Implement the rest of the numeric hierarchy once MMD exists
$M->{_ast} = Op::Num->new(value => $M->{number}{_ast});
}

sub value__S_quote { my ($cl, $M) = @_;
Expand Down
17 changes: 17 additions & 0 deletions Op.pm
Expand Up @@ -125,6 +125,23 @@ use 5.010;
no Moose;
}

{
package Op::Num;
use Moose;
extends 'Op';

has value => (isa => 'Num', is => 'ro', required => 1);

sub item_cg {
my ($self, $cg, $body) = @_;
$cg->clr_double($self->value);
$cg->box('Num');
}

__PACKAGE__->meta->make_immutable;
no Moose;
}

{
package Op::Lexical;
use Moose;
Expand Down

0 comments on commit 440f8e2

Please sign in to comment.