Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Patch up several missing cases, add S02-names/symbolic-deref.t
  • Loading branch information
sorear committed Aug 2, 2011
1 parent a73f026 commit be423d4
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 33 deletions.
85 changes: 52 additions & 33 deletions lib/Kernel.cs
Expand Up @@ -2565,6 +2565,9 @@ public struct StashCursor {

bool TryLexOut(string key, bool rbar_w, ref Variable o) {
StashCursor sc = this;
if (key.Length >= 2 && key[1] == '*') {
return TryDynamic(key, rbar_w, ref o);
}
while (true) {
if (sc.TryLex(key, rbar_w, ref o)) return true;
if ((sc.p1 as Frame).outer == null && sc.p2 == 0)
Expand All @@ -2573,6 +2576,32 @@ public struct StashCursor {
}
}

bool TryDynamic(string key, bool rbar_w, ref Variable o) {
StashCursor sc = this;
while (true) {
if (sc.TryLex(key, rbar_w, ref o)) {
return true;
}
if (!sc.HasCaller())
break;
sc = sc.ToCaller();
}
if (key.Length >= 2 && key[1] == '*') {
key = key.Remove(1,1);
BValue bv;

if (Kernel.UnboxAny<Dictionary<string,BValue>>(Kernel.GlobalO).
TryGetValue(key, out bv) ||
Kernel.UnboxAny<Dictionary<string,BValue>>(Kernel.ProcessO).
TryGetValue(key, out bv)) {

if (rbar_w) { bv.v = o; } else { o = bv.v; }
return true;
}
}
return false;
}

bool TryLex(string key, bool rbar_w, ref Variable o) {
Frame f = (Frame)p1;
if (p2 > 0) {
Expand All @@ -2598,7 +2627,15 @@ public struct StashCursor {
sc = this;
if (type == DYNA) {
// DYNAMIC::{key}, no special names used
goto get_dynamic;
v = bind_to;
if (TryDynamic(key, (bind_to != null), ref v)) {
if (bind_to != null) return;
goto have_v;
}
if (bind_to != null)
throw new NieczaException("No slot to bind");
v = Kernel.AnyMO.typeVar;
goto have_v;
}
else if (type == WHO) {
// only special type is PARENT, maybe not even that?
Expand Down Expand Up @@ -2664,6 +2701,11 @@ public struct StashCursor {
sc.type = DYNA;
goto have_sc;
} else {
v = bind_to;
if (TryLexOut(key, bind_to != null, ref v)) {
if (bind_to != null) return;
goto have_v;
}
StashCursor n = default(StashCursor);
n.type = WHO;
n.p1 = (key == "PARENT" || key.Length > 0 &&
Expand Down Expand Up @@ -2696,9 +2738,6 @@ public struct StashCursor {
sc = sc.ToOuter();
goto have_sc;
}
else if (key.Length >= 2 && key[1] == '*') {
goto get_dynamic;
}
else {
v = bind_to;
if (TryLexOut(key, bind_to != null, ref v)) {
Expand All @@ -2717,38 +2756,18 @@ public struct StashCursor {

have_sc:
if (!final) return;
throw new NieczaException("PP NYI");
if (bind_to != null)
throw new NieczaException("cannot bind a psuedo package");
v = MakePackage(key, Kernel.BoxRaw(sc, Kernel.PseudoStashMO));
return;

have_v:
if (final) return;
throw new NieczaException("VIV NYI");

get_dynamic:
v = bind_to;
while (true) {
if (sc.TryLex(key, (bind_to != null), ref v)) {
if (bind_to != null) return;
goto have_v;
}
if (!sc.HasCaller())
break;
sc = sc.ToCaller();
}
if (key.Length >= 2 && key[1] == '*') {
key = key.Remove(1,1);
BValue bv;

if (Kernel.UnboxAny<Dictionary<string,BValue>>(Kernel.GlobalO).
TryGetValue(key, out bv) ||
Kernel.UnboxAny<Dictionary<string,BValue>>(Kernel.ProcessO).
TryGetValue(key, out bv)) {

if (bind_to != null) { bv.v = bind_to; return; }
else { v = bv.v; goto have_v; }
}
}
if (bind_to != null) throw new NieczaException("No slot to bind");
v = Kernel.AnyMO.typeVar;
if (v.rw || v.Fetch().IsDefined())
throw new NieczaException(key + " is not a stash");
sc.type = WHO;
sc.p1 = v.Fetch().mo.who;
return;
}

public Variable Indirect(string key, bool bind_ro, Variable bind_to) {
Expand Down
1 change: 1 addition & 0 deletions t/spectest.data
Expand Up @@ -23,6 +23,7 @@ S02-magicals/file_line.t
S02-magicals/sub.t
S02-names_and_variables/contextual.t
S02-names/identifier.t
S02-names/symbolic-deref.t
S02-whitespace_and_comments/begin_end_pod.t
S02-whitespace_and_comments/pod-in-multi-line-exprs.t
S02-whitespace_and_comments/sub-block-parsing.t
Expand Down

0 comments on commit be423d4

Please sign in to comment.