Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Resolve code-related objects in setting.
  • Loading branch information
jnthn committed Dec 13, 2015
1 parent a360f3b commit 3c81e33
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 36 deletions.
38 changes: 19 additions & 19 deletions src/Perl6/Actions.nqp
Expand Up @@ -1350,7 +1350,7 @@ Compilation unit '$file' contained the following violations:
}
# Handle phasers.
my $code := $loop[1].ann('code_object');
my $block_type := $*W.find_symbol(['Block']);
my $block_type := $*W.find_symbol(['Block'], :setting-only);
my $phasers := nqp::getattr($code, $block_type, '$!phasers');
if nqp::isnull($phasers) {
$loop[1] := pblock_immediate($loop[1]);
Expand Down Expand Up @@ -2154,7 +2154,7 @@ Compilation unit '$file' contained the following violations:
scope => $*SCOPE,
);
}
my $Routine := $*W.find_symbol(['Routine']);
my $Routine := $*W.find_symbol(['Routine'], :setting-only);
if $name eq '&?BLOCK' || nqp::istype($*CODE_OBJECT, $Routine) {
# Just need current code object.
$past := QAST::Op.new( :op('getcodeobj'), QAST::Op.new( :op('curcode') ) );
Expand Down Expand Up @@ -3030,7 +3030,7 @@ Compilation unit '$file' contained the following violations:
# Install.
my $predeclared := $outer.symbol($name);
if $predeclared {
unless nqp::getattr_i($predeclared<value>, $*W.find_symbol(['Routine']), '$!yada') {
unless nqp::getattr_i($predeclared<value>, $*W.find_symbol(['Routine'], :setting-only), '$!yada') {
$*W.throw($/, ['X', 'Redeclaration'],
symbol => ~$<deflongname>.ast,
what => 'routine',
Expand Down Expand Up @@ -3090,11 +3090,11 @@ Compilation unit '$file' contained the following violations:
# appropriate pragma is in effect.
if $<deflongname> {
if %*PRAGMAS<soft> {
$*W.find_symbol(['&infix:<does>'])($code, $*W.find_symbol(['SoftRoutine']));
$*W.find_symbol(['&infix:<does>'])($code, $*W.find_symbol(['SoftRoutine'], :setting-only));
}
elsif !nqp::can($code, 'CALL-ME') {
my $phasers :=
nqp::getattr($code,$*W.find_symbol(['Block']),'$!phasers');
nqp::getattr($code,$*W.find_symbol(['Block'], :setting-only),'$!phasers');
if nqp::isnull($phasers) || !nqp::p6bool($phasers) {
self.add_inlining_info_if_possible($/, $code, $signature, $block, @params);
}
Expand Down Expand Up @@ -3124,7 +3124,7 @@ Compilation unit '$file' contained the following violations:
QAST::Var.new(
:name('$!dispatch_cache'), :scope('attribute'),
QAST::Op.new( :op('getcodeobj'), QAST::Op.new( :op('curcode') ) ),
QAST::WVal.new( :value($*W.find_symbol(['Routine'])) ),
QAST::WVal.new( :value($*W.find_symbol(['Routine'], :setting-only)) ),
),
QAST::Op.new( :op('usecapture') )
),
Expand Down Expand Up @@ -3156,8 +3156,8 @@ Compilation unit '$file' contained the following violations:

# Ensure all parameters are simple and build placeholders for
# them.
my $Param := $*W.find_symbol(['Parameter']);
my @p_objs := nqp::getattr($sig, $*W.find_symbol(['Signature']), '$!params');
my $Param := $*W.find_symbol(['Parameter'], :setting-only);
my @p_objs := nqp::getattr($sig, $*W.find_symbol(['Signature'], :setting-only), '$!params');
my int $i := 0;
my int $n := nqp::elems(@params);
my %arg_placeholders;
Expand Down Expand Up @@ -3663,7 +3663,7 @@ Compilation unit '$file' contained the following violations:
QAST::Var.new(
:name('$!dispatch_cache'), :scope('attribute'),
QAST::Op.new( :op('getcodeobj'), QAST::Op.new( :op('curcode') ) ),
QAST::WVal.new( :value($*W.find_symbol(['Routine'])) ),
QAST::WVal.new( :value($*W.find_symbol(['Routine'], :setting-only)) ),
),
QAST::Op.new( :op('usecapture') )
),
Expand Down Expand Up @@ -3784,7 +3784,7 @@ Compilation unit '$file' contained the following violations:
install_method($/, $name, $scope, $code, $outer) if $name ne '';

# Bind original source to $!source
my $Regex := $*W.find_symbol(['Regex']);
my $Regex := $*W.find_symbol(['Regex'], :setting-only);
my $source := ($*METHODTYPE ?? $*METHODTYPE ~ ' ' !! '') ~ $/;
my $match := $source ~~ /\s+$/;

Expand Down Expand Up @@ -4402,7 +4402,7 @@ Compilation unit '$file' contained the following violations:
# Attach the dummy param we set up in Grammar::param_var to PARAM_INFO,
# so we can access it later on. The dummy param may have goodies like
# trailing docs!
my $par_type := $*W.find_symbol(['Parameter']);
my $par_type := $*W.find_symbol(['Parameter'], :setting-only);
if nqp::istype($*PRECEDING_DECL, $par_type) {
%*PARAM_INFO<dummy> := $*PRECEDING_DECL;
}
Expand Down Expand Up @@ -5289,7 +5289,7 @@ Compilation unit '$file' contained the following violations:
QAST::Var.new(
:name('$!dispatch_cache'), :scope('attribute'),
QAST::Var.new( :name('&*CURRENT_DISPATCHER'), :scope('lexical') ),
QAST::WVal.new( :value($*W.find_symbol(['Routine'])) ),
QAST::WVal.new( :value($*W.find_symbol(['Routine'], :setting-only)) ),
),
QAST::Var.new( :name($dc_name), :scope('local') )
),
Expand Down Expand Up @@ -5555,7 +5555,7 @@ Compilation unit '$file' contained the following violations:
my $subelem := $elem[0];
if $subelem ~~ QAST::Op && $subelem.op eq 'callmethod' && $subelem.name eq 'clone' {
$subelem := $subelem[0];
if $subelem ~~ QAST::WVal && nqp::istype($subelem.value, $*W.find_symbol(['WhateverCode'])) {
if $subelem ~~ QAST::WVal && nqp::istype($subelem.value, $*W.find_symbol(['WhateverCode'], :setting-only)) {
$/.CURSOR.malformed("double closure; WhateverCode is already a closure without curlies, so either remove the curlies or use valid parameter syntax instead of *");
}
}
Expand Down Expand Up @@ -6038,7 +6038,7 @@ Compilation unit '$file' contained the following violations:
$target.annotate('nosink', 1);
make $target;
}
elsif $target.isa(QAST::WVal) && nqp::istype($target.value, $*W.find_symbol(['Signature'])) {
elsif $target.isa(QAST::WVal) && nqp::istype($target.value, $*W.find_symbol(['Signature'], :setting-only)) {
make QAST::Op.new(
:op('p6bindcaptosig'),
$target,
Expand Down Expand Up @@ -7398,8 +7398,8 @@ Compilation unit '$file' contained the following violations:
my @result;
my $clear_topic_bind;
my $saw_slurpy;
my $Sig := $*W.find_symbol(['Signature']);
my $Param := $*W.find_symbol(['Parameter']);
my $Sig := $*W.find_symbol(['Signature'], :setting-only);
my $Param := $*W.find_symbol(['Parameter'], :setting-only);
my $Iterable := $*W.find_symbol(['Iterable']);
my @p_objs := nqp::getattr($sig, $Sig, '$!params');
my int $i := 0;
Expand Down Expand Up @@ -7808,7 +7808,7 @@ Compilation unit '$file' contained the following violations:
:op('istrue'),
QAST::Op.new(
:op('callmethod'), :name('ACCEPTS'),
nqp::istype($_, $*W.find_symbol(['Code']))
nqp::istype($_, $*W.find_symbol(['Code'], :setting-only))
?? QAST::Op.new( :op('p6capturelex'),
QAST::Op.new( :op('callmethod'), :name('clone'), $wval ) )
!! $wval,
Expand Down Expand Up @@ -8302,8 +8302,8 @@ Compilation unit '$file' contained the following violations:
my int $whatevers := 0;
my int $hyperwhatever := 0;

my $Whatever := $*W.find_symbol(['Whatever']);
my $WhateverCode := $*W.find_symbol(['WhateverCode']);
my $Whatever := $*W.find_symbol(['Whatever'], :setting-only);
my $WhateverCode := $*W.find_symbol(['WhateverCode'], :setting-only);
my $HyperWhatever := $*W.find_symbol(['HyperWhatever']);

while $i < $e {
Expand Down
2 changes: 1 addition & 1 deletion src/Perl6/Grammar.nqp
Expand Up @@ -2805,7 +2805,7 @@ grammar Perl6::Grammar is HLL::Grammar does STD {
my $line_no := HLL::Compiler.lineof(self.orig(), self.from(), :cache(1));
if $*PRECEDING_DECL_LINE < $line_no {
$*PRECEDING_DECL_LINE := $line_no;
my $par_type := $*W.find_symbol(['Parameter']);
my $par_type := $*W.find_symbol(['Parameter'], :setting-only);
$*PRECEDING_DECL := nqp::create($par_type); # actual declarand comes later, in World::create_parameter
}
}
Expand Down
37 changes: 21 additions & 16 deletions src/Perl6/World.nqp
Expand Up @@ -1601,7 +1601,7 @@ class Perl6::World is HLL::World {
# Creates a parameter object.
method create_parameter($/, %param_info) {
# Create parameter object now.
my $par_type := self.find_symbol(['Parameter']);
my $par_type := self.find_symbol(['Parameter'], :setting-only);
my $parameter := nqp::create($par_type);
self.add_object($parameter);

Expand Down Expand Up @@ -1818,7 +1818,7 @@ class Perl6::World is HLL::World {
# If it's natively typed and we got "is rw" set, need to mark the
# container as being a lexical ref.
if $varname && nqp::objprimspec($_<nominal_type>) {
my $param_type := self.find_symbol(['Parameter']);
my $param_type := self.find_symbol(['Parameter'], :setting-only);
my int $flags := nqp::getattr_i($param_obj, $param_type, '$!flags');
if $flags +& $SIG_ELEM_IS_RW {
for @($lexpad[0]) {
Expand Down Expand Up @@ -1849,7 +1849,7 @@ class Perl6::World is HLL::World {
# Creates a signature object from a set of parameters.
method create_signature(%signature_info) {
# Create signature object now.
my $sig_type := self.find_symbol(['Signature']);
my $sig_type := self.find_symbol(['Signature'], :setting-only);
my $signature := nqp::create($sig_type);
my @parameters := %signature_info<parameter_objects>;
self.add_object($signature);
Expand All @@ -1861,7 +1861,7 @@ class Perl6::World is HLL::World {
}

# Compute arity and count.
my $p_type := self.find_symbol(['Parameter']);
my $p_type := self.find_symbol(['Parameter'], :setting-only);
my int $arity := 0;
my int $count := 0;
my int $i := 0;
Expand Down Expand Up @@ -1926,7 +1926,7 @@ class Perl6::World is HLL::World {

# Stubs a code object of the specified type.
method stub_code_object($type) {
my $type_obj := self.find_symbol([$type]);
my $type_obj := self.find_symbol([$type], :setting-only);
my $code := nqp::create($type_obj);
@!CODES[+@!CODES] := $code;
self.add_object($code);
Expand All @@ -1936,8 +1936,8 @@ class Perl6::World is HLL::World {
# Attaches a signature to a code object, and gives the
# signature its backlink to the code object.
method attach_signature($code, $signature) {
my $code_type := self.find_symbol(['Code']);
my $sig_type := self.find_symbol(['Signature']);
my $code_type := self.find_symbol(['Code'], :setting-only);
my $sig_type := self.find_symbol(['Signature'], :setting-only);
nqp::bindattr($code, $code_type, '$!signature', $signature);
nqp::bindattr($signature, $sig_type, '$!code', $code);
}
Expand All @@ -1956,8 +1956,8 @@ class Perl6::World is HLL::World {
@!CODES.pop();

# Locate various interesting symbols.
my $code_type := self.find_symbol(['Code']);
my $routine_type := self.find_symbol(['Routine']);
my $code_type := self.find_symbol(['Code'], :setting-only);
my $routine_type := self.find_symbol(['Routine'], :setting-only);

# Attach code object to QAST node.
$code_past.annotate('code_object', $code);
Expand Down Expand Up @@ -2131,7 +2131,7 @@ class Perl6::World is HLL::World {

# Adds any extra code needing for handling phasers.
method add_phasers_handling_code($code, $code_past) {
my $block_type := self.find_symbol(['Block']);
my $block_type := self.find_symbol(['Block'], :setting-only);
if nqp::istype($code, $block_type) {
my %phasers := nqp::getattr($code, $block_type, '$!phasers');
unless nqp::isnull(%phasers) {
Expand Down Expand Up @@ -2519,7 +2519,7 @@ class Perl6::World is HLL::World {
while nqp::istype($inspect, QAST::Op) {
$inspect := $inspect[0];
}
if nqp::istype($inspect, QAST::WVal) && !nqp::istype($inspect.value, self.find_symbol(["Block"])) {
if nqp::istype($inspect, QAST::WVal) && !nqp::istype($inspect.value, self.find_symbol(["Block"], :setting-only)) {
$/.CURSOR.panic($mkerr());
}
else {
Expand Down Expand Up @@ -2666,7 +2666,7 @@ class Perl6::World is HLL::World {
# Compile it immediately (we always compile role bodies as
# early as possible, but then assume they don't need to be
# re-compiled and re-fixed up at startup).
self.compile_in_context($past, self.find_symbol(['Code']));
self.compile_in_context($past, self.find_symbol(['Code'], :setting-only));
}

# Adds a possible role to a role group.
Expand Down Expand Up @@ -2977,7 +2977,7 @@ class Perl6::World is HLL::World {
$phaser_past[0].unshift(QAST::Var.new( :name('$_'), :scope('lexical'), :decl('var') ));
}
nqp::push(
nqp::getattr($block.signature, self.find_symbol(['Signature']), '$!params'),
nqp::getattr($block.signature, self.find_symbol(['Signature'], :setting-only), '$!params'),
self.create_parameter($/, hash(
variable_name => '$_', is_raw => 1,
nominal_type => self.find_symbol(['Mu'])
Expand Down Expand Up @@ -3408,7 +3408,7 @@ class Perl6::World is HLL::World {
my $result := 0;
try {
my $maybe_regex := self.find_symbol([$name]);
$result := nqp::istype($maybe_regex, self.find_symbol(['Regex']));
$result := nqp::istype($maybe_regex, self.find_symbol(['Regex'], :setting-only));
}
$result
}
Expand Down Expand Up @@ -3447,11 +3447,16 @@ class Perl6::World is HLL::World {
return $*GLOBALish;
}

# Work out where to start searching.
my int $start_scope := $setting-only
?? ($*COMPILING_CORE_SETTING ?? 2 !! 1)
!! nqp::elems(@!BLOCKS);

# If it's a single-part name, look through the lexical
# scopes.
if +@name == 1 {
my $final_name := @name[0];
my int $i := $setting-only ?? 1 !! +@!BLOCKS;
my int $i := $start_scope;
while $i > 0 {
$i := $i - 1;
my %sym := @!BLOCKS[$i].symbol($final_name);
Expand All @@ -3467,7 +3472,7 @@ class Perl6::World is HLL::World {
my $result := $*GLOBALish;
if +@name >= 2 {
my $first := @name[0];
my int $i := $setting-only ?? 1 !! +@!BLOCKS;
my int $i := $start_scope;
while $i > 0 {
$i := $i - 1;
my %sym := @!BLOCKS[$i].symbol($first);
Expand Down

0 comments on commit 3c81e33

Please sign in to comment.