Skip to content

Commit

Permalink
Overhaul handling of names; make &infix:<+> and leading double colons…
Browse files Browse the repository at this point in the history
… work
  • Loading branch information
sorear committed Aug 10, 2010
1 parent 8ea4ced commit 4ecd8ab
Show file tree
Hide file tree
Showing 5 changed files with 205 additions and 78 deletions.
17 changes: 6 additions & 11 deletions Body.pm
Expand Up @@ -15,8 +15,7 @@ use CgOp ();
has signature => (isa => 'Maybe[Sig]', is => 'ro');
has mainline => (isa => 'Bool', is => 'ro', lazy => 1,
builder => 'is_mainline');
# currently used types are phaser, loop, cond, class, mainline, bare, sub
# also '' for incorrectly contextualized {p,x,}block, blast
# '' for incorrectly contextualized {p,x,}block, blast
has type => (isa => 'Str', is => 'rw');

has lexical => (isa => 'HashRef[Str]', is => 'rw');
Expand Down Expand Up @@ -154,20 +153,15 @@ use CgOp ();
sub lookup_var {
my ($self, $name, @path) = @_;

if (@path) {
return $self->lookup_pkg((map { $_ . "::" } @path),
(defined $name) ? ($name) : ());
} else {
# This is supposed to dwimmily do MY:: or OUR::, neither of which
# is implemented. So...
die "\$::x is not yet implemented";
}
return $self->lookup_pkg((map { $_ . "::" } @path),
(defined $name) ? ($name) : ());
}

sub lookup_pkg {
my ($self, @components) = @_;

my $pkgcg;
my $usedstate = 0;
# TODO: S02 says PROCESS:: and GLOBAL:: are also accessible as lexical
# packages in UNIT::.
if ($components[0] eq 'PROCESS::') {
Expand All @@ -181,6 +175,7 @@ use CgOp ();
shift @components;
} elsif ($self->lex_level($components[0]) >= 0) {
$pkgcg = CgOp::scopedlex($components[0]);
$usedstate = 1 unless $components[0] =~ /::$/;
shift @components;
} else {
$pkgcg = CgOp::scopedlex('$?CURPKG');
Expand All @@ -191,7 +186,7 @@ use CgOp ();
CgOp::clr_string($c));
}

$pkgcg;
$usedstate, $pkgcg;
}

__PACKAGE__->meta->make_immutable;
Expand Down
22 changes: 13 additions & 9 deletions Decl.pm
Expand Up @@ -152,7 +152,7 @@ use CgOp;
sub preinit_code {
my ($self, $body) = @_;

CgOp::bind(1, $body->lookup_var($self->name, @{ $self->path }),
CgOp::bind(1, ($body->lookup_var($self->name, @{ $self->path }))[1],
CgOp::scopedlex($self->slot));
}

Expand All @@ -176,9 +176,9 @@ use CgOp;

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

CgOp::proto_var($self->slot,
$body->lookup_var($self->name, @{ $self->path }));
my ($st, $cg) = $body->lookup_var($self->name, @{ $self->path });
Carp::confess("bad use of OurAlias") if $st;
CgOp::proto_var($self->slot, $cg);
}

sub enter_code {
Expand Down Expand Up @@ -264,6 +264,11 @@ use CgOp;
sub bodies { $_[0]->body ? $_[0]->body : () }
sub stashvar { $_[0]->var . '::' }

sub stash {
my ($self, $body, $suf) = @_;
($body->lookup_pkg(@{ $self->ourpkg }, $self->name . $suf))[1];
}

sub used_slots {
my ($self) = @_;
$self->var, 'Variable', $self->stashvar,
Expand All @@ -280,13 +285,12 @@ use CgOp;
return CgOp::prog(
CgOp::proto_var($self->var, CgOp::newscalar(CgOp::null('IP6'))),
CgOp::proto_var($self->stashvar,
($self->ourpkg ? $body->lookup_pkg(@{ $self->ourpkg }, $self->name . "::") :
($self->ourpkg ? $self->stash($body, '::') :
CgOp::wrap(CgOp::rawnew('Dictionary<string,Variable>')))));
}

CgOp::letn("pkg",
($self->ourpkg ?
$body->lookup_pkg(@{ $self->ourpkg }, $self->name . "::") :
($self->ourpkg ? $self->stash($body, '::') :
CgOp::wrap(CgOp::rawnew('Dictionary<string,Variable>'))),
CgOp::letn("how", $self->make_how,
# catch usages before the closing brace
Expand Down Expand Up @@ -345,8 +349,8 @@ use CgOp;
}
push @r, CgOp::scopedlex($self->var,
CgOp::methodcall(CgOp::letvar("how"), "create-protoobject"));
push @r, CgOp::bind(1, $body->lookup_pkg(@{ $self->ourpkg },
$self->name), CgOp::scopedlex($self->var)) if $self->ourpkg;
push @r, CgOp::bind(1, $self->stash($body, ''),
CgOp::scopedlex($self->var)) if $self->ourpkg;
@r;
}

Expand Down

0 comments on commit 4ecd8ab

Please sign in to comment.