Skip to content

Commit

Permalink
give numeric constant QAST nodes a .node
Browse files Browse the repository at this point in the history
now Int and Num literals warn in void context
  • Loading branch information
moritz committed Feb 16, 2013
1 parent c24440a commit 89c7e57
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
18 changes: 9 additions & 9 deletions src/Perl6/Actions.pm
Expand Up @@ -4427,8 +4427,8 @@ class Perl6::Actions is HLL::Actions does STDActions {

sub flipflop($lhs, $rhs, $min_excl, $max_excl, $one_only) {
# Need various constants.
my $zero := $*W.add_numeric_constant('Int', 0);
my $one := $*W.add_numeric_constant('Int', 1);
my $zero := $*W.add_numeric_constant(NQPMu, 'Int', 0);
my $one := $*W.add_numeric_constant(NQPMu, 'Int', 1);
my $nil := QAST::WVal.new( :value($*W.find_symbol(['Nil'])) );
my $false := QAST::WVal.new( :value($*W.find_symbol(['Bool', 'False'])) );
my $true := QAST::WVal.new( :value($*W.find_symbol(['Bool', 'True'])) );
Expand Down Expand Up @@ -4759,12 +4759,12 @@ class Perl6::Actions is HLL::Actions does STDActions {

method numish($/) {
if $<integer> {
make $*W.add_numeric_constant('Int', $<integer>.ast);
make $*W.add_numeric_constant($/, 'Int', $<integer>.ast);
}
elsif $<dec_number> { make $<dec_number>.ast; }
elsif $<rad_number> { make $<rad_number>.ast; }
else {
make $*W.add_numeric_constant('Num', +$/);
make $*W.add_numeric_constant($/, 'Num', +$/);
}
}

Expand Down Expand Up @@ -4804,11 +4804,11 @@ class Perl6::Actions is HLL::Actions does STDActions {
my $radix := +($<radix>.Str);
if $<bracket> {
make QAST::Op.new(:name('&unbase_bracket'), :op('call'),
$*W.add_numeric_constant('Int', $radix), $<bracket>.ast);
$*W.add_numeric_constant($/, 'Int', $radix), $<bracket>.ast);
}
elsif $<circumfix> {
make QAST::Op.new(:name('&unbase'), :op('call'),
$*W.add_numeric_constant('Int', $radix), $<circumfix>.ast);
$*W.add_numeric_constant($/, 'Int', $radix), $<circumfix>.ast);
} else {
my $intpart := $<intpart>.Str;
my $fracpart := $<fracpart> ?? $<fracpart>.Str !! "0";
Expand Down Expand Up @@ -5664,9 +5664,9 @@ class Perl6::Actions is HLL::Actions does STDActions {
if $num {
if nqp::bool_I($iresult) {
my num $result := nqp::mul_n(nqp::div_n(nqp::tonum_I($iresult), nqp::tonum_I($fdivide)), nqp::pow_n($base, $exponent));
return $*W.add_numeric_constant('Num', $result);
return $*W.add_numeric_constant($/, 'Num', $result);
} else {
return $*W.add_numeric_constant('Num', 0e0);
return $*W.add_numeric_constant($/, 'Num', 0e0);
}
} else {
if nqp::defined($exponent) {
Expand All @@ -5688,7 +5688,7 @@ class Perl6::Actions is HLL::Actions does STDActions {
$iresult, $fdivide, :nocache(1)
);
} else {
return $*W.add_numeric_constant('Int', $iresult);
return $*W.add_numeric_constant($/, 'Int', $iresult);
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/Perl6/World.pm
Expand Up @@ -1307,7 +1307,7 @@ class Perl6::World is HLL::World {

# Adds a numeric constant value (int or num) to the constants table.
# Returns PAST to do the lookup of the constant.
method add_numeric_constant($type, $value) {
method add_numeric_constant($/, $type, $value) {
if $type eq 'Int' && pir::typeof__SP($value) eq 'Int' {
if nqp::isbig_I($value) {
# cannot unbox to int without loss of information
Expand All @@ -1329,6 +1329,9 @@ class Perl6::World is HLL::World {
QAST::NVal.new( :value($value) ) );
}
$past.returns($const.returns);
if $/ {
$past.node($/);
}
$past;
}

Expand Down

0 comments on commit 89c7e57

Please sign in to comment.