Skip to content

Commit

Permalink
Merge branch 'tune-hash'
Browse files Browse the repository at this point in the history
  • Loading branch information
jnthn committed Aug 7, 2018
2 parents 7c08ba7 + 90f678f commit a2c3450
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 133 deletions.
39 changes: 26 additions & 13 deletions src/Perl6/Actions.nqp
Expand Up @@ -720,37 +720,50 @@ register_op_desugar('p6scalarfromdesc', -> $qast {
)
)
});
register_op_desugar('p6scalarwithvalue', -> $qast {
# The "certain" variant is allowed to assume the container descriptor is
# reliably provided, so need not map it to the default one. Ideally, we'll
# eventually have everything using this version of the op.
register_op_desugar('p6scalarfromcertaindesc', -> $qast {
my $desc := QAST::Node.unique('descriptor');
my $Scalar := QAST::WVal.new( :value(nqp::gethllsym('perl6', 'Scalar')) );
my $default_cont_spec := nqp::gethllsym('perl6', 'default_cont_spec');
QAST::Stmt.new(
QAST::Op.new(
:op('bind'),
QAST::Var.new( :name($desc), :scope('local'), :decl('var') ),
$qast[0]
),
QAST::Op.new(
:op('p6assign'),
:op('p6bindattrinvres'),
QAST::Op.new(
:op('p6bindattrinvres'),
QAST::Op.new( :op('create'), $Scalar ),
$Scalar,
QAST::SVal.new( :value('$!descriptor') ),
QAST::Op.new(
:op('if'),
QAST::Op.new(
:op('isconcrete'),
QAST::Var.new( :name($desc), :scope('local') ),
),
QAST::Var.new( :name($desc), :scope('local') ),
QAST::WVal.new( :value($default_cont_spec) )
)
QAST::Var.new( :name($desc), :scope('local') )
),
$qast[1]
$Scalar,
QAST::SVal.new( :value('$!value') ),
QAST::Op.new(
:op('callmethod'), :name('default'),
QAST::Var.new( :name($desc), :scope('local') )
)
)
)
});
register_op_desugar('p6scalarwithvalue', -> $qast {
my $Scalar := QAST::WVal.new( :value(nqp::gethllsym('perl6', 'Scalar')) );
QAST::Op.new(
:op('p6assign'),
QAST::Op.new(
:op('p6bindattrinvres'),
QAST::Op.new( :op('create'), $Scalar ),
$Scalar,
QAST::SVal.new( :value('$!descriptor') ),
$qast[0]
),
$qast[1]
)
});
register_op_desugar('p6recont_ro', -> $qast {
my $result := QAST::Node.unique('result');
my $Scalar := QAST::WVal.new( :value(nqp::gethllsym('perl6', 'Scalar')) );
Expand Down
22 changes: 18 additions & 4 deletions src/Perl6/Metamodel/BOOTSTRAP.nqp
Expand Up @@ -1407,7 +1407,11 @@ BEGIN {
nqp::bindattr_i($attr, Attribute, '$!has_accessor', $has_accessor);
nqp::bindattr($attr, Attribute, '$!package', $package);
nqp::bindattr_i($attr, Attribute, '$!inlined', $inlined);
if nqp::existskey(%other, 'container_descriptor') {
if nqp::existskey(%other, 'auto_viv_primitive') {
nqp::bindattr($attr, Attribute, '$!auto_viv_container',
%other<auto_viv_primitive>);
}
elsif nqp::existskey(%other, 'container_descriptor') {
nqp::bindattr($attr, Attribute, '$!container_descriptor', %other<container_descriptor>);
if nqp::existskey(%other, 'auto_viv_container') {
nqp::bindattr($attr, Attribute, '$!auto_viv_container',
Expand Down Expand Up @@ -1738,6 +1742,13 @@ BEGIN {
}
}

# Helper for creating an attribute that vivifies to a clone of some VM
# storage type; used for the storage slots of arrays and hashes.
sub storage_attr($name, $type, $package, $clonee, :$associative_delegate) {
return Attribute.new( :$name, :$type, :$package, :auto_viv_primitive($clonee),
:$associative_delegate );
}

# class Signature is Any{
# has @!params;
# has Mu $!returns;
Expand Down Expand Up @@ -3232,20 +3243,23 @@ BEGIN {
# class Array is List {
# has Mu $!descriptor;
Array.HOW.add_parent(Array, List);
Array.HOW.add_attribute(Array, scalar_attr('$!descriptor', Mu, Array, :!auto_viv_container));
Array.HOW.add_attribute(Array, storage_attr('$!descriptor', Mu, Array,
Scalar.HOW.cache_get(Scalar, 'default_cont_spec')));
Array.HOW.compose_repr(Array);

# my class Map is Cool {
# has Mu $!storage;
Map.HOW.add_parent(Map, Cool);
Map.HOW.add_attribute(Map, scalar_attr('$!storage', Mu, Map, :associative_delegate));
Map.HOW.add_attribute(Map, storage_attr('$!storage', Mu, Map, nqp::hash(),
:associative_delegate));
Map.HOW.compose_repr(Map);
nqp::settypehllrole(Map, 5);

# my class Hash is Map {
# has Mu $!descriptor;
Hash.HOW.add_parent(Hash, Map);
Hash.HOW.add_attribute(Hash, scalar_attr('$!descriptor', Mu, Hash, :!auto_viv_container));
Hash.HOW.add_attribute(Hash, storage_attr('$!descriptor', Mu, Hash,
Scalar.HOW.cache_get(Scalar, 'default_cont_spec')));
Hash.HOW.compose_repr(Hash);
nqp::settypehllrole(Hash, 5);

Expand Down
3 changes: 0 additions & 3 deletions src/Perl6/World.nqp
Expand Up @@ -1604,9 +1604,6 @@ class Perl6::World is HLL::World {
elsif nqp::istype($cont_type, self.find_symbol(['Hash'], :setting-only)) {
$cont := nqp::create($cont_type);
nqp::bindattr($cont, %cont_info<container_base>, '$!descriptor', $descriptor);
my $Map := self.find_symbol(['Map'], :setting-only);
my $Mu := self.find_symbol(['Mu'], :setting-only);
nqp::bindattr($cont, $Map, '$!storage', $Mu);
}
else {
$cont := $cont_type.new;
Expand Down
6 changes: 3 additions & 3 deletions src/core/Any.pm6
Expand Up @@ -251,10 +251,10 @@ my class Any { # declared in BOOTSTRAP

proto method AT-POS(|) is nodal {*}
multi method AT-POS(Any:U \SELF: int \pos) is raw {
nqp::p6scalarfromdesc(ContainerDescriptor::VivifyArray.new(SELF, pos))
nqp::p6scalarfromcertaindesc(ContainerDescriptor::VivifyArray.new(SELF, pos))
}
multi method AT-POS(Any:U \SELF: Int:D \pos) is raw {
nqp::p6scalarfromdesc(ContainerDescriptor::VivifyArray.new(SELF, pos))
nqp::p6scalarfromcertaindesc(ContainerDescriptor::VivifyArray.new(SELF, pos))
}
multi method AT-POS(Any:U: Num:D \pos) is raw {
nqp::isnanorinf(pos)
Expand Down Expand Up @@ -385,7 +385,7 @@ my class Any { # declared in BOOTSTRAP
)
}
multi method AT-KEY(Any:U \SELF: \key) is raw {
nqp::p6scalarfromdesc(ContainerDescriptor::VivifyHash.new(SELF, key))
nqp::p6scalarfromcertaindesc(ContainerDescriptor::VivifyHash.new(SELF, key))
}

proto method BIND-KEY(|) is nodal {*}
Expand Down
18 changes: 9 additions & 9 deletions src/core/Array.pm6
Expand Up @@ -76,7 +76,7 @@ my class Array { # declared in BOOTSTRAP
iter.push-until-lazy:
my \target := ArrayReificationTarget.new(
(my \buffer := nqp::create(IterationBuffer)),
nqp::isnull($!descriptor) ?? (nqp::null) !! nqp::clone($!descriptor))),
nqp::clone($!descriptor))),
nqp::p6bindattrinvres(result, List, '$!reified', buffer),
nqp::stmts(
nqp::bindattr(result, List, '$!reified', buffer),
Expand Down Expand Up @@ -137,7 +137,7 @@ my class Array { # declared in BOOTSTRAP
)
}
method hole(int $i) {
nqp::p6scalarfromdesc(ContainerDescriptor::BindArrayPos.new(
nqp::p6scalarfromcertaindesc(ContainerDescriptor::BindArrayPos.new(
$!descriptor, $!reified, $i))
}
method done() is raw {
Expand Down Expand Up @@ -200,7 +200,7 @@ my class Array { # declared in BOOTSTRAP
$iter.push-until-lazy(
my \target := ArrayReificationTarget.new(
(my \buffer := nqp::create(IterationBuffer)),
nqp::null
nqp::getcurhllsym('perl6', 'default_cont_spec')
)
),
IterationEnd
Expand Down Expand Up @@ -331,7 +331,7 @@ my class Array { # declared in BOOTSTRAP
multi method AT-POS(Int:D \pos) {
nqp::ifnull(
nqp::atpos(nqp::getattr(self,List,'$!reified'),pos),
nqp::p6scalarfromdesc(ContainerDescriptor::BindArrayPos.new(
nqp::p6scalarfromcertaindesc(ContainerDescriptor::BindArrayPos.new(
$!descriptor, nqp::getattr(self,List,'$!reified'), pos))
)
}
Expand Down Expand Up @@ -386,7 +386,7 @@ my class Array { # declared in BOOTSTRAP
nqp::bindpos(
$reified,
$i,
nqp::p6scalarfromdesc($!descriptor)
nqp::p6scalarfromcertaindesc($!descriptor)
)
)
)
Expand Down Expand Up @@ -551,7 +551,7 @@ my class Array { # declared in BOOTSTRAP
nqp::bindpos(
nqp::getattr(self,List,'$!reified'),
$pos,
nqp::p6scalarfromdesc($!descriptor)
nqp::p6scalarfromcertaindesc($!descriptor)
),
nqp::if(
nqp::isconcrete(nqp::getattr(self,List,'$!todo')),
Expand All @@ -566,22 +566,22 @@ my class Array { # declared in BOOTSTRAP
nqp::bindpos( # outlander
nqp::getattr(self,List,'$!reified'),
$pos,
nqp::p6scalarfromdesc($!descriptor)
nqp::p6scalarfromcertaindesc($!descriptor)
)
)
),
nqp::bindpos( # outlander without todo
nqp::getattr(self,List,'$!reified'),
$pos,
nqp::p6scalarfromdesc($!descriptor)
nqp::p6scalarfromcertaindesc($!descriptor)
)
)
)
),
nqp::bindpos( # new outlander
nqp::bindattr(self,List,'$!reified',nqp::create(IterationBuffer)),
$pos,
nqp::p6scalarfromdesc($!descriptor)
nqp::p6scalarfromcertaindesc($!descriptor)
)
) = assignee
)
Expand Down

0 comments on commit a2c3450

Please sign in to comment.