Skip to content

Commit

Permalink
Move state completely to the new model
Browse files Browse the repository at this point in the history
  • Loading branch information
sorear committed Jul 22, 2010
1 parent b08dd5f commit 4da1598
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
12 changes: 8 additions & 4 deletions Decl.pm
Expand Up @@ -146,12 +146,12 @@ use CgOp;
use Moose;
extends 'Decl';

has slot => (isa => 'Str', is => 'ro', required => 1);
has slot => (isa => 'Str', is => 'ro', required => 0);
has backing => (isa => 'Str', is => 'ro', required => 1);
has list => (isa => 'Bool', is => 'ro', default => 0);

sub used_slots {
$_[0]->slot, 'Variable';
$_[0]->slot ? ($_[0]->slot, 'Variable') : ();
}

sub outer_decls {
Expand All @@ -161,12 +161,16 @@ use CgOp;

sub preinit_code {
my ($self, $body) = @_;
CgOp::proto_var($self->slot, CgOp::scopedlex($self->backing));
$self->slot ?
CgOp::proto_var($self->slot, CgOp::scopedlex($self->backing)) :
CgOp::noop;
}

sub enter_code {
my ($self, $body) = @_;
CgOp::scopedlex($self->slot, CgOp::scopedlex($self->backing));
$self->slot ?
CgOp::scopedlex($self->slot, CgOp::scopedlex($self->backing)) :
CgOp::noop;
}

__PACKAGE__->meta->make_immutable;
Expand Down
9 changes: 3 additions & 6 deletions Niecza/Actions.pm
Expand Up @@ -283,7 +283,6 @@ sub INFIX { my ($cl, $M) = @_;
# Assignments (and assign metaops, but we don't do that yet) to has
# and state declarators are rewritten into an appropriate phaser
my $cv = $cl->gensym;
$cl->add_decl(Decl::StateVar->new(backing => $cl->gensym, slot => $cv));
$M->{_ast} = Op::StatementList->new(children => [
Op::Start->new(condvar => $cv, body => $M->{_ast}),
Op::Lexical->new(name => $l->name)]);
Expand Down Expand Up @@ -801,9 +800,9 @@ sub variable_declarator { my ($cl, $M) = @_;
}

if ($scope eq 'state') {
$cl->add_decl(Decl::StateVar->new(backing => $cl->gensym,
slot => $slot, list => scalar ($M->{variable}->Str =~ /^\@/)));
$M->{_ast} = Op::Lexical->new(name => $slot, state_decl => 1);
$M->{_ast} = Op::Lexical->new(name => $slot, state_decl => 1,
state_backing => $cl->gensym, declaring => 1,
list => scalar ($M->{variable}->Str =~ /^\@/));
} else {
$M->{_ast} = Op::Lexical->new(name => $slot, declaring => 1,
list => scalar ($M->{variable}->Str =~ /^\@/));
Expand Down Expand Up @@ -1164,8 +1163,6 @@ sub statement_prefix__S_PREMinusINIT { my ($cl, $M) = @_;

sub statement_prefix__S_START { my ($cl, $M) = @_;
my $cv = $cl->gensym;
$cl->add_decl(Decl::StateVar->new(backing => $cl->gensym, slot => $cv));

$M->{_ast} = Op::Start->new(condvar => $cv, body =>
$cl->block_to_immediate('phaser', $M->{blast}{_ast}));
}
Expand Down
18 changes: 16 additions & 2 deletions Op.pm
Expand Up @@ -331,6 +331,12 @@ use CgOp;
has body => (isa => 'Op', is => 'ro', required => 1);
sub zyg { $_[0]->body }

sub local_decls {
my ($self) = @_;
Decl::StateVar->new(backing => $self->condvar),
$self->SUPER::local_decls(@_);
}

sub code {
my ($self, $body) = @_;

Expand Down Expand Up @@ -480,15 +486,23 @@ use CgOp;
has declaring => (isa => 'Bool', is => 'ro');
has list => (isa => 'Bool', is => 'ro');

has state_backing => (isa => 'Str', is => 'ro');

sub local_decls {
my ($self) = @_;
$self->declaring ?
(Decl::SimpleVar->new(slot => $self->name, list => $self->list)) :
($self->state_backing ?
(Decl::StateVar->new(slot => $self->name,
backing => $self->state_backing, list => $self->list)) :
(Decl::SimpleVar->new(slot => $self->name,
list => $self->list))) :
();
}

sub paren {
Op::Lexical->new(name => shift()->name);
my %p = %{ $_[0] };
$p{state_decl} = 0;
Op::Lexical->new(%p);
}

sub code {
Expand Down

0 comments on commit 4da1598

Please sign in to comment.