Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Cheat a bit with field access in the kernel
  • Loading branch information
sorear committed Sep 13, 2010
1 parent e0c8d34 commit 9f6189f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 26 deletions.
29 changes: 15 additions & 14 deletions lib/Cursor.cs
Expand Up @@ -95,9 +95,9 @@ public sealed class RxFrame {
return Kernel.Take(th, Kernel.NewROScalar(EMPTYP));
} else {
DynObject lst = new DynObject(ListMO);
lst.SetSlot("items", new VarDeque());
lst.SetSlot("rest", new VarDeque());
lst.SetSlot("flat", Kernel.NewROScalar(Kernel.AnyP));
lst.slots[0 /*items*/] = new VarDeque();
lst.slots[1 /*rest*/ ] = new VarDeque();
lst.slots[2 /*flat*/ ] = Kernel.NewROScalar(Kernel.AnyP);
th.caller.resultSlot = Kernel.NewRWListVar(lst);
}

Expand Down Expand Up @@ -238,6 +238,7 @@ public sealed class RxFrame {
public static DynMetaObject ListMO;
public static DynMetaObject GatherIteratorMO;
public static IP6 EMPTYP;

public Frame End(Frame th) {
return End(th, MakeMatch());
}
Expand All @@ -250,14 +251,14 @@ public sealed class RxFrame {
VarDeque ks = new VarDeque();
ks.Push(Kernel.NewROScalar(m));
DynObject it = new DynObject(GatherIteratorMO);
it.SetSlot("reify", Kernel.NewRWScalar(Kernel.AnyP));
it.SetSlot("frame", Kernel.NewRWScalar(th));
it.slots[0 /*frame*/] = Kernel.NewRWScalar(th);
it.slots[1 /*reify*/] = Kernel.NewRWScalar(Kernel.AnyP);
VarDeque iss = new VarDeque();
iss.Push(Kernel.NewROScalar(it));
DynObject lst = new DynObject(ListMO);
lst.SetSlot("items", ks);
lst.SetSlot("rest", iss);
lst.SetSlot("flat", Kernel.NewROScalar(Kernel.AnyP));
lst.slots[0 /*items*/] = ks;
lst.slots[1 /*rest*/ ] = iss;
lst.slots[2 /*flat*/ ] = Kernel.NewROScalar(Kernel.AnyP);
th.caller.resultSlot = Kernel.NewRWListVar(lst);
}
return th.caller;
Expand Down Expand Up @@ -343,9 +344,9 @@ public Cursor(IP6 proto, string text)

if (list) {
DynObject l = new DynObject(RxFrame.ListMO);
l.SetSlot("flat", Kernel.NewROScalar(Kernel.AnyP));
l.SetSlot("items", caps);
l.SetSlot("rest", new VarDeque());
l.slots[0 /*items*/] = caps;
l.slots[1 /*rest*/ ] = new VarDeque();
l.slots[2 /*flat*/ ] = Kernel.NewROScalar(Kernel.AnyP);
return Kernel.NewRWListVar(l);
} else {
return caps.Count() != 0 ? caps[0] :
Expand All @@ -360,9 +361,9 @@ public Cursor(IP6 proto, string text)
VarDeque ks = new VarDeque();

DynObject lst = new DynObject(RxFrame.ListMO);
lst.SetSlot("items", ks);
lst.SetSlot("rest", new VarDeque());
lst.SetSlot("flat", Kernel.NewROScalar(Kernel.AnyP));
lst.slots[0 /*items*/] = ks;
lst.slots[1 /*rest*/ ] = new VarDeque();
lst.slots[2 /*flat*/ ] = Kernel.NewROScalar(Kernel.AnyP);

if (p != 0 && p != l && CC.Word.Accepts(backing[p]) &&
CC.Word.Accepts(backing[p-1])) {
Expand Down
27 changes: 15 additions & 12 deletions lib/Kernel.cs
Expand Up @@ -522,8 +522,11 @@ public class CLRImportObject : IP6 {
public class Kernel {
public static DynBlockDelegate MainlineContinuation;

// Note: for classes without public .new, there's no way to get
// "interesting" user subclasses, so direct indexing is safe

public static object UnboxDO(DynObject o) {
return o.GetSlot("value");
return o.slots[0];
}

public static object UnboxAny(IP6 o) {
Expand All @@ -533,13 +536,13 @@ public class Kernel {

private static Frame SCFetch(IP6 th, Frame caller) {
DynObject dyo = (DynObject) th;
caller.resultSlot = dyo.GetSlot("value");
caller.resultSlot = dyo.slots[0];
return caller;
}

private static Frame SCStore(IP6 th, Frame caller, IP6 nv) {
DynObject dyo = (DynObject) th;
dyo.SetSlot("value", nv);
dyo.slots[0] = nv;
return caller;
}

Expand All @@ -561,17 +564,17 @@ public class Kernel {
public static Frame GatherHelper(Frame th, IP6 sub) {
DynObject dyo = (DynObject) sub;
Frame n = new Frame(th,
(Frame) dyo.GetSlot("outer"),
(SubInfo) dyo.GetSlot("info"));
(Frame) dyo.slots[0],
(SubInfo) dyo.slots[1]);
th.resultSlot = n;
return th;
}

private static Frame SubInvoke(IP6 th, Frame caller,
Variable[] pos, Dictionary<string,Variable> named) {
DynObject dyo = ((DynObject) th);
Frame outer = (Frame) dyo.GetSlot("outer");
SubInfo info = (SubInfo) dyo.GetSlot("info");
Frame outer = (Frame) dyo.slots[0];
SubInfo info = (SubInfo) dyo.slots[1];

Frame n = new Frame(caller, outer, info);
n.pos = pos;
Expand All @@ -596,7 +599,7 @@ public class Kernel {

public static Frame Die(Frame caller, string msg) {
DynObject n = new DynObject(((DynObject)StrP).klass);
n.SetSlot("value", msg);
n.slots[0] = msg;
return new FatalException(n).SearchForHandler(caller);
}

Expand All @@ -607,22 +610,22 @@ public class Kernel {

public static IP6 MakeSub(SubInfo info, Frame outer) {
DynObject n = new DynObject(info.mo ?? SubMO);
n.SetSlot("outer", outer);
n.SetSlot("info", info);
n.slots[0] = outer;
n.slots[1] = info;
return n;
}

public static DynObject MockBox(object v) {
DynObject n = new DynObject(ScalarMO);
n.SetSlot("value", v);
n.slots[0] = v;
return n;
}

public static Variable BoxAny(object v, IP6 proto) {
if (v == null)
return NewROScalar(proto);
DynObject n = new DynObject(((DynObject)proto).klass);
n.SetSlot("value", v);
n.slots[0] = v;
return NewROScalar(n);
}

Expand Down

0 comments on commit 9f6189f

Please sign in to comment.