Skip to content

Commit d0337bd

Browse files
committed
Stub in use. Will eventually be where GLOBAL merging and stuff gets done.
1 parent 5d47501 commit d0337bd

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

src/HLL/SerializationContextBuilder.pm

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,22 @@ class HLL::Compiler::SerializationContextBuilder {
169169
}
170170
}
171171

172+
# Loads a module immediately, and also makes sure we load it
173+
# during the deserialization.
174+
method load_module($module_name) {
175+
# Immediate loading.
176+
my $*LOAD_UNIT;
177+
my $path := pir::join('/', pir::split('::', $module_name)) ~ '.pbc';
178+
pir::load_bytecode($path);
179+
180+
# Make sure we do the loading during deserialization.
181+
self.add_event(:deserialize_past(
182+
PAST::Op.new( :pirop('load_bytecode vs'), $path )));
183+
184+
# Return UNIT of the loaded module.
185+
$*LOAD_UNIT
186+
}
187+
172188
# Installs a symbol into the package. Does so immediately, and
173189
# makes sure this happens on deserialization also.
174190
method install_package_symbol(@sym, $obj) {

src/NQP/Actions.pm

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,11 @@ method you_are_here($/) {
185185

186186
## Statement control
187187

188+
method statement_control:sym<use>($/) {
189+
$*SC.load_module(~$<name>);
190+
make PAST::Stmts.new();
191+
}
192+
188193
method statement_control:sym<if>($/) {
189194
my $count := +$<xblock> - 1;
190195
my $past := xblock_immediate( $<xblock>[$count].ast );

src/NQP/Grammar.pm

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,10 @@ token terminator:sym<}> { <?[}]> }
185185

186186
proto token statement_control { <...> }
187187

188+
token statement_control:sym<use> {
189+
<sym> \s :s <name>
190+
}
191+
188192
token statement_control:sym<if> {
189193
<sym> \s :s
190194
<xblock>

0 commit comments

Comments
 (0)