Navigation Menu

Skip to content

Commit

Permalink
Implement parsing for package, module, grammar, role
Browse files Browse the repository at this point in the history
  • Loading branch information
sorear committed Jul 18, 2010
1 parent a33aa22 commit d38b860
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 19 deletions.
9 changes: 5 additions & 4 deletions Decl.pm
Expand Up @@ -190,6 +190,7 @@ use CgOp;

has name => (is => 'ro', isa => 'Str', predicate => 'has_name');
has var => (is => 'ro', isa => 'Str', required => 1);
has bodyvar => (is => 'ro', isa => 'Str');
has stub => (is => 'ro', isa => 'Bool', default => 0);
has parents => (is => 'ro', isa => 'ArrayRef', default => sub { [] });
has body => (is => 'ro', isa => 'Body');
Expand All @@ -199,7 +200,7 @@ use CgOp;
if ($self->stub) {
($self->var, $self->var . '!HOW');
} else {
($self->var, $self->var . '!HOW', $self->var . '!BODY');
($self->var, $self->var . '!HOW', $self->bodyvar);
}
}

Expand All @@ -225,7 +226,7 @@ use CgOp;
# a BEGIN.
CgOp::proto_var($self->var, CgOp::null('Variable')),

CgOp::proto_var($self->var . '!BODY',
CgOp::proto_var($self->bodyvar,
CgOp::newscalar(
CgOp::protosub($self->body))),
CgOp::scopedlex($self->var,
Expand All @@ -239,8 +240,8 @@ use CgOp;
CgOp::share_lex($self->var),
($self->stub ? () :
($body->mainline ?
CgOp::share_lex($self->var . '!BODY') :
CgOp::clone_lex($self->var . '!BODY'))));
CgOp::share_lex($self->bodyvar) :
CgOp::clone_lex($self->bodyvar))));
}

sub write {
Expand Down
36 changes: 21 additions & 15 deletions Niecza/Actions.pm
Expand Up @@ -819,26 +819,28 @@ sub statement_control__S_until { my ($cl, $M) = @_;
until => 1, once => 0);
}

# All package defs have a couple things in common - a special-ish block,
# with a special decl, and some nice runtimey code
sub package_def { my ($cl, $M) = @_;
if ($::PKGDECL ne 'class') {
$M->sorry('Non-class package definitions are not yet supported');
return;
}
my $scope = $::SCOPE;
if (!$M->{longname}[0]) {
$scope = 'anon';
}
if ($::SCOPE ne 'anon' && $::SCOPE ne 'my') {
$M->sorry('Non-lexical class definitions are not yet supported');
$M->sorry('Non-lexical package definitions are not yet supported');
return;
}
my $name = $M->{longname}[0] ?
$cl->mangle_longname($M->{longname}[0]) : 'ANON';
my $outer = $cl->get_outer($::CURLEX);
my $outervar = $::SCOPE eq 'my' ? $name : $cl->gensym;
if (!$M->{decl}{stub}) {

my $stmts = $M->{statementlist} // $M->{blockoid};
my $decltype = 'Decl::' . ucfirst $::PKGDECL;
my $blocktype = $::PKGDECL;
my $bodyvar = $cl->gensym;

if (($blocktype eq 'class' || $blocktype eq 'grammar')
&& !$M->{decl}{stub}) {
unshift @{ $::CURLEX->{'!decls'} //= [] },
map { $_->{_ast} } @{ $M->{trait} };

Expand All @@ -849,29 +851,33 @@ sub package_def { my ($cl, $M) = @_;
}

push @{ $::CURLEX->{'!decls'} //= [] },
Decl::Super->new(name => 'Any');
Decl::Super->new(name => ($blocktype eq 'grammar' ?
'Cursor' : 'Any'));
}
}

my $cbody = $cl->sl_to_block('class', $stmts->{_ast},
if (!$M->{decl}{stub}) {
my $stmts = $M->{statementlist} // $M->{blockoid};

my $cbody = $cl->sl_to_block($blocktype, $stmts->{_ast},
name => $name);
my $cdecl = Decl::Class->new(
my $cdecl = $decltype->new(
name => $name,
var => $outervar,
bodyvar => $bodyvar,
body => $cbody);
push @{ $outer->{'!decls'} //= [] }, $cdecl;
$M->{_ast} = Op::StatementList->new(
children => [
Op::CallSub->new(
invocant => Op::Lexical->new(name => $outervar . '!BODY')),
invocant => Op::Lexical->new(name => $bodyvar)),
Op::Lexical->new(name => $outervar)]);
} else {

push @{ $outer->{'!decls'} //= [] }, Decl::Class->new(
push @{ $outer->{'!decls'} //= [] }, $decltype->new(
name => $name,
var => $outervar,
stub => 1);

#XXX: What should this return?
# XXX return what?
}
}

Expand Down

0 comments on commit d38b860

Please sign in to comment.