Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
reorganize lookup of dynamic variables
The code before assumed that a dynamic variable always has an true-ish
value after it has been initialized. This was not true for $*TZ and
perhaps others. Now we have a candidate for INITIALIZE_DYNAMIC that
returns an exception, and we can check on that and fail.
Also I reordered the source files, so that we build Env.pm before
ThreadPoolScheduler.pm, since the ThreadPoolScheduler accesses
%*ENV<RAKUDO_MAX_THREADS>. This used to cause a hang when building
RESTRICTED.setting on my box.
  • Loading branch information
FROGGS committed Sep 10, 2014
1 parent 51ddd5d commit f79201d
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 24 deletions.
6 changes: 3 additions & 3 deletions src/core/Distro.pm
Expand Up @@ -30,7 +30,7 @@ class Distro does Systemic {
}

# set up $*DISTRO and deprecated $*OS and $*OSVER
multi sub INITIALIZE('$*DISTRO') {
multi sub INITIALIZE_DYNAMIC('$*DISTRO') {
PROCESS::<$DISTRO> := do {
#?if jvm
my $properties := $*VM.properties;
Expand Down Expand Up @@ -69,15 +69,15 @@ multi sub INITIALIZE('$*DISTRO') {
};
}

multi sub INITIALIZE('$*OS') {
multi sub INITIALIZE_DYNAMIC('$*OS') {
PROCESS::<$OS> := Deprecation.obsolete(
:name('$*OS'),
:value($*DISTRO.name),
:instead('$*DISTRO.name'),
);
}

multi sub INITIALIZE('$*OSVER') {
multi sub INITIALIZE_DYNAMIC('$*OSVER') {
PROCESS::<$OSVER> := Deprecation.obsolete(
:name('$*OSVER'),
:value($*DISTRO.version),
Expand Down
2 changes: 1 addition & 1 deletion src/core/Env.pm
Expand Up @@ -12,7 +12,7 @@
PROCESS::<%ENV> := %ENV;
}

multi sub INITIALIZE('$*CWD') {
multi sub INITIALIZE_DYNAMIC('$*CWD') {
## duplicate src/core/IO.pm::cwd
my $CWD = IO::Path.new(nqp::p6box_s(
#?if parrot
Expand Down
2 changes: 1 addition & 1 deletion src/core/Instant.pm
Expand Up @@ -122,7 +122,7 @@ sub term:<now>() {

#{
my num $init-time-num = nqp::time_n; # need find a way to not leak this
multi sub INITIALIZE('$*INITTIME') {
multi sub INITIALIZE_DYNAMIC('$*INITTIME') {
PROCESS::<$INITTIME> := Instant.from-posix: $init-time-num;
}
#}
Expand Down
2 changes: 1 addition & 1 deletion src/core/Kernel.pm
Expand Up @@ -105,7 +105,7 @@ class Kernel does Systemic {
#?endif
}

multi sub INITIALIZE('$*KERNEL') {
multi sub INITIALIZE_DYNAMIC('$*KERNEL') {
PROCESS::<$KERNEL> := Kernel.new;
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/Perl.pm
Expand Up @@ -27,7 +27,7 @@ class Perl does Systemic {
method KERNELnames { <darwin linux win32> }
}

multi sub INITIALIZE('$*PERL') {
multi sub INITIALIZE_DYNAMIC('$*PERL') {
PROCESS::<$PERL> := Perl.new;
}
multi postcircumfix:<{ }> (Perl $d, "name" ) {
Expand Down
12 changes: 6 additions & 6 deletions src/core/Process.pm
@@ -1,8 +1,8 @@
multi sub INITIALIZE('$*PID') {
multi sub INITIALIZE_DYNAMIC('$*PID') {
PROCESS::<$PID> := nqp::p6box_i(nqp::getpid());
}

multi sub INITIALIZE('$*EXECUTABLE') {
multi sub INITIALIZE_DYNAMIC('$*EXECUTABLE') {
my $EXECUTABLE =
#?if parrot
nqp::p6box_s(pir::interpinfo__Si(pir::const::INTERPINFO_EXECUTABLE_FULLNAME));
Expand All @@ -20,22 +20,22 @@ multi sub INITIALIZE('$*EXECUTABLE') {
PROCESS::<$EXECUTABLE> := $EXECUTABLE;
}

multi sub INITIALIZE('$*EXECUTABLE_NAME') {
multi sub INITIALIZE_DYNAMIC('$*EXECUTABLE_NAME') {
PROCESS::<$EXECUTABLE_NAME> := $*EXECUTABLE.basename;
}

multi sub INITIALIZE('$*PROGRAM_NAME') {
multi sub INITIALIZE_DYNAMIC('$*PROGRAM_NAME') {
my Mu $comp := nqp::getcomp('perl6');
my $PROGRAM_NAME = $comp.user-progname();
PROCESS::<$PROGRAM> := IO::Path.new($PROGRAM_NAME);
PROCESS::<$PROGRAM_NAME> := $PROGRAM_NAME;
}

multi sub INITIALIZE('$*PROGRAM') {
multi sub INITIALIZE_DYNAMIC('$*PROGRAM') {
PROCESS::<$PROGRAM> := IO::Path.new($*PROGRAM_NAME);
}

multi sub INITIALIZE('$*TMPDIR') {
multi sub INITIALIZE_DYNAMIC('$*TMPDIR') {
PROCESS::<$TMPDIR> := IO::Spec.tmpdir.path;
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/Temporal.pm
Expand Up @@ -648,7 +648,7 @@ multi infix:«>»(Date:D $a, Date:D $b) {
$a.daycount > $b.daycount
}

multi sub INITIALIZE('$*TZ') {
multi sub INITIALIZE_DYNAMIC('$*TZ') {
PROCESS::<$TZ> = get-local-timezone-offset();
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/VM.pm
Expand Up @@ -56,7 +56,7 @@ multi postcircumfix:<{ }> (VM $d, "properties" ) {
}
#?endif

multi sub INITIALIZE('$*VM') {
multi sub INITIALIZE_DYNAMIC('$*VM') {
PROCESS::<$VM> := do {
my $config :=
#?if parrot
Expand Down
15 changes: 8 additions & 7 deletions src/core/stubs.pm
Expand Up @@ -24,7 +24,7 @@ my role Mixy { ... }
my class Mix { ... }
my class MixHash { ... }

sub DYNAMIC(\name) is rw {
sub DYNAMIC(\name) is rw {
my Mu $x := nqp::getlexdyn(nqp::unbox_s(name));
if nqp::isnull($x) {
my str $pkgname = nqp::replace(nqp::unbox_s(name), 1, 1, '');
Expand All @@ -34,19 +34,20 @@ sub DYNAMIC(\name) is rw {
elsif nqp::existskey(PROCESS.WHO, $pkgname) {
$x := nqp::atkey(PROCESS.WHO, $pkgname);
}
elsif try INITIALIZE(name) -> \result {
$x := result;
}
else {
fail X::Dynamic::NotFound.new(:name(name));
$x := INITIALIZE_DYNAMIC(name);
fail $x if nqp::istype($x, Exception);
}
}
$x
}

# prime the automagic dynamic variable initializers
proto sub INITIALIZE(|) { * }
#multi sub INITIALIZE('$*FOO') { # example stub
proto sub INITIALIZE_DYNAMIC(|) { * }
multi sub INITIALIZE_DYNAMIC(\name) {
X::Dynamic::NotFound.new(:name(name));
}
#multi sub INITIALIZE_DYNAMIC('$*FOO') { # example stub
# PROCESS::<$FOO> := "foo";
#}

Expand Down
2 changes: 1 addition & 1 deletion tools/build/Makefile-JVM.in
Expand Up @@ -162,6 +162,7 @@ J_CORE_SOURCES = \
src/core/Semaphore.pm \
src/core/Cancellation.pm \
src/core/Scheduler.pm \
src/core/Env.pm \
src/core/ThreadPoolScheduler.pm \
src/core/CurrentThreadScheduler.pm \
src/core/Promise.pm \
Expand All @@ -175,7 +176,6 @@ J_CORE_SOURCES = \
src/core/IO/Socket.pm \
src/core/IO/Socket/Async.pm \
src/core/IO/Socket/INET.pm \
src/core/Env.pm \
src/core/Systemic.pm \
src/core/VM.pm \
src/core/Distro.pm \
Expand Down
2 changes: 1 addition & 1 deletion tools/build/moar_core_sources
Expand Up @@ -110,6 +110,7 @@ src/core/Lock.pm
src/core/Semaphore.pm
src/core/Cancellation.pm
src/core/Scheduler.pm
src/core/Env.pm
src/core/ThreadPoolScheduler.pm
src/core/CurrentThreadScheduler.pm
src/core/Promise.pm
Expand All @@ -122,7 +123,6 @@ src/core/IO/Socket/INET.pm
src/core/IO/Socket/Async.pm
src/core/IO/Notification.pm
src/core/Proc/Async.pm
src/core/Env.pm
src/core/signals.pm
src/core/Systemic.pm
src/core/VM.pm
Expand Down

0 comments on commit f79201d

Please sign in to comment.