Permalink
Browse files

Top removal: StashCursor

  • Loading branch information...
1 parent 3c5f8e1 commit 5ac00cc014828bd73d4836ed6469dfe37a4d1e21 @sorear committed Sep 25, 2012
Showing with 28 additions and 25 deletions.
  1. +1 −1 lib/CodeGen.cs
  2. +24 −21 lib/Kernel.cs
  3. +3 −3 lib/NieczaCLR.cs
View
@@ -4158,7 +4158,7 @@ public class DowncallReceiver : CallReceiver {
} else {
c.globals[hkey] = v = new StashEnt();
v.constant = true;
- v.v = StashCursor.MakePackage((who + "::" + key).Substring(2), Kernel.BoxRaw<string>(who + "::" + key, c.setting.StashMO));
+ v.v = StashCursor.MakePackage(c.setting, (who + "::" + key).Substring(2), Kernel.BoxRaw<string>(who + "::" + key, c.setting.StashMO));
pkg = v.v.Fetch().mo;
}
}
View
@@ -4167,25 +4167,27 @@ public struct StashCursor {
public const int DYNA = 3; // p1&p2
public const int CLR = 4; // p1(string)
+ Compartment setting;
int type;
object p1;
int p2;
public StashCursor(Frame fr, int depth) {
+ this.setting = fr.info.setting;
this.type = ROOT;
this.p1 = fr;
this.p2 = depth;
}
- public static Variable MakePackage(string name, P6any who) {
+ internal static Variable MakePackage(Compartment s, string name, P6any who) {
STable st = new STable(name);
st.who = who;
st.typeObj = st.initObj = new P6opaque(st, 0);
((P6opaque)st.typeObj).slots = null;
st.mo.type = P6how.PACKAGE;
st.mo.rtype = "package";
// XXX should be PackageHOW
- st.how = new BoxObject<STable>(st, Compartment.Top.ClassHOWMO, 0);
+ st.how = new BoxObject<STable>(st, s.ClassHOWMO, 0);
st.mo.Revalidate();
st.SetupVTables();
return st.typeObj;
@@ -4195,7 +4197,7 @@ public struct StashCursor {
Frame f = (Frame)p1;
if (p2 == 0) {
f = f.caller;
- if (f != null && f.info == Compartment.Top.ExitRunloopSI) f = f.caller;
+ if (f != null && f.info == setting.ExitRunloopSI) f = f.caller;
if (f == null) return false;
}
return true;
@@ -4275,8 +4277,8 @@ public struct StashCursor {
key = key.Remove(1,1);
StashEnt bv;
- if (Compartment.Top.currentGlobals.TryGetValue("\x8::GLOBAL" + key, out bv) ||
- Compartment.Top.currentGlobals.TryGetValue("\x9::PROCESS" + key, out bv)) {
+ if (setting.currentGlobals.TryGetValue("\x8::GLOBAL" + key, out bv) ||
+ setting.currentGlobals.TryGetValue("\x9::PROCESS" + key, out bv)) {
if (rbar_w) { bv.Bind(o); } else { o = bv.v; }
return true;
}
@@ -4303,12 +4305,13 @@ public struct StashCursor {
return true;
}
- public static P6any MakeCLR_WHO(string name) {
+ internal static P6any MakeCLR_WHO(Compartment s, string name) {
StashCursor sc = default(StashCursor);
+ sc.setting = s;
sc.type = CLR;
sc.p1 = name;
- P6any who = Kernel.BoxRaw(sc, Compartment.Top.PseudoStashMO);
- who.SetSlot(Compartment.Top.PseudoStashMO, "$!name", Kernel.BoxAnyMO(name, Compartment.Top.StrMO));
+ P6any who = Kernel.BoxRaw(sc, s.PseudoStashMO);
+ who.SetSlot(s.PseudoStashMO, "$!name", Kernel.BoxAnyMO(name, s.StrMO));
return who;
}
@@ -4325,21 +4328,21 @@ public struct StashCursor {
}
if (bind_to != null)
throw new NieczaException("No slot to bind");
- v = Compartment.Top.AnyP;
+ v = setting.AnyP;
goto have_v;
}
else if (type == CLR) {
if (Kernel.SaferMode)
throw new NieczaException("CLR objects may not be used directly in safe mode");
if (bind_to != null)
throw new NieczaException("Cannot bind interop namespaces");
- v = CLRWrapperProvider.GetNamedWrapper(Compartment.Top, (string)p1 + "." + key).typeObj;
+ v = CLRWrapperProvider.GetNamedWrapper(setting, (string)p1 + "." + key).typeObj;
goto have_v;
}
else if (type == WHO) {
// only special type is PARENT, maybe not even that?
P6any who = (P6any) p1;
- Variable keyv = Kernel.BoxAnyMO(key, Compartment.Top.StrMO);
+ Variable keyv = Kernel.BoxAnyMO(key, setting.StrMO);
if (bind_to != null) {
v = who.mo.mro_bind_key.Bind(who, keyv, bind_to);
return;
@@ -4349,12 +4352,12 @@ public struct StashCursor {
if (final) return;
if (v.Rw && !v.Fetch().IsDefined()) {
- if (!who.Isa(Compartment.Top.StashMO))
+ if (!who.Isa(setting.StashMO))
throw new NieczaException("Autovivification only implemented for normal-type stashes");
string name = Kernel.UnboxAny<string>(who);
- P6any new_who = Kernel.BoxRaw(name + "::" + key, Compartment.Top.StashMO);
+ P6any new_who = Kernel.BoxRaw(name + "::" + key, setting.StashMO);
who.mo.mro_bind_key.Bind(who, keyv,
- MakePackage(key, new_who));
+ MakePackage(setting, key, new_who));
sc.p1 = new_who;
return;
}
@@ -4450,7 +4453,7 @@ public struct StashCursor {
}
if (bind_to != null)
throw new NieczaException("No slot to bind");
- v = Compartment.Top.AnyP;
+ v = setting.AnyP;
goto have_v;
}
}
@@ -4463,9 +4466,9 @@ public struct StashCursor {
if (bind_to != null)
throw new NieczaException("cannot bind a pseudo package");
{
- P6any who = Kernel.BoxRaw(this, Compartment.Top.PseudoStashMO);
- who.SetSlot(Compartment.Top.PseudoStashMO, "$!name", Kernel.BoxAnyMO(key, Compartment.Top.StrMO));
- v = MakePackage(key, who);
+ P6any who = Kernel.BoxRaw(this, setting.PseudoStashMO);
+ who.SetSlot(setting.PseudoStashMO, "$!name", Kernel.BoxAnyMO(key, setting.StrMO));
+ v = MakePackage(setting, key, who);
}
return;
@@ -4517,14 +4520,14 @@ public struct StashCursor {
throw new NieczaException("Cannot bind to a stash");
if (sc.type == WHO)
return (P6any) sc.p1;
- P6any who = Kernel.BoxRaw(sc, Compartment.Top.PseudoStashMO);
- who.SetSlot(Compartment.Top.PseudoStashMO, "$!name", Kernel.BoxAnyMO(last, Compartment.Top.StrMO));
+ P6any who = Kernel.BoxRaw(sc, setting.PseudoStashMO);
+ who.SetSlot(setting.PseudoStashMO, "$!name", Kernel.BoxAnyMO(last, setting.StrMO));
return who;
}
if (bind_to != null) {
bool list = key != "" && (key[0] == '@' || key[0] == '%');
bind_to = Kernel.NewBoundVar(list ? Kernel.NBV_LIST :
- bind_ro ? Kernel.NBV_RO : Kernel.NBV_RW, Compartment.Top.MuMO,
+ bind_ro ? Kernel.NBV_RO : Kernel.NBV_RW, setting.MuMO,
bind_to); // XXX should use types maybe?
}
sc.Core(key, true, out r, out v, bind_to);
View
@@ -526,9 +526,9 @@ public class CLRWrapperProvider {
if (ty != null) {
c.named_wrapper_cache[nm] = r = GetWrapper(c, ty);
} else {
- c.named_wrapper_cache[nm] = r = StashCursor.MakePackage(
+ c.named_wrapper_cache[nm] = r = StashCursor.MakePackage(c,
"CLR" + nm.Replace(".","::"),
- StashCursor.MakeCLR_WHO(nm)).Fetch().mo;
+ StashCursor.MakeCLR_WHO(c, nm)).Fetch().mo;
}
return r;
}
@@ -655,7 +655,7 @@ public class CLRWrapperProvider {
if (CLROpts.Debug)
Console.WriteLine("Setting up wrapper for {0}", t.FullName);
STable m = new STable("CLR::" + t.FullName.Replace(".","::"));
- m.who = StashCursor.MakeCLR_WHO("." + t.FullName);
+ m.who = StashCursor.MakeCLR_WHO(s, "." + t.FullName);
m.how = Kernel.BoxRaw(m, s.ClassHOWMO);
STable pm = t.BaseType == null ? s.AnyMO : GetWrapper(s, t.BaseType);
STable[] mro = new STable[pm.mo.mro.Length + 1];

0 comments on commit 5ac00cc

Please sign in to comment.