Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[mm] implement WhateverCode and transparent blocks
  • Loading branch information
sorear committed Sep 19, 2010
1 parent 78739fd commit 76df230
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 23 deletions.
24 changes: 19 additions & 5 deletions src/Metamodel.pm
Expand Up @@ -333,7 +333,7 @@ sub Body::begin {

my $top = @opensubs ? $opensubs[-1] : undef;

push @opensubs, Metamodel::StaticSub->new(
my $metabody = Metamodel::StaticSub->new(
outer => $top,
body_of => $args{body_of},
augmenting => $args{augmenting},
Expand All @@ -342,16 +342,22 @@ sub Body::begin {
class => $self->class,
run_once => $args{once} && (!defined($top) || $top->run_once));

push @opensubs, $metabody; # always visible in the signature XXX

if ($self->signature) {
$self->signature->begin;
$opensubs[-1]->signature($self->signature);
$metabody->signature($self->signature);
}

pop @opensubs if $self->transparent;

$self->do->begin;
$opensubs[-1]->code($self->do);
$metabody->code($self->do);

$metabody->close;
pop @opensubs unless $self->transparent;

$opensubs[-1]->close;
pop @opensubs;
$metabody;
}

sub Sig::begin {
Expand Down Expand Up @@ -415,6 +421,14 @@ sub Op::SubDef::begin {
delete $self->{$_} for (qw( body method_too proto_too exports once ));
}

sub Op::WhateverCode::begin {
my $self = shift;
my $body = Body->new(name => 'ANON', transparent => 1, do => $self->ops,
signature => Sig->simple(@{ $self->vars }));
delete $self->{$_} for (qw( vars ops ));
$opensubs[-1]->add_my_sub($self->slot, $body->begin);
}

sub Op::Start::begin {
my $self = shift;
$opensubs[-1]->add_state_name(undef, $self->condvar);
Expand Down
18 changes: 0 additions & 18 deletions src/Op.pm
Expand Up @@ -15,11 +15,6 @@ use CgOp;

sub zyg { }

sub lift_decls {
my ($self) = shift;
map { $_->lift_decls } $self->zyg;
}

sub cgop {
my ($self, $body) = @_;
if (defined $self->file) {
Expand Down Expand Up @@ -548,12 +543,6 @@ use CgOp;
has body => (isa => 'Op', is => 'ro', required => 1);
sub zyg { $_[0]->body }

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

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

Expand Down Expand Up @@ -818,13 +807,6 @@ use CgOp;
has vars => (isa => 'ArrayRef[Str]', is => 'ro', required => 1);
has slot => (isa => 'Str', is => 'ro', required => 1);

sub lift_decls {
my ($self) = @_;
Decl::Sub->new(var => $self->slot, code => Body->new(
name => "whatever-anon", type => 'sub', transparent => 1,
do => $self->ops, signature => Sig->simple(@{ $self->vars })));
}

sub code {
my ($self, $body) = @_;
CgOp::scopedlex($self->slot);
Expand Down

0 comments on commit 76df230

Please sign in to comment.