Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Make Rakudo::Internals a class with methods
This should be about 18x as fast then calling our subs
  • Loading branch information
lizmat committed Oct 6, 2015
1 parent 8709352 commit 0689733
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/core/Exception.pm
Expand Up @@ -272,7 +272,7 @@ do {
nqp::printfh($err, $e.Str);
nqp::printfh($err, "\n");
}
Rakudo::Internals::THE_END();
Rakudo::Internals.THE_END();
CONTROL { when CX::Warn { .resume } }
}
if $! {
Expand Down
10 changes: 5 additions & 5 deletions src/core/Rakudo/Internals.pm
@@ -1,6 +1,6 @@
my role Iterator { ... }

my module Rakudo::Internals {
my class Rakudo::Internals {

our role MapIterator does Iterator {
has $!hash-storage;
Expand All @@ -19,7 +19,7 @@ my module Rakudo::Internals {
}
}

our sub SET_LEADING_DOCS($obj, $docs) {
method SET_LEADING_DOCS($obj, $docs) {
my $current_why := $obj.WHY;

if $current_why {
Expand All @@ -40,7 +40,7 @@ my module Rakudo::Internals {
}
}

our sub SET_TRAILING_DOCS($obj, $docs) {
method SET_TRAILING_DOCS($obj, $docs) {
my $current_why := $obj.WHY;

if $current_why {
Expand All @@ -51,7 +51,7 @@ my module Rakudo::Internals {
}
}

our sub EXPORT_SYMBOL(\exp_name, @tags, Mu \sym) {
method EXPORT_SYMBOL(\exp_name, @tags, Mu \sym) {
my @export_packages = $*EXPORT;
for flat nqp::hllize(@*PACKAGES) {
unless .WHO.EXISTS-KEY('EXPORT') {
Expand Down Expand Up @@ -82,7 +82,7 @@ my module Rakudo::Internals {
0;
}

our sub THE_END {
method THE_END {
my @END := nqp::p6bindattrinvres(nqp::create(List), List, '$!reified',
nqp::getcurhllsym("@END_PHASERS"));
for @END -> $end { $end() };
Expand Down
2 changes: 1 addition & 1 deletion src/core/Variable.pm
Expand Up @@ -93,7 +93,7 @@ multi sub trait_mod:<is>(Variable:D $v, :$export!) {
my @tags = flat 'ALL', (nqp::istype($export,Pair) ?? $export.key() !!
nqp::istype($export,Positional) ?? @($export)>>.key !!
'DEFAULT');
Rakudo::Internals::EXPORT_SYMBOL($var.VAR.name, @tags, $var);
Rakudo::Internals.EXPORT_SYMBOL($var.VAR.name, @tags, $var);
}

# does trait
Expand Down
2 changes: 1 addition & 1 deletion src/core/control.pm
Expand Up @@ -241,7 +241,7 @@ sub exit($status = 0) {
$exit = $status;

once {
Rakudo::Internals::THE_END();
Rakudo::Internals.THE_END();
nqp::exit(nqp::unbox_i($exit.Int));
}
$exit;
Expand Down
4 changes: 1 addition & 3 deletions src/core/core_prologue.pm
Expand Up @@ -5,6 +5,7 @@ my class HyperWhatever { ... }
my class WhateverCode { ... }
my class Cursor { ... }
my class Failure { ... }
my class Rakudo::Internals { ... }

# Stub these or we can't use any sigil other than $.
my role Positional { ... }
Expand All @@ -13,9 +14,6 @@ my role Callable { ... }
my role Iterable { ... }
my role PositionalBindFailover { ... }

# for the internals
my module Rakudo::Internals { ... }

# Set up Empty, which is a Slip created with an empty IterationBuffer (which
# we also stub here). This is needed in a bunch of simple constructs (like if
# with only one branch).
Expand Down
28 changes: 14 additions & 14 deletions src/core/traits.pm
Expand Up @@ -93,11 +93,11 @@ multi sub trait_mod:<is>(Attribute:D $attr, :$DEPRECATED!) {
# to the (possibly auto-generated) accessor method.
}
multi sub trait_mod:<is>(Attribute:D $attr, :$leading_docs!) {
Rakudo::Internals::SET_LEADING_DOCS($attr, $leading_docs);
Rakudo::Internals.SET_LEADING_DOCS($attr, $leading_docs);
}

multi sub trait_mod:<is>(Attribute:D $attr, :$trailing_docs!) {
Rakudo::Internals::SET_TRAILING_DOCS($attr, $trailing_docs);
Rakudo::Internals.SET_TRAILING_DOCS($attr, $trailing_docs);
}

multi sub trait_mod:<is>(Routine:D $r, |c ) {
Expand Down Expand Up @@ -208,10 +208,10 @@ multi sub trait_mod:<is>(Parameter:D $param, :$onearg!) {
$param.set_onearg();
}
multi sub trait_mod:<is>(Parameter:D $param, :$leading_docs!) {
Rakudo::Internals::SET_LEADING_DOCS($param, $leading_docs);
Rakudo::Internals.SET_LEADING_DOCS($param, $leading_docs);
}
multi sub trait_mod:<is>(Parameter:D $param, :$trailing_docs!) {
Rakudo::Internals::SET_TRAILING_DOCS($param, $trailing_docs);
Rakudo::Internals.SET_TRAILING_DOCS($param, $trailing_docs);
}

# Declare these, as setting mainline doesn't get them automatically (as the
Expand All @@ -226,18 +226,18 @@ multi sub trait_mod:<is>(Routine:D \r, :$export!) {
my @tags = flat 'ALL', (nqp::istype($export,Pair) ?? $export.key() !!
nqp::istype($export,Positional) ?? @($export)>>.key !!
'DEFAULT');
Rakudo::Internals::EXPORT_SYMBOL($exp_name, @tags, $to_export);
Rakudo::Internals.EXPORT_SYMBOL($exp_name, @tags, $to_export);
}
multi sub trait_mod:<is>(Mu:U \type, :$export!) {
my $exp_name := type.^name;
my @tags = flat 'ALL', (nqp::istype($export,Pair) ?? $export.key !!
nqp::istype($export,Positional) ?? @($export)>>.key !!
'DEFAULT');
Rakudo::Internals::EXPORT_SYMBOL($exp_name, @tags, type);
Rakudo::Internals.EXPORT_SYMBOL($exp_name, @tags, type);
if nqp::istype(type.HOW, Metamodel::EnumHOW) {
type.^set_export_callback( {
for type.^enum_values.keys -> $value_name {
Rakudo::Internals::EXPORT_SYMBOL(
Rakudo::Internals.EXPORT_SYMBOL(
$value_name, @tags, type.WHO{$value_name});
}
});
Expand All @@ -248,31 +248,31 @@ multi sub trait_mod:<is>(Mu \sym, :$export!, :$SYMBOL!) {
my @tags = flat 'ALL', (nqp::istype($export,Pair) ?? $export.key !!
nqp::istype($export,Positional) ?? @($export)>>.key !!
'DEFAULT');
Rakudo::Internals::EXPORT_SYMBOL($SYMBOL, @tags, sym);
Rakudo::Internals.EXPORT_SYMBOL($SYMBOL, @tags, sym);
}

multi sub trait_mod:<is>(Block:D $r, :$leading_docs!) {
Rakudo::Internals::SET_LEADING_DOCS($r, $leading_docs);
Rakudo::Internals.SET_LEADING_DOCS($r, $leading_docs);
}
multi sub trait_mod:<is>(Block:D $r, :$trailing_docs!) {
Rakudo::Internals::SET_TRAILING_DOCS($r, $trailing_docs);
Rakudo::Internals.SET_TRAILING_DOCS($r, $trailing_docs);
}

# this should be identical to Mu:D, :leading_docs, otherwise the fallback Block:D, |c
# will catch it and declare "leading_docs" to be an unknown trait. This is why
# we need this redundant form in spite of having a Block:D candidate above
multi sub trait_mod:<is>(Routine:D $r, :$leading_docs!) {
Rakudo::Internals::SET_LEADING_DOCS($r, $leading_docs);
Rakudo::Internals.SET_LEADING_DOCS($r, $leading_docs);
}
multi sub trait_mod:<is>(Routine:D $r, :$trailing_docs!) {
Rakudo::Internals::SET_TRAILING_DOCS($r, $trailing_docs);
Rakudo::Internals.SET_TRAILING_DOCS($r, $trailing_docs);
}

multi sub trait_mod:<is>(Mu:U $docee, :$leading_docs!) {
Rakudo::Internals::SET_LEADING_DOCS($docee, $leading_docs);
Rakudo::Internals.SET_LEADING_DOCS($docee, $leading_docs);
}
multi sub trait_mod:<is>(Mu:U $docee, :$trailing_docs!) {
Rakudo::Internals::SET_TRAILING_DOCS($docee.HOW, $trailing_docs);
Rakudo::Internals.SET_TRAILING_DOCS($docee.HOW, $trailing_docs);
}

proto sub trait_mod:<does>(|) { * }
Expand Down

0 comments on commit 0689733

Please sign in to comment.