Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Allow list-valued constants
  • Loading branch information
sorear committed Oct 15, 2010
1 parent 8c6552e commit 0644834
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 8 deletions.
11 changes: 11 additions & 0 deletions src/Metamodel.pm
Expand Up @@ -908,6 +908,17 @@ sub Op::CallMethod::begin {
}
}

sub Op::ConstantDecl::begin {
my $self = shift;

if ($self->path) {
$opensubs[-1]->add_common_name($self->name,
$opensubs[-1]->find_pkg($self->path), $self->name);
} else {
$opensubs[-1]->add_my_name($self->name);
}
}

sub Op::PackageVar::begin {
my $self = shift;

Expand Down
13 changes: 6 additions & 7 deletions src/Niecza/Actions.pm
Expand Up @@ -1036,6 +1036,10 @@ sub INFIX { my ($cl, $M) = @_;
Op::Start->new(condvar => $cv, body => $M->{_ast}),
Op::Lexical->new(name => $l->name)]);
}
elsif ($s eq '&infix:<=>' && $l->isa('Op::ConstantDecl') && !$l->init) {
$l->init($r);
$M->{_ast} = $l;
}
}
$M->{_ast} = $cl->whatever_postcheck($M, $st, $M->{_ast});
}
Expand Down Expand Up @@ -1926,13 +1930,8 @@ sub type_declarator__S_constant { my ($cl, $M) = @_;
}
my $slot = ($M->{identifier} // $M->{variable})->Str;

# This is a cheat. Constants should be, well, constant, and we should be
# using the phaser rewrite mechanism to get the initializer here. XXX
# terms need to use a context hash.
$M->{_ast} = ($::SCOPE eq 'our') ?
Op::PackageVar->new(node($M), name => $slot, slot => $slot,
path => [ 'OUR' ]) :
Op::Lexical->new(node($M), name => $slot, declaring => 1);
$M->{_ast} = Op::ConstantDecl->new(node($M), name => $slot,
path => ($::SCOPE eq 'our' ? [ 'OUR' ] : undef));
}

sub package_declarator {}
Expand Down
18 changes: 18 additions & 0 deletions src/Op.pm
Expand Up @@ -840,6 +840,24 @@ use CgOp;
no Moose;
}

{
package Op::ConstantDecl;
use Moose;
extends 'Op';

has name => (isa => 'Str', is => 'ro', required => 1);
has init => (isa => 'Op', is => 'rw');
has path => (isa => 'Maybe[ArrayRef]', is => 'ro');

sub code {
my ($self, $body) = @_;
CgOp::rnull(CgOp::scopedlex($self->name, $self->init->cgop($body)));
}

__PACKAGE__->meta->make_immutable;
no Moose;
}

{
package Op::ContextVar;
use Moose;
Expand Down
2 changes: 1 addition & 1 deletion v6/STD.pm6
Expand Up @@ -5402,7 +5402,7 @@ method add_my_name ($n, $d?, $p?) {
$*DECLARAND<inlex> = $curstash.idref;
$*DECLARAND<signum> = $*SIGNUM if $*SIGNUM;
$*DECLARAND<const> = $*DECLARAND<const> || 1 if $*IN_DECL eq 'constant';
$*DECLARAND<used> = 1 if substr($name,0,1) eq '&' and %::MYSTERY{substr($name,1)};
$*DECLARAND<used> = 1 if substr($name,0,1) eq '&' and %*MYSTERY{substr($name,1)};
if !$*DECLARAND<const> and $shortname ~~ /^\w+$/ {
$curstash.{"\&$shortname"} = $curstash.{"\&$shortname"} // $curstash.{$shortname};
$curstash.{"\&$shortname"}<used> = 1;
Expand Down

0 comments on commit 0644834

Please sign in to comment.