Skip to content

Commit

Permalink
Normalise RakuAST all other class specifications (10/10)
Browse files Browse the repository at this point in the history
  • Loading branch information
lizmat committed Feb 5, 2023
1 parent 33c2b28 commit 1d97dce
Show file tree
Hide file tree
Showing 23 changed files with 473 additions and 162 deletions.
8 changes: 6 additions & 2 deletions src/Raku/ast/attaching.rakumod
Expand Up @@ -5,14 +5,18 @@
# nearest scope that can carry a signature. When reached during resolution or
# check time, the `attach` method is invoked with the resolver, which can be
# used to discover target attachment nodes and interact with them.
class RakuAST::Attaching is RakuAST::Node {
class RakuAST::Attaching
is RakuAST::Node
{
method attach(RakuAST::Resolver $resolver) {
nqp::die('attach not implemented for ' ~ self.HOW.name(self));
}
}

# Done by any AST node that is the target for an attaching node.
class RakuAST::AttachTarget is RakuAST::Node {
class RakuAST::AttachTarget
is RakuAST::Node
{
# Returns a List (possibly empty) of attach target names for this node.
method attach-target-names() {
nqp::die('attach-target-names not implemented for ' ~ self.HOW.name(self));
Expand Down
4 changes: 3 additions & 1 deletion src/Raku/ast/base.rakumod
Expand Up @@ -391,7 +391,9 @@ class RakuAST::Node {
}

# Anything with a known compile time value does RakuAST::CompileTimeValue.
class RakuAST::CompileTimeValue is RakuAST::Node {
class RakuAST::CompileTimeValue
is RakuAST::Node
{
method compile-time-value() {
nqp::die('compile-time-value not implemented for ' ~ self.HOW.name(self))
}
Expand Down
4 changes: 3 additions & 1 deletion src/Raku/ast/begintime.rakumod
@@ -1,7 +1,9 @@
# Done by all things that want to perform some kind of effect at BEGIN time.
# They may do that effect before their children are visited in resolution or
# after; the default is after.
class RakuAST::BeginTime is RakuAST::Node {
class RakuAST::BeginTime
is RakuAST::Node
{
has int $!begin-performed;

# Method implemented by a node to perform its begin-time side-effects.
Expand Down
4 changes: 3 additions & 1 deletion src/Raku/ast/checktime.rakumod
@@ -1,5 +1,7 @@
# Done by every AST node that can report CHECK-time problems.
class RakuAST::CheckTime is RakuAST::Node {
class RakuAST::CheckTime
is RakuAST::Node
{
# A list of sorries, lazily allocated if there are any.
has Mu $!sorries;

Expand Down
21 changes: 15 additions & 6 deletions src/Raku/ast/circumfix.rakumod
@@ -1,9 +1,12 @@
# Marker for all kinds of circumfix.
class RakuAST::Circumfix is RakuAST::Term is RakuAST::Contextualizable {
}
class RakuAST::Circumfix
is RakuAST::Term
is RakuAST::Contextualizable { }

# Grouping parentheses circumfix.
class RakuAST::Circumfix::Parentheses is RakuAST::Circumfix {
class RakuAST::Circumfix::Parentheses
is RakuAST::Circumfix
{
has RakuAST::SemiList $.semilist;

method new(RakuAST::SemiList $semilist) {
Expand All @@ -30,8 +33,11 @@ class RakuAST::Circumfix::Parentheses is RakuAST::Circumfix {
}

# Array composer circumfix.
class RakuAST::Circumfix::ArrayComposer is RakuAST::Circumfix is RakuAST::Lookup
is RakuAST::ColonPairish {
class RakuAST::Circumfix::ArrayComposer
is RakuAST::Circumfix
is RakuAST::Lookup
is RakuAST::ColonPairish
{
has RakuAST::SemiList $.semilist;

method new(RakuAST::SemiList $semilist) {
Expand Down Expand Up @@ -82,7 +88,10 @@ class RakuAST::Circumfix::ArrayComposer is RakuAST::Circumfix is RakuAST::Lookup
# thing as a block. At the AST level there are two distinct node types:
# this, and Block (for the case it's a block). The Block node has a method
# on it for performing this disambiguation.
class RakuAST::Circumfix::HashComposer is RakuAST::Circumfix is RakuAST::Lookup {
class RakuAST::Circumfix::HashComposer
is RakuAST::Circumfix
is RakuAST::Lookup
{
has RakuAST::Expression $.expression;

method new(RakuAST::Expression $expression?) {
Expand Down
26 changes: 25 additions & 1 deletion src/Raku/ast/compunit.rakumod
Expand Up @@ -505,9 +505,33 @@ class RakuAST::LiteralBuilder {
# Produce the Rat object.
unless $!has-cached-rat {
nqp::bindattr(self, RakuAST::LiteralBuilder, '$!cached-rat',
$!resolver.resolve-lexical-constant-in-setting('Rat').compile-time-value);
$!resolver.resolve-lexical-constant-in-setting('Rat').compile-time-value);
nqp::bindattr_i(self, RakuAST::LiteralBuilder, '$!has-cached-rat', 1);
}
$!cached-rat.new($parti, $partf)
}

# Build a Complex constant and intern it.
method intern-complex($real-part, $imaginary-part) {
# TODO interning
self.build-complex($real-part, $imaginary-part)
}

# Build a Complex constant, but do not intern it.
method build-complex(str $real-part, str $imaginary-part) {
my num $real := $real-part
?? nqp::box_n(nqp::numify($real-part), Num)
!! 0e0;
my num $imaginary := $imaginary-part
?? nqp::box_n(nqp::numify($imaginary-part), Num)
!! 0e0;

# Produce the Complex object.
unless $!has-cached-complex {
nqp::bindattr(self, RakuAST::LiteralBuilder, '$!cached-complex',
$!resolver.resolve-lexical-constant-in-setting('Complex').compile-time-value);
nqp::bindattr_i(self, RakuAST::LiteralBuilder, '$!has-cached-complex', 1);
}
$!cached-complex.new($real, $imaginary)
}
}
16 changes: 12 additions & 4 deletions src/Raku/ast/contextualizer.rakumod
@@ -1,5 +1,7 @@
# The base of all contextualizers.
class RakuAST::Contextualizer is RakuAST::Term {
class RakuAST::Contextualizer
is RakuAST::Term
{
# The thing to be contextualized.
has RakuAST::Contextualizable $.target;

Expand All @@ -23,19 +25,25 @@ class RakuAST::Contextualizer is RakuAST::Term {
}

# The item contextualizer.
class RakuAST::Contextualizer::Item is RakuAST::Contextualizer {
class RakuAST::Contextualizer::Item
is RakuAST::Contextualizer
{
method IMPL-METHOD() { 'item' }
method sigil { '$' }
}

# The list contextualizer.
class RakuAST::Contextualizer::List is RakuAST::Contextualizer {
class RakuAST::Contextualizer::List
is RakuAST::Contextualizer
{
method IMPL-METHOD() { 'cache' }
method sigil { '@' }
}

# The hash contextualizer.
class RakuAST::Contextualizer::Hash is RakuAST::Contextualizer {
class RakuAST::Contextualizer::Hash
is RakuAST::Contextualizer
{
method IMPL-METHOD() { 'hash' }
method sigil { '%' }
}

0 comments on commit 1d97dce

Please sign in to comment.