Skip to content

Commit 3404565

Browse files
committed
Start to rename SettingManager to ModuleLoader, and move the current (very minimalistic) module loading to there, in anticipation of expanding it with extra pieces soon.
1 parent acf33e3 commit 3404565

File tree

2 files changed

+29
-12
lines changed

2 files changed

+29
-12
lines changed

src/HLL/SerializationContextBuilder.pm

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ class HLL::Compiler::SerializationContextBuilder {
149149
# Once it's loaded, set it as the outer context of the code
150150
# being compiled.
151151
my $path := %*COMPILING<%?OPTIONS><setting-path>;
152-
%*COMPILING<%?OPTIONS><outer_ctx> := HLL::SettingManager.load_setting(
152+
%*COMPILING<%?OPTIONS><outer_ctx> := ModuleLoader.load_setting(
153153
$path ?? "$path/$setting_name" !! $setting_name);
154154

155155
# Do load for pre-compiled situation.
@@ -162,7 +162,7 @@ class HLL::Compiler::SerializationContextBuilder {
162162
PAST::Var.new( :name('block'), :scope('register') ),
163163
PAST::Op.new(
164164
:pasttype('callmethod'), :name('load_setting'),
165-
PAST::Var.new( :name('SettingManager'), :namespace('HLL'), :scope('package') ),
165+
PAST::Var.new( :name('ModuleLoader'), :namespace([]), :scope('package') ),
166166
$setting_name
167167
)
168168
)
@@ -174,17 +174,18 @@ class HLL::Compiler::SerializationContextBuilder {
174174
# during the deserialization.
175175
method load_module($module_name) {
176176
# Immediate loading.
177-
my $*MAIN_CTX;
178-
my $*CTXSAVE := HLL::Compiler;
179-
my $path := pir::join('/', pir::split('::', $module_name)) ~ '.pbc';
180-
pir::load_bytecode($path);
177+
ModuleLoader.load_module($module_name);
181178

182179
# Make sure we do the loading during deserialization.
183-
self.add_event(:deserialize_past(
184-
PAST::Op.new( :pirop('load_bytecode vs'), $path )));
185-
186-
# Return UNIT of the loaded module.
187-
$*MAIN_CTX
180+
self.add_event(:deserialize_past(PAST::Stmts.new(
181+
PAST::Op.new(
182+
:pirop('load_bytecode vs'), 'SettingManager.pbc'
183+
),
184+
PAST::Op.new(
185+
:pasttype('callmethod'), :name('load_module'),
186+
PAST::Var.new( :name('ModuleLoader'), :namespace([]), :scope('package') ),
187+
$module_name
188+
))));
188189
}
189190

190191
# Installs a symbol into the package. Does so immediately, and

src/HLL/SettingManager.pm

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
knowhow HLL::SettingManager {
1+
knowhow ModuleLoader {
22
my %settings_loaded;
33

44
method ctxsave() {
@@ -10,6 +10,15 @@ knowhow HLL::SettingManager {
1010
$*CTXSAVE := 0;
1111
}
1212

13+
method load_module($module_name) {
14+
# XXX Implement the various bits of GLOBAL merging of the loaded
15+
# module. For now we just make sure we capture the mainline, though.
16+
my $*CTXSAVE := self;
17+
my $*MAIN_CTX;
18+
my $path := pir::join('/', pir::split('::', $module_name)) ~ '.pbc';
19+
pir::load_bytecode($path);
20+
}
21+
1322
method load_setting($setting_name) {
1423
if $setting_name ne 'NULL' {
1524
# Unless we already did so, load the setting.
@@ -26,3 +35,10 @@ knowhow HLL::SettingManager {
2635
return %settings_loaded{$setting_name};
2736
}
2837
}
38+
39+
# XXX For backwards compat while renaming to the above.
40+
knowhow HLL::SettingManager {
41+
method load_setting($setting_name) {
42+
ModuleLoader.load_setting($setting_name);
43+
}
44+
}

0 commit comments

Comments
 (0)