Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix up moritz++'s patch for rationals.
  • Loading branch information
jnthn committed Jul 1, 2011
1 parent 681e4b5 commit 7cd81b3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
8 changes: 3 additions & 5 deletions src/Perl6/Actions.pm
Expand Up @@ -2713,11 +2713,9 @@ class Perl6::Actions is HLL::Actions {
str2num(0, $int, $frac, ($<escale>[0]<sign> eq '-'), $exp));
} else {
# TODO: strip trailing zeros from $frac
my $nu := pir::perl6_box_int__PI($int ~ $frac);
my $de := pir::perl6_box_int__PI(nqp::pow_n(10, nqp::chars($frac)));
my $rat := $*ST.find_symbol(['Rat']).new($nu, $de);

make $*ST.add_constant('Rat', 'rational', $rat);
my $nu := $*ST.add_constant('Int', 'int', +($int ~ $frac));
my $de := $*ST.add_constant('Int', 'int', pir::set__In(nqp::pow_n(10, nqp::chars($frac))));
make $*ST.add_constant('Rat', 'rational', $nu<compile_time_value>, $de<compile_time_value>);
}
}

Expand Down
24 changes: 16 additions & 8 deletions src/Perl6/SymbolTable.pm
Expand Up @@ -681,10 +681,10 @@ class Perl6::SymbolTable is HLL::Compiler::SerializationContextBuilder {

# Adds a constant value to the constants table. Returns PAST to do
# the lookup of the constant.
method add_constant($type, $primitive, $value) {
method add_constant($type, $primitive, *@value) {
# If we already built this, find it in the cache and
# just return that.
my $cache_key := "$type,$primitive,$value";
my $cache_key := "$type,$primitive," ~ pir::join(',', @value);
if pir::exists(%!const_cache, $cache_key) {
my $past := self.get_slot_past_for_object(%!const_cache{$cache_key});
$past<has_compile_time_value> := 1;
Expand All @@ -702,16 +702,24 @@ class Perl6::SymbolTable is HLL::Compiler::SerializationContextBuilder {
my $constant;
my $des;
if $primitive eq 'int' {
$constant := pir::repr_box_int__PiP($value, $type_obj);
$des := PAST::Op.new( :pirop('repr_box_int PiP'), $value, $type_obj_lookup );
$constant := pir::repr_box_int__PiP(@value[0], $type_obj);
$des := PAST::Op.new( :pirop('repr_box_int PiP'), @value[0], $type_obj_lookup );
}
elsif $primitive eq 'str' {
$constant := pir::repr_box_str__PsP($value, $type_obj);
$des := PAST::Op.new( :pirop('repr_box_str PsP'), $value, $type_obj_lookup );
$constant := pir::repr_box_str__PsP(@value[0], $type_obj);
$des := PAST::Op.new( :pirop('repr_box_str PsP'), @value[0], $type_obj_lookup );
}
elsif $primitive eq 'num' {
$constant := pir::repr_box_num__PnP($value, $type_obj);
$des := PAST::Op.new( :pirop('repr_box_num PnP'), $value, $type_obj_lookup );
$constant := pir::repr_box_num__PnP(@value[0], $type_obj);
$des := PAST::Op.new( :pirop('repr_box_num PnP'), @value[0], $type_obj_lookup );
}
elsif $primitive eq 'rational' {
$constant := $type_obj.new(@value[0], @value[1]);
$des := PAST::Op.new(
:pasttype('callmethod'), :name('new'),
$type_obj_lookup,
self.get_object_sc_ref_past(@value[0]),
self.get_object_sc_ref_past(@value[1]));
}
else {
pir::die("Don't know how to build a $primitive constant");
Expand Down

0 comments on commit 7cd81b3

Please sign in to comment.