diff --git a/Body.pm b/Body.pm index d6564b06..3a48b4d9 100644 --- a/Body.pm +++ b/Body.pm @@ -23,10 +23,12 @@ use CgOp (); # also '' for incorrectly contextualized {p,x,}block, blast has type => (isa => 'Str', is => 'rw'); - sub lexical { + has lexical => (isa => 'HashRef[Str]', is => 'ro', lazy_build => 1); + + sub _build_lexical { my ($self) = @_; - +{ map { $_, 1 } map { $_->used_slots } @{ $self->decls } }; + +{ map { $_->used_slots } @{ $self->decls } }; } sub is_mainline { @@ -51,6 +53,7 @@ use CgOp (); my ($self) = @_; # TODO: Bind a return value here to catch non-ro sub use CodeGen->new(name => $self->name, body => $self, + lex2type => +{ %{ $self->lexical } }, ops => CgOp::prog($self->enter_code, CgOp::return($self->do->code($self)))); } @@ -58,8 +61,6 @@ use CgOp (); sub enter_code { my ($self) = @_; my @p; - push @p, CgOp::lextypes(map { $_, 'Variable' } - keys %{ $self->lexical }); push @p, map { $_->enter_code($self) } @{ $self->decls }; push @p, $self->signature->binder if $self->signature; push @p, map { CgOp::sink($_->code($self)) } @{ $self->enter }; diff --git a/Decl.pm b/Decl.pm index fc1eaefe..91c0270c 100644 --- a/Decl.pm +++ b/Decl.pm @@ -10,7 +10,7 @@ use CgOp; has zyg => (is => 'ro', isa => 'ArrayRef', default => sub { [] }); - sub used_slots { } + sub used_slots { () } sub preinit_code { CgOp::noop } sub enter_code { CgOp::noop } sub write {} @@ -30,7 +30,7 @@ use CgOp; sub used_slots { my ($self) = @_; - return $self->has_var ? ($self->var) : (); + $self->has_var ? ($self->var, 'Variable') : (); } sub preinit_code { @@ -66,7 +66,7 @@ use CgOp; has code => (isa => 'Body', is => 'ro', required => 1); sub used_slots { - return $_[0]->var; + $_[0]->var, 'Variable'; } sub preinit_code { @@ -103,7 +103,7 @@ use CgOp; has list => (isa => 'Bool', is => 'ro', default => 0); sub used_slots { - return $_[0]->slot; + $_[0]->slot, 'Variable'; } sub preinit_code { @@ -143,7 +143,7 @@ use CgOp; has backing => (isa => 'Str', is => 'ro', required => 1); sub used_slots { - return $_[0]->slot; + $_[0]->slot, 'Variable'; } sub preinit_code { @@ -165,7 +165,7 @@ use CgOp; use Moose; extends 'Decl'; - sub used_slots { '!mainline' } + sub used_slots { '!mainline', 'Variable' } sub preinit_code { my ($self, $body) = @_; @@ -206,11 +206,8 @@ use CgOp; sub used_slots { my ($self) = @_; - if ($self->stub) { - ($self->var, $self->var . '!HOW'); - } else { - ($self->var, $self->var . '!HOW', $self->bodyvar); - } + $self->var, 'Variable', ($self->var . '!HOW'), 'Variable', + (!$self->stub ? ($self->bodyvar, 'Variable') : ()); } sub preinit_code {