Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Stage 2 of auto-generated BUILDALL methods
- the _UNDER_CONSTRUCTION postfix is removed
- they've become multi's
- it *should* be possible to remove the Mu.BUILDALL candidate
  but it breaks the core setting build
- and somehow the Mu.BUILDALL shadows all auto-generated BUILDALLs
- so no speed improvement yet :-(
  • Loading branch information
lizmat committed Sep 27, 2017
1 parent 4c337e8 commit 63cf246
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 36 deletions.
7 changes: 5 additions & 2 deletions src/Perl6/Metamodel/ClassHOW.nqp
Expand Up @@ -160,16 +160,19 @@ class Perl6::Metamodel::ClassHOW
nqp::say('Could not generate a BUILDALL for ' ~ $obj.HOW.name($obj));
}
else {
$method.set_name('BUILDALL_UNDER_CONSTRUCTION');
$method.set_name('BUILDALL');
my $result := try {
self.add_method($obj,'BUILDALL_UNDER_CONSTRUCTION',$method)
self.add_multi_method($obj,'BUILDALL',$method)
}
unless $result {
nqp::say($obj.HOW.name($obj) ~ ' failed to add a BUILDALL');
}
}
}

# Incorporate any new multi candidates (needs MRO built).
self.incorporate_multi_candidates($obj);

# Compose the representation
self.compose_repr($obj);
}
Expand Down
63 changes: 42 additions & 21 deletions src/Perl6/World.nqp
Expand Up @@ -3027,8 +3027,9 @@ class Perl6::World is HLL::World {
);

# signature configuration hash for ":(%init)"
my %sig_init :=
nqp::hash('parameters', [nqp::hash('variable_name','%init')]);
my %sig_init := nqp::hash('parameters', [
nqp::hash('variable_name','%init','is_multi_invocant',1)
]);

