Skip to content

Commit

Permalink
Generalize scopedlex to also handle puts
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan O'Rear committed Jul 16, 2010
1 parent d45d477 commit 0d2e83d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
3 changes: 2 additions & 1 deletion CgOp.pm
Expand Up @@ -203,7 +203,8 @@ use warnings;
}

sub scopedlex {
CgOp::NIL->new(ops => [[ scopelexget => $_[0] ]]);
my $n = shift;
CgOp::NIL->new(ops => [ @_, [ scopelex => $n, scalar @_ ]]);
}

sub lexput {
Expand Down
12 changes: 8 additions & 4 deletions CodeGen.pm
Expand Up @@ -572,8 +572,8 @@ use 5.010;

# These are completely derived.

sub scopelexget {
my ($self, $name) = @_;
sub scopelex {
my ($self, $name, $set) = @_;
my $body = $self->body // $self->bodies->[-1];
my ($order, $scope) = (0, $body);
while ($scope && !$scope->lexical->{$name}) {
Expand All @@ -583,7 +583,11 @@ use 5.010;
if (!$scope) {
die "Failed to resolve lexical $name in " . $body->name;
}
$self->lexget($order, $name);
if ($set) {
$self->lexput($order, $name);
} else {
$self->lexget($order, $name);
}
}

sub string_var {
Expand Down Expand Up @@ -611,7 +615,7 @@ use 5.010;

sub box {
my ($self, $ty) = @_;
$self->scopelexget($ty);
$self->scopelex($ty);
$self->fetch;
$self->clr_call_direct('Kernel.BoxAny', 2);
}
Expand Down
2 changes: 1 addition & 1 deletion Decl.pm
Expand Up @@ -248,7 +248,7 @@ use CgOp;

CgOp::sink(
CgOp::methodcall(CgOp::aux('how'), "add-super",
CgOp::scopedlex($self->name . "!HOW", $body)));
CgOp::scopedlex($self->name . "!HOW")));
}

__PACKAGE__->meta->make_immutable;
Expand Down

0 comments on commit 0d2e83d

Please sign in to comment.