Skip to content

Commit cd12868

Browse files
committed
Refactor to ensure proper handling of --module-path.
1 parent e9a452a commit cd12868

File tree

2 files changed

+26
-12
lines changed

2 files changed

+26
-12
lines changed

src/HLL/SerializationContextBuilder.pm

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,8 @@ class HLL::Compiler::SerializationContextBuilder {
155155
# Load it immediately, so the compile time info is available.
156156
# Once it's loaded, set it as the outer context of the code
157157
# being compiled.
158-
my $path := %*COMPILING<%?OPTIONS><setting-path>;
159-
my $setting := %*COMPILING<%?OPTIONS><outer_ctx> := $loader.load_setting(
160-
$path ?? "$path/$setting_name" !! $setting_name);
158+
my $setting := %*COMPILING<%?OPTIONS><outer_ctx>
159+
:= $loader.load_setting($setting_name);
161160

162161
# Do load for pre-compiled situation.
163162
self.add_event(:deserialize_past(PAST::Stmts.new(
@@ -183,8 +182,7 @@ class HLL::Compiler::SerializationContextBuilder {
183182
# during the deserialization.
184183
method load_module($module_name, $cur_GLOBALish) {
185184
# Immediate loading.
186-
my $module := $loader.load_module($module_name, $cur_GLOBALish,
187-
:prefix(%*COMPILING<%?OPTIONS><module-path>));
185+
my $module := $loader.load_module($module_name, $cur_GLOBALish);
188186

189187
# Make sure we do the loading during deserialization.
190188
self.add_event(:deserialize_past(PAST::Stmts.new(

src/ModuleLoader.pm

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,17 @@ knowhow ModuleLoader {
1111
$*CTXSAVE := 0;
1212
}
1313

14-
method load_module($module_name, $cur_GLOBALish, :$prefix) {
14+
method load_module($module_name, $cur_GLOBALish) {
1515
# If we didn't already do so, load the module and capture
1616
# its mainline. Otherwise, we already loaded it so go on
1717
# with what we already have.
1818
my $module_ctx;
1919
my $path := pir::join('/', pir::split('::', $module_name)) ~ '.pbc';
20-
if $prefix {
21-
$path := "$prefix/$path";
20+
try {
21+
my $prefix := %*COMPILING<%?OPTIONS><module-path>;
22+
if $prefix {
23+
$path := "$prefix/$path";
24+
}
2225
}
2326
if pir::defined(%modules_loaded{$path}) {
2427
$module_ctx := %modules_loaded{$path};
@@ -72,21 +75,34 @@ knowhow ModuleLoader {
7275
}
7376

7477
method load_setting($setting_name) {
78+
my $setting;
79+
7580
if $setting_name ne 'NULL' {
81+
# Add path prefix and .setting suffix.
82+
my $path := "$setting_name.setting.pbc";
83+
try {
84+
my $prefix := %*COMPILING<%?OPTIONS><setting-path>;
85+
if $prefix {
86+
$path := "$prefix/$path";
87+
}
88+
}
89+
7690
# Unless we already did so, load the setting.
77-
unless pir::defined(%settings_loaded{$setting_name}) {
91+
unless pir::defined(%settings_loaded{$path}) {
7892
my $*CTXSAVE := self;
7993
my $*MAIN_CTX;
8094
my $preserve_global := pir::get_hll_global__Ps('GLOBAL');
81-
pir::load_bytecode("$setting_name.setting.pbc");
95+
pir::load_bytecode($path);
8296
pir::set_hll_global__vsP('GLOBAL', $preserve_global);
8397
unless pir::defined($*MAIN_CTX) {
8498
pir::die("Unable to load setting $setting_name; maybe it is missing a YOU_ARE_HERE?");
8599
}
86-
%settings_loaded{$setting_name} := $*MAIN_CTX;
100+
%settings_loaded{$path} := $*MAIN_CTX;
87101
}
102+
103+
$setting := %settings_loaded{$path};
88104
}
89105

90-
return %settings_loaded{$setting_name};
106+
return $setting;
91107
}
92108
}

0 commit comments

Comments
 (0)