Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Implement unit linking
  • Loading branch information
sorear committed Oct 20, 2011
1 parent 604037a commit c52005a
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 8 deletions.
13 changes: 12 additions & 1 deletion lib/CodeGen.cs
Expand Up @@ -3582,13 +3582,23 @@ public class DowncallReceiver : CallReceiver {
Backend.currentUnit = (RuntimeUnit)Handle.Unbox(args[1]);
Kernel.currentGlobals = Backend.currentUnit.globals;
return null;
} else if (cmd == "unit_need_unit") {
RuntimeUnit ru = (RuntimeUnit)Handle.Unbox(args[1]);
string oname = (string)args[2];

RuntimeUnit tg = (RuntimeUnit)
RuntimeUnit.reg.LoadUnit(oname).root;
string err = ru.LinkUnit(tg);
return err == null ? (object)new Handle(tg) : new Exception(err);
} else if (cmd == "unit_anon_stash") {
return Backend.currentUnit.name + ":" +
(Backend.currentUnit.nextid++);
} else if (cmd == "unit_set_bottom") {
((RuntimeUnit)Handle.Unbox(args[1])).bottom =
(SubInfo)Handle.Unbox(args[2]);
return null;
} else if (cmd == "unit_bottom") {
return new Handle(((RuntimeUnit)Handle.Unbox(args[1])).bottom);
} else if (cmd == "set_mainline") {
Backend.currentUnit.mainline = (SubInfo)Handle.Unbox(args[1]);
Backend.currentUnit.mainline.special |= SubInfo.MAINLINE;
Expand Down Expand Up @@ -3703,6 +3713,7 @@ public class DowncallReceiver : CallReceiver {

if (file != null) {
for (SubInfo csr2 = from; csr2 != csr &&
csr2.unit == from.unit && // modify this unit only
!csr2.used_in_scope.ContainsKey(lkey);
csr2 = csr2.outer, levels--) {

Expand Down Expand Up @@ -4153,7 +4164,7 @@ public class DowncallReceiver : CallReceiver {
Kernel.SaferMode = true;
return null;
} else {
return new Exception("ERROR");
return new Exception("No handler for downcall " + cmd);
}
}
}
Expand Down
24 changes: 24 additions & 0 deletions lib/Kernel.cs
Expand Up @@ -630,6 +630,25 @@ class IdentityComparer : IEqualityComparer<object> {
FieldAttributes.Static);
}

internal string LinkUnit(RuntimeUnit other) {
foreach (RuntimeUnit third in other.depended_units)
depended_units.Add(third);

foreach (KeyValuePair<string, StashEnt> gm in other.globals) {
StashEnt ose;
StashEnt nse = gm.Value;
string who = gm.Key.Substring(1, (int)gm.Key[0]);
string name = gm.Key.Substring(1 + (int)gm.Key[0]);
string err = null;
if (globals.TryGetValue(gm.Key, out ose))
err = NsMerge(who, name, ref nse, ose);
if (err != null) return err;
globals[gm.Key] = nse;
}

return null;
}

public static Variable MakeAppropriateVar(string name) {
if (name.Length >= 1 && name[0] == '@')
return Kernel.CreateArray();
Expand Down Expand Up @@ -716,6 +735,8 @@ class IdentityComparer : IEqualityComparer<object> {
fb.String(asm_name);
fb.String(dll_name);

fb.Refs(dep);

fb.Int(constants.Count);
foreach (KeyValuePair<object,FieldBuilder> kv in constants) {
fb.String(kv.Value.Name);
Expand Down Expand Up @@ -756,6 +777,7 @@ class IdentityComparer : IEqualityComparer<object> {
Array.Copy(srcinfo, 0, args, 1, srcinfo.Length);
args[0] = "check_dated";
string result = (string) Builtins.UpCall(args);
Console.WriteLine(result);
if (result != "ok")
throw new ThawException("dated sources");
}
Expand All @@ -765,6 +787,8 @@ class IdentityComparer : IEqualityComparer<object> {
n.asm_name = tb.String();
n.dll_name = tb.String();

n.depended_units = new HashSet<RuntimeUnit>(tb.RefsA<RuntimeUnit>());

n.assembly = Assembly.LoadFrom(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, n.dll_name));
n.type = tb.type = n.assembly.GetType(n.name, true);

Expand Down
12 changes: 5 additions & 7 deletions src/CompilerBlob.cs
Expand Up @@ -31,13 +31,11 @@ public class UpcallReceiver : CallReceiver {
object[] ia = (object[]) i;
string[] sa = new string[ia.Length];
Array.Copy(ia, sa, ia.Length);
string[] sar = Builtins.UnboxLoS(Kernel.RunInferior(
Downcaller.upcall_cb.Fetch().Invoke(
Kernel.GetInferiorRoot(),
new Variable[] { Builtins.BoxLoS(sa) }, null)));
object[] iar = new object[sar.Length];
Array.Copy(sar, iar, sar.Length);
return iar;
Variable vr = Kernel.RunInferior(
Downcaller.upcall_cb.Fetch().Invoke(
Kernel.GetInferiorRoot(),
new Variable[] { Builtins.BoxLoS(sa) }, null));
return vr.Fetch().mo.mro_raw_Str.Get(vr);
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/NieczaBackendDotnet.pm6
Expand Up @@ -43,6 +43,9 @@ sub upcalled(@strings) {
}
return $!;
}
when "check_dated" {
return "ok"; #TODO
}
say "upcall: @strings.join('|')";
"ERROR";
}
Expand Down

0 comments on commit c52005a

Please sign in to comment.