Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Implement the "use" statement
  • Loading branch information
sorear committed Oct 20, 2011
1 parent 3a27812 commit 2e191e7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
27 changes: 24 additions & 3 deletions lib/CodeGen.cs
Expand Up @@ -3600,7 +3600,9 @@ public class DowncallReceiver : CallReceiver {
(SubInfo)Handle.Unbox(args[2]);
return null;
} else if (cmd == "unit_bottom") {
return new Handle(((RuntimeUnit)Handle.Unbox(args[1])).bottom);
return Handle.Wrap(((RuntimeUnit)Handle.Unbox(args[1])).bottom);
} else if (cmd == "unit_mainline") {
return Handle.Wrap(((RuntimeUnit)Handle.Unbox(args[1])).mainline);
} else if (cmd == "set_mainline") {
Backend.currentUnit.mainline = (SubInfo)Handle.Unbox(args[1]);
Backend.currentUnit.mainline.special |= SubInfo.MAINLINE;
Expand Down Expand Up @@ -3719,7 +3721,6 @@ public class DowncallReceiver : CallReceiver {
!csr2.used_in_scope.ContainsKey(lkey);
csr2 = csr2.outer, levels--) {

Console.WriteLine("Marking {0} used in {1}", lkey, csr2.name);
var uisi = new SubInfo.UsedInScopeInfo();
uisi.orig_file = li.file;
uisi.orig_line = li.line;
Expand Down Expand Up @@ -3775,7 +3776,6 @@ public class DowncallReceiver : CallReceiver {
foreach (KeyValuePair<string,LexInfo> kv in s.dylex) {
if (s.used_in_scope.ContainsKey(kv.Key))
continue;
Console.WriteLine("{0} not used in {1}", kv.Key, s.name);
ret.Add(kv.Key);
ret.Add(kv.Value.pos);
}
Expand Down Expand Up @@ -3844,6 +3844,27 @@ public class DowncallReceiver : CallReceiver {
}
}
return new Handle(pkg);
} else if (cmd == "unit_list_stash") {
RuntimeUnit c = (RuntimeUnit) Handle.Unbox(args[1]);
string who = (string)args[2];
var r = new List<object>();
string filter = ((char)who.Length) + who;

foreach (KeyValuePair<string,StashEnt> kv in c.globals) {
if (!Utils.StartsWithInvariant(filter, kv.Key))
continue;
r.Add(kv.Key.Substring(filter.Length));
StashEnt b = kv.Value;

if (!b.v.rw && !b.v.Fetch().IsDefined()) {
r.Add(new Handle(b.v.Fetch().mo));
} else if (!b.v.rw && b.v.Fetch().Isa(Kernel.CodeMO)) {
r.Add(new Handle(b.v.Fetch().GetSlot("info")));
} else {
r.Add(null);
}
}
return r.ToArray();
} else if (cmd == "unit_get") {
string who = (string)args[1];
string key = (string)args[2];
Expand Down
15 changes: 6 additions & 9 deletions src/niecza
Expand Up @@ -214,24 +214,21 @@ method statement_control:use ($/) {

my $module = $u2.mainline.compile_get_pkg($name.split('::'));
my $exp;
try $exp = $*unit.get_pkg($module, 'EXPORT', 'DEFAULT');
try $exp = $*unit.rel_pkg($module, 'EXPORT', 'DEFAULT');

# in the :: case, $module will usually be visible via GLOBAL
if !defined($name.index('::')) {
$*CURLEX<!sub>.add_my_stash($name, $module.xref);
$*CURLEX<!sub>.add_my_stash($name, $module);
}

return unless $exp;

my $h = $/.CURSOR;
for $*unit.list_stash($exp) -> $tup {
my $uname = $tup.key;
my $obj = $tup.value && $*unit.deref($tup.value);

if !$obj || $obj ~~ ::Metamodel::StaticSub {
$*CURLEX<!sub>.add_common_name($uname, $exp.xref, $uname);
for $*unit.list_stash($exp.who) -> $uname, $obj {
if !$obj || $obj.kind eq 'sub' {
$*CURLEX<!sub>.add_common_name($uname, $exp, $uname);
} else {
$*CURLEX<!sub>.add_my_stash($uname, $obj.xref);
$*CURLEX<!sub>.add_my_stash($uname, $obj);
}
$h.check_categorical($uname);
$h = $h.cursor_fresh(%*LANG<MAIN>);
Expand Down

0 comments on commit 2e191e7

Please sign in to comment.