Skip to content
Permalink
Browse files

Turn a lot of stuff into constants

So we don't have to do this at each startup
  • Loading branch information...
lizmat committed Dec 26, 2018
1 parent 6392634 commit 5540212cfc8805f869ce566c94c406f5cb18224b
@@ -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')
);
@@ -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,
@@ -12,6 +12,7 @@ my class Date does Dateish {
'year', 0,
'years', 0,
);

method !VALID-UNIT($unit) {
nqp::existskey($valid-units,$unit)
?? $unit
@@ -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,
@@ -40,6 +40,7 @@ my class DateTime does Dateish {
'year', 1,
'years', 1,
);

method !VALID-UNIT($unit) {
nqp::existskey($valid-units,$unit)
?? $unit
@@ -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:
@@ -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() {
@@ -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)
}
@@ -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.
@@ -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')};
}
}

@@ -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);
@@ -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',
@@ -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,
@@ -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(
@@ -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 {

0 comments on commit 5540212

Please sign in to comment.
You can’t perform that action at this time.