Skip to content

Commit

Permalink
The great codegen refactor
Browse files Browse the repository at this point in the history
We no longer need to fake an evaluation stack and can use C#'s stack directly,
cutting an additional 10,000 lines off CORE.cs.  CORE.cs is down to 1/3 the
size it was at the beginning of this spree and compiles 5(!) times faster.
  • Loading branch information
sorear committed Jul 25, 2010
1 parent 0ec7b78 commit 7227acd
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 107 deletions.
47 changes: 40 additions & 7 deletions CgOp.pm
Expand Up @@ -48,11 +48,16 @@ use warnings;
my ($head, @kids) = @{ $self->zyg };
$head->var_cg($cg);
$cg->push_let($self->name);
for (@kids) {
$_->var_cg($cg);
for my $i (0 .. $#kids) {
$kids[$i]->var_cg($cg);
}
$cg->pop_let($self->name);
$cg->drop;
$cg->drop_let($self->name);
}

sub drop_end {
my ($self) = @_;
$self->zyg->[-1] = CgOp::sink($self->zyg->[-1]);
$self;
}

no Moose;
Expand All @@ -78,9 +83,13 @@ use warnings;

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

sub drop_end {
my ($self) = @_;
$self->zyg->[-1] = CgOp::sink($self->zyg->[-1]);
$self;
}

no Moose;
Expand Down Expand Up @@ -156,6 +165,30 @@ use warnings;

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

if ($self->op->[0] eq 'drop') {
# XXX C# has some fairly fiddly rules concerning what's legal to
# use in void context.
my $z = $self->zyg->[0];
if ($z->isa('CgOp::Primitive')) {
given ($z->op->[0]) {
when ("result") {
$z->zyg->[0]->var_cg($cg);
return;
}
when ("scopelex") {
return;
}
when ("push_null") {
return;
}
}
} elsif ($z->isa('CgOp::Let') || $z->isa('CgOp::Seq')) {
$z->drop_end->var_cg($cg);
return;
}
}

for (@{ $self->zyg }) {
$_->var_cg($cg);
}
Expand Down

0 comments on commit 7227acd

Please sign in to comment.