Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Implement object reification of pseudopackages and pseudostashes
  • Loading branch information
sorear committed Aug 2, 2011
1 parent be423d4 commit 48d6cd3
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
8 changes: 8 additions & 0 deletions lib/Builtins.cs
Expand Up @@ -1997,4 +1997,12 @@ class CrossSource: ItemSource {
dd.Remove(key);
return r.v;
}

public static Variable pstash_at_key(P6any st, string key) {
return Kernel.UnboxAny<StashCursor>(st).Raw(key, null);
}

public static Variable pstash_bind_key(P6any st, string key, Variable to) {
return Kernel.UnboxAny<StashCursor>(st).Raw(key, to);
}
}
5 changes: 5 additions & 0 deletions lib/CORE.setting
Expand Up @@ -962,6 +962,11 @@ my class Stash {
my class PseudoStash {
has $.name;
method at_key($key) {
Q:CgOp { (pstash_at_key (@ {self}) (obj_getstr {$key})) } }
method bind_key($key, \$to) {
Q:CgOp { (pstash_bind_key (@ {self}) (obj_getstr {$key}) {$to}) } }
}
my class Hash {
Expand Down
16 changes: 14 additions & 2 deletions lib/Kernel.cs
Expand Up @@ -2520,6 +2520,7 @@ public struct StashCursor {
st.mo.isPackage = true;
// XXX should be PackageHOW
st.how = new BoxObject<STable>(st, Kernel.AnyMO.how.mo, 0);
st.mo.Revalidate();
return st.typeVar;
}

Expand Down Expand Up @@ -2643,7 +2644,7 @@ public struct StashCursor {
Variable whov = Kernel.NewROScalar(who);
Variable keyv = Kernel.BoxAnyMO(key, Kernel.StrMO);
if (bind_to != null) {
who.mo.mro_bind_key.Bind(whov, keyv, bind_to);
v = who.mo.mro_bind_key.Bind(whov, keyv, bind_to);
return;
}
v = who.mo.mro_at_key.Get(whov, keyv);
Expand Down Expand Up @@ -2758,7 +2759,11 @@ public struct StashCursor {
if (!final) return;
if (bind_to != null)
throw new NieczaException("cannot bind a psuedo package");
v = MakePackage(key, Kernel.BoxRaw(sc, Kernel.PseudoStashMO));
{
P6any who = Kernel.BoxRaw(sc, Kernel.PseudoStashMO);
who.SetSlot("name", Kernel.BoxAnyMO(key, Kernel.StrMO));
v = MakePackage(key, who);
}
return;

have_v:
Expand All @@ -2770,6 +2775,13 @@ public struct StashCursor {
return;
}

internal Variable Raw(string key, Variable bind_to) {
Variable r;
StashCursor sc;
Core(key, true, out sc, out r, bind_to);
return r;
}

public Variable Indirect(string key, bool bind_ro, Variable bind_to) {
StashCursor sc = this;
StashCursor r;
Expand Down

0 comments on commit 48d6cd3

Please sign in to comment.