Skip to content

Commit

Permalink
Tease apart scalar init and default value.
Browse files Browse the repository at this point in the history
  • Loading branch information
jnthn committed Aug 18, 2013
1 parent 4d160b3 commit d3bd8df
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
12 changes: 10 additions & 2 deletions src/Perl6/Actions.nqp
Expand Up @@ -190,11 +190,14 @@ class Perl6::Actions is HLL::Actions does STDActions {
%info<bind_constraint> := $*W.parameterize_type_with_args(
%info<bind_constraint>, [@value_type[0]], nqp::hash());
%info<value_type> := @value_type[0];
%info<default_value> := @value_type[0];
}
else {
%info<container_type> := %info<container_base>;
%info<value_type> := $*W.find_symbol(['Mu']);
%info<default_value> := $*W.find_symbol(['Any']);
}
%info<default_value> := %info<value_type>;
if $shape {
$*W.throw($/, 'X::Comp::NYI', feature => 'Shaped arrays');
}
Expand Down Expand Up @@ -235,10 +238,12 @@ class Perl6::Actions is HLL::Actions does STDActions {
%info<bind_constraint> := $*W.parameterize_type_with_args(
%info<bind_constraint>, @value_type, nqp::hash());
%info<value_type> := @value_type[0];
%info<default_value> := @value_type[0];
}
else {
%info<container_type> := %info<container_base>;
%info<value_type> := $*W.find_symbol(['Mu']);
%info<default_value> := $*W.find_symbol(['Any']);
}
}
elsif $sigil eq '&' {
Expand All @@ -250,7 +255,8 @@ class Perl6::Actions is HLL::Actions does STDActions {
%info<bind_constraint>, [@value_type[0]], nqp::hash());
}
%info<value_type> := %info<bind_constraint>;
%info<default_value> := $*W.find_symbol(['Any']);
%info<default_value> := $*W.find_symbol(['Any']);
%info<scalar_value> := $*W.find_symbol(['Any']);
}
else {
%info<container_base> := $*W.find_symbol(['Scalar']);
Expand All @@ -265,6 +271,7 @@ class Perl6::Actions is HLL::Actions does STDActions {
%info<value_type> := $*W.find_symbol(['Mu']);
%info<default_value> := $*W.find_symbol(['Any']);
}
%info<scalar_value> := %info<default_value>;
}
%info
}
Expand Down Expand Up @@ -1251,7 +1258,7 @@ class Perl6::Actions is HLL::Actions does STDActions {
my $descriptor := $*W.create_container_descriptor($mu, 1, $sym);
my %info;
%info<container_type> := %info<container_base> := $*W.find_symbol(['Scalar']);
%info<default_value> := %info<bind_constraint> := %info<value_type> := $mu;
%info<scalar_value> := %info<default_value> := %info<bind_constraint> := %info<value_type> := $mu;
$*W.install_lexical_container($pad, $sym, %info, $descriptor, :scope('state'));

# generate code that runs the block only once
Expand Down Expand Up @@ -4785,6 +4792,7 @@ class Perl6::Actions is HLL::Actions does STDActions {
%cont{'container_type'} := $*W.find_symbol(['Scalar']);
%cont{'container_base'} := %cont{'container_type'};
%cont{'default_value'} := $zero.compile_time_value;
%cont{'scalar_value'} := $zero.compile_time_value;
$*W.install_lexical_container($*W.cur_lexpad(), $state, %cont,
$*W.create_container_descriptor(%cont{'bind_constraint'}, 1, $state),
:scope('state'));
Expand Down
13 changes: 7 additions & 6 deletions src/Perl6/World.nqp
Expand Up @@ -622,9 +622,9 @@ class Perl6::World is HLL::World {
# Build container.
my $cont := nqp::create(%cont_info<container_type>);
nqp::bindattr($cont, %cont_info<container_base>, '$!descriptor', $descriptor);
if nqp::existskey(%cont_info, 'default_value') {
if nqp::existskey(%cont_info, 'scalar_value') {
nqp::bindattr($cont, %cont_info<container_base>, '$!value',
%cont_info<default_value>);
%cont_info<scalar_value>);
}
self.add_object($cont);
$block.symbol($name, :value($cont));
Expand Down Expand Up @@ -667,6 +667,7 @@ class Perl6::World is HLL::World {
'bind_constraint', $Mu,
'value_type', $Mu,
'default_value', $Nil,
'scalar_value', $Nil,
);
$desc := self.create_container_descriptor($Mu, 1, $name, $Nil, 1);

Expand Down Expand Up @@ -697,13 +698,13 @@ class Perl6::World is HLL::World {

# Default contents, if applicable (note, slurpy param as we can't
# use definedness here, as it's a type object we'd be checking).
if nqp::existskey(%cont_info, 'default_value') {
if nqp::existskey(%cont_info, 'scalar_value') {
$cont_code.push(QAST::Op.new(
:op('bindattr'),
QAST::Var.new( :name($tmp), :scope('local') ),
QAST::WVal.new( :value(%cont_info<container_base>) ),
QAST::SVal.new( :value('$!value') ),
QAST::WVal.new( :value(%cont_info<default_value>) )));
QAST::WVal.new( :value(%cont_info<scalar_value>) )));
}

$cont_code
Expand Down Expand Up @@ -1495,9 +1496,9 @@ class Perl6::World is HLL::World {
# Build container.
my $cont := nqp::create(%cont_info<container_type>);
nqp::bindattr($cont, %cont_info<container_base>, '$!descriptor', $descriptor);
if nqp::existskey(%cont_info, 'default_value') {
if nqp::existskey(%cont_info, 'scalar_value') {
nqp::bindattr($cont, %cont_info<container_base>, '$!value',
%cont_info<default_value>);
%cont_info<scalar_value>);
}

# Create meta-attribute instance and add right away. Also add
Expand Down

0 comments on commit d3bd8df

Please sign in to comment.