# Generate a method for building a new object that takes a hash
# with attribute => value pairs to be assigned to the object's
Expand Down Expand Up @@ -3063,20 +3064,24 @@ class Perl6::World is HLL::World {

# The block of the method
my $block := QAST::Block.new(
:name<BUILDALL_UNDER_CONSTRUCTION>, :blocktype<declaration_static>,
:name<BUILDALL>, :blocktype<declaration_static>,
$declarations
);

# Register the block in its SC
$!w.cur_lexpad()[0].push($block);

# :(Foo:D: %init)
my $sig := $!w.create_signature_and_params(
NQPMu, %sig_init, $block, 'Any', :method,
invocant_type => $!w.create_definite_type(
$!w.find_symbol(['Metamodel','DefiniteHOW']),
$object,
1
my $invocant_type := $!w.create_definite_type(
$!w.find_symbol(['Metamodel','DefiniteHOW']),
$object,
1
);

$stmts.push(
QAST::Op.new( :op<say>,
QAST::SVal.new( :value(
$object.HOW.name($object) ~ '.BUILDALL called'
))
)
);

Expand Down Expand Up @@ -3152,6 +3157,12 @@ class Perl6::World is HLL::World {
QAST::SVal.new( :value(nqp::atpos($task,2)) )
);

# set assign operation to be used
my $sigil :=
nqp::substr(nqp::atpos($task,2),0,1);
my $op := $sigil eq '$' || $sigil eq '&'
?? 'assign'
!! 'p6store';
# nqp::unless(
# nqp::attrinited(self,Foo,'$!a'),
# (nqp::getattr(self,Foo,'$!a') =
Expand All @@ -3166,7 +3177,7 @@ class Perl6::World is HLL::World {
:value(nqp::atpos($task,2))
)
),
QAST::Op.new( :op<assign>,
QAST::Op.new( :$op,
$getattrop,
QAST::Op.new( :op<call>,
QAST::WVal.new(
Expand Down Expand Up @@ -3356,16 +3367,20 @@ class Perl6::World is HLL::World {
QAST::SVal.new( :value( nqp::atpos($task,2) ) )
);

#$execution.push(QAST::Op.new( :op('say'), QAST::SVal.new( :value("Initializing for 0: " ~ nqp::atpos($task,2) ~ ' - ' ~ nqp::atpos($task,3)) )));

# set assign operation to be used
my $sigil :=
nqp::substr(nqp::atpos($task,2),0,1);
my $op := $sigil eq '$' || $sigil eq '&'
?? 'assign'
!! 'p6store';
# nqp::if(
# nqp::existskey($init,'a'),
# nqp::getattr(self,Foo,'$!a') = %init.AT-KEY('a')
# ),
$stmts.push(
QAST::Op.new( :op<if>,
$existskeyop,
QAST::Op.new( :op<assign>,
QAST::Op.new( :$op,
$getattrop,
QAST::Op.new( :op<callmethod>,
QAST::Var.new(:scope<local>,:name('%init')),
Expand Down Expand Up @@ -3461,6 +3476,11 @@ class Perl6::World is HLL::World {
# Add the statements to the block
$block.push($stmts);

# :(Foo:D: %init)
my $sig := $!w.create_signature_and_params(
NQPMu, %sig_init, $block, 'Any', :method, :$invocant_type
);

# Create the code object and return it
$!w.create_code_object($block, 'Submethod', $sig)
}
Expand All @@ -3475,7 +3495,7 @@ class Perl6::World is HLL::World {

# submethod :: (Any:D:) { self }
my $block := QAST::Block.new(
:name<BUILDALL_UNDER_CONSTRUCTION>, :blocktype<declaration_static>,
:name<BUILDALL>, :blocktype<declaration_static>,
QAST::Stmts.new(
QAST::Var.new(:decl<param>, :scope<local>, :name<self>),
QAST::Var.new(:decl<param>, :scope<local>, :name('%init')),
Expand All @@ -3486,13 +3506,14 @@ class Perl6::World is HLL::World {
# Register the block in its SC
$!w.cur_lexpad()[0].push($block);

my $invocant_type := $!w.create_definite_type(
$!w.find_symbol(['Metamodel','DefiniteHOW']),
$!w.find_symbol(['Any']),
1
);

my $sig := $!w.create_signature_and_params(
NQPMu, %sig_init, $block, 'Any', :method,
invocant_type => $!w.create_definite_type(
$!w.find_symbol(['Metamodel','DefiniteHOW']),
$!w.find_symbol(['Any']),
1
)
NQPMu, %sig_init, $block, 'Any', :method, :$invocant_type
);

# Create the code object, save and return it
Expand Down
15 changes: 2 additions & 13 deletions src/core/Mu.pm
Expand Up @@ -108,17 +108,6 @@ Perhaps it can be found at https://docs.perl6.org/type/$name"
nqp::p6bool(nqp::isconcrete(self))
}

method new_UNDER_CONSTRUCTION(*%init) {
nqp::if(
nqp::eqaddr(
(my $bless := nqp::findmethod(self,'bless')),
nqp::findmethod(Mu,'bless')
),
nqp::create(self).BUILDALL_UNDER_CONSTRUCTION(%init),
nqp::invokewithcapture($bless,nqp::usecapture)
)
}

proto method new(|) { * }
multi method new(*%attrinit) {
nqp::if(
Expand Down Expand Up @@ -149,11 +138,11 @@ Perhaps it can be found at https://docs.perl6.org/type/$name"

# This candidate provided for those modules that rely on the old
# BUILDALL interface, such as Inline::Perl5
multi method BUILDALL(@positional,%attrinit) {
multi method BUILDALL(Mu:D: @positional,%attrinit) {
self.BUILDALL(%attrinit)
}

multi method BUILDALL(%attrinit) {
multi method BUILDALL(Mu:D: %attrinit) {
my $init := nqp::getattr(%attrinit,Map,'$!storage');
# Get the build plan. Note that we do this "low level" to
# avoid the NQP type getting mapped to a Rakudo one, which
Expand Down

0 comments on commit 63cf246

Please sign in to comment.