Skip to content

Commit

Permalink
Simplify after begin is always after children
Browse files Browse the repository at this point in the history
  • Loading branch information
jnthn committed Jun 4, 2023
1 parent 8ed4a96 commit 4392264
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 37 deletions.
16 changes: 5 additions & 11 deletions src/Raku/ast/base.rakumod
Expand Up @@ -108,32 +108,26 @@ class RakuAST::Node {
self.apply-implicit-block-semantics();
}

# Apply any pre-children BEGIN-time effects that were not yet
# performed (and figure out if we have to do the later).
my int $needs-begin-after := nqp::istype(self, RakuAST::BeginTime) && self.is-begin-performed-after-children();
if nqp::istype(self, RakuAST::BeginTime) && self.is-begin-performed-before-children() {
self.ensure-begin-performed($resolver, $context, :phase(1));
}

# Visit children. But don't run CHECK yet if this will be followed by more BEGIN handling
my int $is-begin-time := nqp::istype(self, RakuAST::BeginTime);
my int $is-package := nqp::istype(self, RakuAST::Package);
$resolver.push-scope(self) if $is-scope;
$resolver.push-package(self) if $is-package;
self.visit-children(-> $child { $child.IMPL-CHECK($resolver, $context, $resolve-only || $needs-begin-after) });
self.visit-children(-> $child { $child.IMPL-CHECK($resolver, $context, $resolve-only || $is-begin-time) });
$resolver.pop-scope() if $is-scope;
$resolver.pop-package() if $is-package;

# Perform any parse time BEGIN-time effects.
if $is-parse-time {
self.ensure-parse-performed($resolver, $context);
}
if $needs-begin-after {
self.ensure-begin-performed($resolver, $context, :phase(2));
if $is-begin-time {
self.ensure-begin-performed($resolver, $context);
}

# Unless in resolve-only mode, do other check-time activities.
unless $resolve-only {
if $needs-begin-after {
if $is-begin-time {
# Run children's CHECK processing. Couldn't do it earlier as
# that would have interfered with our BEGIN handling.
$resolver.push-scope(self) if $is-scope;
Expand Down
11 changes: 1 addition & 10 deletions src/Raku/ast/begintime.rakumod
Expand Up @@ -11,24 +11,15 @@ class RakuAST::BeginTime
nqp::die('Missing PERFORM-BEGIN implementation in ' ~ self.HOW.name(self))
}

# Should the BEGIN-time effects be performed before or after the parse of
# this node or both?
method is-begin-performed-before-children() { False }
method is-begin-performed-after-children() { !self.is-begin-performed-before-children }

# Ensure the begin-time effects are performed.
method ensure-begin-performed(RakuAST::Resolver $resolver, RakuAST::IMPL::QASTContext $context, int :$phase) {
unless $!begin-performed {
self.PERFORM-BEGIN($resolver, $context);
nqp::bindattr_i(self, RakuAST::BeginTime, '$!begin-performed', 3);
nqp::bindattr_i(self, RakuAST::BeginTime, '$!begin-performed', 1);
}
Nil
}

method begin-performed() {
$!begin-performed == 3
}

# Called when a BEGIN-time construct needs to evaluate code. Tries to
# interpret simple things to avoid the cost of compilation.
method IMPL-BEGIN-TIME-EVALUATE(RakuAST::Node $code, RakuAST::Resolver $resolver, RakuAST::IMPL::QASTContext $context) {
Expand Down
9 changes: 0 additions & 9 deletions src/Raku/ast/code.rakumod
Expand Up @@ -344,8 +344,6 @@ class RakuAST::ExpressionThunk
self.HOW.name(self)
}

method is-begin-performed-before-children() { False }

method PERFORM-BEGIN(RakuAST::Resolver $resolver, RakuAST::IMPL::QASTContext $context) {
self.IMPL-STUB-CODE($resolver, $context);

Expand Down Expand Up @@ -962,8 +960,6 @@ class RakuAST::Block
self.IMPL-WRAP-LIST(@implicit)
}

method is-begin-performed-before-children() { False }

method PERFORM-BEGIN(RakuAST::Resolver $resolver, RakuAST::IMPL::QASTContext $context) {
# Make sure that our placeholder signature has resolutions performed,
# and that we don't produce a topic parameter.
Expand Down Expand Up @@ -2038,8 +2034,6 @@ class RakuAST::RegexThunk
)
}

method is-begin-performed-before-children() { False }

method PERFORM-BEGIN(RakuAST::Resolver $resolver, RakuAST::IMPL::QASTContext $context) {
self.IMPL-STUB-CODE($resolver, $context);

Expand Down Expand Up @@ -2135,11 +2129,8 @@ class RakuAST::QuotedMatchConstruct
}
}

method is-begin-performed-before-children() { False }

method PERFORM-BEGIN(RakuAST::Resolver $resolver, RakuAST::IMPL::QASTContext $context) {
self.IMPL-STUB-CODE($resolver, $context);

Nil
}
}
Expand Down
3 changes: 0 additions & 3 deletions src/Raku/ast/statement-mods.rakumod
Expand Up @@ -261,9 +261,6 @@ class RakuAST::StatementModifier::Condition::Thunk
Nil
}

method is-begin-performed-before-children() { False }
method is-begin-performed-after-children() { False }

method PERFORM-BEGIN(RakuAST::Resolver $resolver, RakuAST::IMPL::QASTContext $context) {
Nil
}
Expand Down
4 changes: 0 additions & 4 deletions src/Raku/ast/statementprefixes.rakumod
Expand Up @@ -221,12 +221,8 @@ class RakuAST::StatementPrefix::Thunky
is RakuAST::Code
is RakuAST::BeginTime
{

method is-begin-performed-before-children() { False }

method PERFORM-BEGIN(RakuAST::Resolver $resolver, RakuAST::IMPL::QASTContext $context) {
self.IMPL-STUB-CODE($resolver, $context);

Nil
}

Expand Down

0 comments on commit 4392264

Please sign in to comment.