Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Clean up list assignment, allow for custom FETCH / STORE / INVOKE
  • Loading branch information
sorear committed Jul 20, 2010
1 parent 84a4c6b commit d48aa80
Showing 1 changed file with 12 additions and 23 deletions.
35 changes: 12 additions & 23 deletions Kernel.cs
Expand Up @@ -270,23 +270,29 @@ public class DynObject: IP6 {
if (klass.OnInvoke != null) {
return klass.OnInvoke(this, c, p, n);
} else {
return Fail(c, "No invoke handler set");
LValue[] np = new LValue[p.Length + 1];
Array.Copy(p, 0, np, 1, p.Length);
np[0] = new LValue(false, false, Kernel.MakeSC(this));
return InvokeMethod(c, "INVOKE", np, n);
}
}

public Frame Fetch(Frame c) {
if (klass.OnFetch != null) {
return klass.OnFetch(this, c);
} else {
return Fail(c, "No fetch handler set");
return InvokeMethod(c, "FETCH", new LValue[1] {
new LValue(false, false, Kernel.MakeSC(this)) }, null);
}
}

public Frame Store(Frame c, IP6 o) {
if (klass.OnStore != null) {
return klass.OnStore(this, c, o);
} else {
return Fail(c, "No store handler set");
return InvokeMethod(c, "STORE", new LValue[2] {
new LValue(false, false, Kernel.MakeSC(this)),
new LValue(false, false, Kernel.MakeSC(o)) }, null);
}
}
}
Expand Down Expand Up @@ -536,35 +542,18 @@ public class Kernel {
throw new Exception("assigning to readonly value");
}
if (th.pos[0].islist) {
// list assignments apply listy context to the RHS
// then delegate
if (th.pos[1].islist) {
return th.pos[0].container.Store(th.caller,
th.pos[1].container);
} else {
th.ip = 1;
return th.pos[1].container.Fetch(th);
}
return th.pos[0].container.InvokeMethod(th.caller,
"LISTSTORE", th.pos, null);
} else {
if (th.pos[1].islist) {
return th.pos[0].container.Store(th.caller,
th.pos[1].container);
} else {
th.ip = 3;
th.ip = 1;
return th.pos[1].container.Fetch(th);
}
}
case 1:
th.ip = 2;
return ((IP6)th.resultSlot).InvokeMethod(th, "list",
new LValue[1] { th.pos[1] }, null);
case 2:
if (!((Variable)th.resultSlot).lv.islist) {
throw new Exception(".list didn't return one!");
}
return th.pos[0].container.Store(th.caller,
((Variable)th.resultSlot).lv.container);
case 3:
return th.pos[0].container.Store(th.caller,
(IP6)th.resultSlot);
default:
Expand Down

0 comments on commit d48aa80

Please sign in to comment.