Skip to content

Commit ea37f39

Browse files
committed
First pass at ModuleLoader portability.
Doesn't do all the things, and some amount of this is going to have to be VM specific anyway. But this at least starts to clean up some of what can be stored.
1 parent fc24b09 commit ea37f39

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

src/ModuleLoader.pm

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,22 @@ knowhow ModuleLoader {
1010
my $explicit;
1111
try { $explicit := %*COMPILING<%?OPTIONS>{$explicit_path}; }
1212
if !nqp::isnull($explicit) && $explicit {
13-
@search_paths.push($explicit);
13+
nqp::push(@search_paths, $explicit);
1414
}
1515
else {
1616
my @lib_paths := pir::getinterp__P()[pir::const::IGLOBALS_LIB_PATHS][1];
17-
if +@lib_paths > 3 {
18-
@search_paths.push(@lib_paths[0]);
17+
if nqp::elems(@lib_paths) > 3 {
18+
nqp::push(@search_paths, @lib_paths[0]);
1919
}
2020
}
2121

2222
# Add CWD and blib.
23-
@search_paths.push('.');
24-
@search_paths.push('blib');
23+
nqp::push(@search_paths, '.');
24+
nqp::push(@search_paths, 'blib');
2525

2626
# Add NQP langauge directory.
2727
my %conf := pir::getinterp__P()[pir::const::IGLOBALS_CONFIG_HASH];
28-
@search_paths.push(%conf<libdir> ~ %conf<versiondir> ~
28+
nqp::push(@search_paths, %conf<libdir> ~ %conf<versiondir> ~
2929
'/languages/nqp/lib');
3030

3131
@search_paths
@@ -64,7 +64,7 @@ knowhow ModuleLoader {
6464
# Provided we have a mainline...
6565
if nqp::defined($module_ctx) {
6666
# Merge any globals.
67-
my $UNIT := pir::getattribute__PPs($module_ctx, 'lex_pad');
67+
my $UNIT := nqp::ctxlexpad($module_ctx);
6868
unless nqp::isnull($UNIT<GLOBALish>) {
6969
if +@global_merge_target {
7070
merge_globals(@global_merge_target[0], $UNIT<GLOBALish>);
@@ -87,43 +87,44 @@ knowhow ModuleLoader {
8787
# Obviously, just a first cut at this. :-)
8888
my %known_symbols;
8989
for $target.WHO {
90-
%known_symbols{$_.key} := 1;
90+
%known_symbols{nqp::iterkey_s($_)} := 1;
9191
}
9292
for $source.WHO {
93-
my $sym := $_.key;
93+
my $sym := nqp::iterkey_s($_);
94+
my $val := nqp::iterval($_);
9495
if !nqp::existskey(%known_symbols, $sym) {
9596
my $source_is_stub := 0;
9697
try {
97-
my $source_mo := $_.value.HOW;
98+
my $source_mo := $val.HOW;
9899
$source_is_stub := $source_mo.WHAT.HOW.name($source_mo) eq $stub_how &&
99-
!nqp::isnull(nqp::who($_.value)) && nqp::who($_.value);
100+
!nqp::isnull(nqp::who($val)) && nqp::who($val);
100101
}
101102
if $source_is_stub {
102-
my $source := $_.value;
103+
my $source := $val;
103104
my $source_clone := $source.HOW.new_type(:name($source.HOW.name($source)));
104105
$source_clone.HOW.compose($source_clone);
105106
my %WHO_clone;
106107
for nqp::who($source) {
107-
%WHO_clone{$_.key} := $_.value;
108+
%WHO_clone{nqp::iterkey_s($_)} := nqp::iterval($_);
108109
}
109110
nqp::setwho($source_clone, %WHO_clone);
110111
($target.WHO){$sym} := $source_clone;
111112
}
112113
else {
113-
($target.WHO){$sym} := $_.value;
114+
($target.WHO){$sym} := $val;
114115
}
115116
}
116-
elsif ($target.WHO){$sym} =:= $_.value {
117+
elsif ($target.WHO){$sym} =:= $val {
117118
# No problemo; a symbol can't conflict with itself.
118119
}
119120
else {
120-
my $source_mo := $_.value.HOW;
121+
my $source_mo := $val.HOW;
121122
my $source_is_stub := $source_mo.WHAT.HOW.name($source_mo) eq $stub_how;
122123
my $target_mo := ($target.WHO){$sym}.HOW;
123124
my $target_is_stub := $target_mo.WHAT.HOW.name($target_mo) eq $stub_how;
124125
if $source_is_stub && $target_is_stub {
125126
# Leave target as is, and merge the nested symbols.
126-
merge_globals(($target.WHO){$sym}, $_.value);
127+
merge_globals(($target.WHO){$sym}, $val);
127128
}
128129
else {
129130
nqp::die("Merging GLOBAL symbols failed: duplicate definition of symbol $sym");

0 commit comments

Comments
 (0)