Skip to content

Commit

Permalink
Revert "* Body.pm, CgOp.pm and Decl.pm are now in MooseX::Declare syn…
Browse files Browse the repository at this point in the history
…tax."

This reverts commit 4dc75bb.
  • Loading branch information
Audrey Tang committed Jul 20, 2010
1 parent 2a2ae2d commit 58c7a4a
Show file tree
Hide file tree
Showing 3 changed files with 211 additions and 59 deletions.
27 changes: 20 additions & 7 deletions Body.pm
@@ -1,9 +1,13 @@
use strict;
use warnings;
use 5.010;
use MooseX::Declare;
use CodeGen ();
use CgOp ();

class Body {
{
package Body;
use Moose;

has name => (isa => 'Str', is => 'rw', default => "anon");
has do => (isa => 'Op', is => 'rw');
has enter => (isa => 'ArrayRef[Op]', is => 'ro',
Expand All @@ -20,7 +24,9 @@ class Body {
# also '' for incorrectly contextualized {p,x,}block, blast
has type => (isa => 'Str', is => 'rw');

method is_mainline () {
sub is_mainline {
my $self = shift;

if ($self->type && $self->type eq 'mainline') {
return 1;
}
Expand All @@ -36,14 +42,16 @@ class Body {
}
}

method gen_code () {
sub gen_code {
my ($self) = @_;
# TODO: Bind a return value here to catch non-ro sub use
CodeGen->new(name => $self->name, body => $self,
ops => CgOp::prog($self->enter_code,
CgOp::return($self->do->code($self))));
}

method enter_code () {
sub enter_code {
my ($self) = @_;
my @p;
push @p, CgOp::lextypes(map { $_, 'Variable' }
keys %{ $self->lexical });
Expand All @@ -53,14 +61,19 @@ class Body {
CgOp::prog(@p);
}

method write () {
sub write {
my ($self) = @_;
$self->code->write;
$_->write($self) for (@{ $self->decls });
}

method preinit_code () {
sub preinit_code {
my ($self) = @_;
CgOp::prog(map { $_->preinit_code($self) } @{ $self->decls });
}

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

1;
72 changes: 60 additions & 12 deletions CgOp.pm
@@ -1,22 +1,43 @@
use 5.010;
use MooseX::Declare;
use strict;
use warnings;


{
package CgOp;
use Moose;

class CgOp {
has zyg => (isa => 'ArrayRef', is => 'ro', default => sub { [] });

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

class CgOp::Seq extends CgOp {
method var_cg ($cg) {
{
package CgOp::Seq;
use Moose;
extends 'CgOp';

sub var_cg {
my ($self, $cg) = @_;
for (@{ $self->zyg }) {
$_->var_cg($cg);
}
}

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

class CgOp::Primitive extends CgOp {
{
package CgOp::Primitive;
use Moose;
extends 'CgOp';

has op => (isa => 'ArrayRef', is => 'ro', required => 1);

method var_cg ($cg) {
sub var_cg {
my ($self, $cg) = @_;
for (@{ $self->zyg }) {
$_->var_cg($cg);
}
Expand All @@ -26,10 +47,18 @@ class CgOp::Primitive extends CgOp {
}
$cg->$c(@o);
}

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

class CgOp::Ternary extends CgOp {
method var_cg ($cg) {
{
package CgOp::Ternary;
use Moose;
extends 'CgOp';

sub var_cg {
my ($self, $cg) = @_;
my ($check, $true, $false) = @{ $self->zyg };
my $l1 = $cg->label;
my $l2 = $cg->label;
Expand All @@ -42,13 +71,21 @@ class CgOp::Ternary extends CgOp {
$false->var_cg($cg);
$cg->labelhere($l2);
}

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

class CgOp::While extends CgOp {
{
package CgOp::While;
use Moose;
extends 'CgOp';

has once => (is => 'ro', isa => 'Bool');
has until => (is => 'ro', isa => 'Bool');

method var_cg ($cg) {
sub var_cg {
my ($self, $cg) = @_;
my ($check, $body) = @{ $self->zyg };
my $lagain = $cg->label;
my $lcheck = $self->once ? 0 : $cg->label;
Expand All @@ -66,13 +103,21 @@ class CgOp::While extends CgOp {
$cg->cgoto($lagain);
}
}

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

class CgOp::Let extends CgOp {
{
package CgOp::Let;
use Moose;
extends 'CgOp';

has var => (is => 'ro', isa => 'Str', required => 1);
has type => (is => 'ro', isa => 'Str', required => 1);

method var_cg ($cg) {
sub var_cg {
my ($self, $cg) = @_;

$cg->lextypes($self->var, $self->type);
$self->zyg->[0]->var_cg($cg);
Expand All @@ -81,6 +126,9 @@ class CgOp::Let extends CgOp {
$cg->push_null($self->type);
$cg->rawlexput($self->var, 0);
}

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

# just a bunch of smart constructors
Expand Down

0 comments on commit 58c7a4a

Please sign in to comment.