Skip to content

Commit

Permalink
Turn a lot of stuff into constants
Browse files Browse the repository at this point in the history
So we don't have to do this at each startup
  • Loading branch information
lizmat committed Dec 26, 2018
1 parent 6392634 commit 5540212
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 61 deletions.
2 changes: 1 addition & 1 deletion src/core/Compiler.pm6
Expand Up @@ -3,7 +3,7 @@ class Compiler does Systemic {
has Str $.release;
has Str $!build-date;
has Str $.codename;
BEGIN my $id = nqp::sha1(
my constant $id = nqp::sha1(
$*W.handle.Str
~ nqp::atkey(nqp::getcurhllsym('$COMPILER_CONFIG'), 'source-digest')
);
Expand Down
3 changes: 2 additions & 1 deletion src/core/Date.pm6
Expand Up @@ -2,7 +2,7 @@ my class Date does Dateish {

method !formatter() { sprintf '%s-%02d-%02d',self!year-Str,$!month,$!day }

my $valid-units := nqp::hash(
my constant $valid-units = nqp::hash(
'day', 1,
'days', 1,
'week', 7,
Expand All @@ -12,6 +12,7 @@ my class Date does Dateish {
'year', 0,
'years', 0,
);

method !VALID-UNIT($unit) {
nqp::existskey($valid-units,$unit)
?? $unit
Expand Down
3 changes: 2 additions & 1 deletion src/core/DateTime.pm6
Expand Up @@ -24,7 +24,7 @@ my class DateTime does Dateish {
($!timezone.abs/60%60).floor)
}

my $valid-units := nqp::hash(
my constant $valid-units = nqp::hash(
'second', 0,
'seconds', 0,
'minute', 0,
Expand All @@ -40,6 +40,7 @@ my class DateTime does Dateish {
'year', 1,
'years', 1,
);

method !VALID-UNIT($unit) {
nqp::existskey($valid-units,$unit)
?? $unit
Expand Down
4 changes: 2 additions & 2 deletions src/core/Dateish.pm6
Expand Up @@ -11,7 +11,7 @@ my role Dateish {
sub IS-LEAP-YEAR($y) { $y %% 4 and not $y %% 100 or $y %% 400 }
method is-leap-year(Dateish:D:) { IS-LEAP-YEAR($!year) }

my $days-in-month := nqp::list_i(
my constant $days-in-month = nqp::list_i(
0, 31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
);
# This method is used by Date and DateTime:
Expand Down Expand Up @@ -97,7 +97,7 @@ my role Dateish {
($!day - 1) div 7 + 1
}

my $days-at-start-of-month := nqp::list_i(
my constant $days-at-start-of-month = nqp::list_i(
0, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334
);
method day-of-year() {
Expand Down
3 changes: 2 additions & 1 deletion src/core/Encoding/Builtin.pm6
Expand Up @@ -33,7 +33,8 @@ class Encoding::Builtin does Encoding {
!! $encoder
}

my $enc_type := nqp::hash('utf8',utf8,'utf16',utf16,'utf32',utf32);
my constant $enc_type = nqp::hash('utf8',utf8,'utf16',utf16,'utf32',utf32);

method !buf-type() {
nqp::ifnull(nqp::atkey($enc_type, $!name), blob8)
}
Expand Down
68 changes: 34 additions & 34 deletions src/core/Exception.pm6
Expand Up @@ -1569,43 +1569,43 @@ my class X::Syntax::ConditionalOperator::SecondPartInvalid does X::Syntax {
my class X::Syntax::Perl5Var does X::Syntax {
has $.name;
has $.identifier-name;
BEGIN my %m =
'$"' => '.join() method',
'$$' => '$*PID',
'$;' => 'real multidimensional hashes',
'$&' => '$<>',
'$`' => '$/.prematch',
'$\'' => '$/.postmatch',
'$,' => '.join() method',
'$.' => "the .kv method on e.g. .lines",
'$/' => "the filehandle's .nl-in attribute",
'$\\' => "the filehandle's .nl-out attribute",
'$|' => "the filehandle's .out-buffer attribute",
'$?' => '$! for handling child errors also',
'$@' => '$!',
'$]' => '$*PERL.version or $*PERL.compiler.version',

'$^C' => 'COMPILING namespace',
'$^H' => '$?FOO variables',
'$^N' => '$/[*-1]',
'$^O' => 'VM.osname',
'$^R' => 'an explicit result variable',
'$^S' => 'context function',
'$^T' => '$*INIT-INSTANT',
'$^V' => '$*PERL.version or $*PERL.compiler.version',
'$^X' => '$*EXECUTABLE-NAME',

'@-' => '.from method',
'@+' => '.to method',

'%-' => '.from method',
'%+' => '.to method',
'%^H' => '$?FOO variables',
;
my constant $m = nqp::hash(
'$"', '.join() method',
'$$', '$*PID',
'$;', 'real multidimensional hashes',
'$&', '$<>',
'$`', '$/.prematch',
'$\'', '$/.postmatch',
'$,', '.join() method',
'$.', "the .kv method on e.g. .lines",
'$/', "the filehandle's .nl-in attribute",
'$\\', "the filehandle's .nl-out attribute",
'$|', "the filehandle's .out-buffer attribute",
'$?', '$! for handling child errors also',
'$@', '$!',
'$]', '$*PERL.version or $*PERL.compiler.version',

'$^C', 'COMPILING namespace',
'$^H', '$?FOO variables',
'$^N', '$/[*-1]',
'$^O', 'VM.osname',
'$^R', 'an explicit result variable',
'$^S', 'context function',
'$^T', '$*INIT-INSTANT',
'$^V', '$*PERL.version or $*PERL.compiler.version',
'$^X', '$*EXECUTABLE-NAME',

'@-', '.from method',
'@+', '.to method',

'%-', '.from method',
'%+', '.to method',
'%^H', '$?FOO variables',
);
method message() {
my $name = $!name;
my $v = $name ~~ m/ <[ $ @ % & ]> [ \^ <[ A..Z ]> | \W ] /;
my $sugg = %m{~$v};
my $sugg = nqp::atkey($m,~$v);
if $name eq '$#' {
# Currently only `$#` var has this identifier business handling.
# Should generalize the logic if we get more of stuff like this.
Expand Down
34 changes: 19 additions & 15 deletions src/core/IO/Spec.pm6
Expand Up @@ -2,22 +2,26 @@ my class VM { ... }

my class IO::Spec {

BEGIN my %module = # only list the non-Unix ones in lowercase
'mswin32' => 'Win32',
'os2' => 'Win32',
'dos' => 'Win32',
'symbian' => 'Win32',
'netware' => 'Win32',
'win32' => 'Win32',
'cygwin' => 'Cygwin',
'qnx' => 'QNX',
'nto' => 'QNX',
# <MacOS Mac> »=>» 'Mac',
# 'VMS' => 'VMS'
;
my constant $module = nqp::hash( # only list the non-Unix ones in lowercase
'mswin32', 'Win32',
'os2', 'Win32',
'dos', 'Win32',
'symbian', 'Win32',
'netware', 'Win32',
'win32', 'Win32',
'cygwin', 'Cygwin',
'qnx', 'QNX',
'nto', 'QNX',
# <MacOS Mac> »=>» 'Mac',
# 'VMS' => 'VMS'
);

method select(IO::Spec:U: $token?) {
IO::Spec::{%module{ lc($token // VM.osname) } // 'Unix'};
proto method select(|) {*}
multi method select(IO::Spec:U:) {
IO::Spec::{nqp::ifnull(nqp::atkey($module,VM.osname),'Unix')};
}
multi method select(IO::Spec:U: $token) {
IO::Spec::{nqp::ifnull(nqp::atkey($module,$token.lc),'Unix')};
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/PseudoStash.pm6
Expand Up @@ -22,7 +22,7 @@ my class PseudoStash is Map {

method WHICH() { self.Mu::WHICH }

my $pseudoers := nqp::hash(
my constant $pseudoers = nqp::hash(
'MY', sub ($cur) {
my $stash := nqp::clone($cur);
nqp::bindattr_i($stash, PseudoStash, '$!mode', PRECISE_SCOPE);
Expand Down
8 changes: 4 additions & 4 deletions src/core/Rakudo/Internals.pm6
Expand Up @@ -830,10 +830,10 @@ my class Rakudo::Internals {
# http://tf.nist.gov/pubs/bulletin/leapsecond.htm
# http://hpiers.obspm.fr/eop-pc/earthor/utc/TAI-UTC_tab.html

my int $initial-offset = 10;
my int constant $initial-offset = 10;
# TAI - UTC at the Unix epoch (1970-01-01T00:00:00Z).

my $dates := nqp::list_s(
my constant $dates = nqp::list_s(
#BEGIN leap-second-dates
'1972-06-30',
'1972-12-31',
Expand Down Expand Up @@ -873,7 +873,7 @@ my class Rakudo::Internals {
# %leap-seconds{$d} seconds behind TAI.

# Ambiguous POSIX times.
my $posixes := nqp::list_i(
my constant $posixes = nqp::list_i(
#BEGIN leap-second-posix
78796800,
94694400,
Expand Down Expand Up @@ -904,7 +904,7 @@ my class Rakudo::Internals {
1483228800,
#END leap-second-posix
);
my int $elems = nqp::elems($dates);
my int constant $elems = nqp::elems($dates);

method is-leap-second-date(\date) {
nqp::hllbool(
Expand Down
2 changes: 1 addition & 1 deletion src/core/ShapedNArray.pm6
@@ -1,6 +1,6 @@
# this is actually part of the Array class

my \dim2role :=
my constant \dim2role =
nqp::list(ShapedArray,Shaped1Array,Shaped2Array,Shaped3Array);

sub set-shape(\base, \shape) is raw {
Expand Down

0 comments on commit 5540212

Please sign in to comment.