Skip to content

Commit

Permalink
Specify types when accessing attributes in the C# code
Browse files Browse the repository at this point in the history
  • Loading branch information
sorear committed Jan 11, 2012
1 parent 938e43f commit 67bd4e6
Show file tree
Hide file tree
Showing 9 changed files with 106 additions and 89 deletions.
38 changes: 25 additions & 13 deletions lib/Builtins.cs
Expand Up @@ -1729,14 +1729,25 @@ public partial class Builtins {
return PosixWrapper.getuid() == (uint)stat[5];
}

public static P6any MakeList(VarDeque items, VarDeque rest) {
P6any l = new P6opaque(Kernel.ListMO);
l.SetSlot(Kernel.ListMO, "rest", rest);
l.SetSlot(Kernel.ListMO, "items", items);
return l;
}

public static P6any MakeArray(VarDeque items, VarDeque rest) {
P6any l = new P6opaque(Kernel.ArrayMO);
l.SetSlot(Kernel.ListMO, "rest", rest);
l.SetSlot(Kernel.ListMO, "items", items);
return l;
}

public static Variable BoxLoS(string[] los) {
VarDeque items = new VarDeque();
foreach (string i in los)
items.Push(Kernel.BoxAnyMO(i, Kernel.StrMO));
P6any l = new P6opaque(Kernel.ListMO);
l.SetSlot("rest", new VarDeque());
l.SetSlot("items", items);
return Kernel.NewRWListVar(l);
return Kernel.NewRWListVar(MakeList(items, new VarDeque()));
}

public static string[] UnboxLoS(Variable args) {
Expand Down Expand Up @@ -1802,11 +1813,15 @@ public partial class Builtins {
Variable.None, null)).Fetch();
}

public static Variable pair(Variable key, Variable value) {
public static P6any MakePair(Variable key, Variable value) {
P6any l = new P6opaque(Kernel.PairMO);
l.SetSlot("key", key);
l.SetSlot("value", value);
return Kernel.NewROScalar(l);
l.SetSlot(Kernel.EnumMO, "key", key);
l.SetSlot(Kernel.EnumMO, "value", value);
return l;
}

public static Variable pair(Variable key, Variable value) {
return Kernel.NewROScalar(MakePair(key, value));
}

public static VarDeque start_iter(Variable thing) {
Expand All @@ -1821,10 +1836,7 @@ public partial class Builtins {
VarDeque items = new VarDeque();
while (Kernel.IterHasFlat(rest, true))
items.Push(Kernel.NewMuScalar(rest.Shift().Fetch()));
P6any l = new P6opaque(Kernel.ArrayMO);
l.SetSlot("rest", rest);
l.SetSlot("items", items);
return Kernel.NewROScalar(l);
return Kernel.NewROScalar(MakeArray(items, rest));
}

public static string frame_subname(Frame fr) {
Expand Down Expand Up @@ -2547,7 +2559,7 @@ class CrossSource: ItemSource {
Kernel.CreateHash() : Kernel.CreateArray();
if (vx != null) Kernel.Assign(obj, vx);
}
n.SetSlot(ai.name, obj);
n.SetSlot(ai.owner, ai.name, obj);
}


Expand Down
4 changes: 2 additions & 2 deletions lib/CodeGen.cs
Expand Up @@ -4098,7 +4098,7 @@ public class DowncallReceiver : CallReceiver {
if (!b.v.rw && !b.v.Fetch().IsDefined()) {
r.Add(new Handle(b.v.Fetch().mo));
} else if (!b.v.rw && b.v.Fetch().Isa(Kernel.CodeMO)) {
r.Add(new Handle(b.v.Fetch().GetSlot("info")));
r.Add(new Handle(b.v.Fetch().GetSlot(Kernel.CodeMO, "info")));
} else {
r.Add(null);
}
Expand All @@ -4115,7 +4115,7 @@ public class DowncallReceiver : CallReceiver {
if (!b.v.rw && !b.v.Fetch().IsDefined()) {
return new Handle(b.v.Fetch().mo);
} else if (!b.v.rw && b.v.Fetch().Isa(Kernel.CodeMO)) {
return new Handle(b.v.Fetch().GetSlot("info"));
return new Handle(b.v.Fetch().GetSlot(Kernel.CodeMO, "info"));
} else return null;
} else {
return null;
Expand Down
26 changes: 13 additions & 13 deletions lib/Cursor.cs
Expand Up @@ -572,8 +572,8 @@ public sealed class RxFrame: IFreeze {
if (sobj.Isa(Kernel.RegexMO)) {
toks.Add(sobj);

pad.outer_stack.Add((Frame)sobj.GetSlot("outer"));
pad.info_stack.Add((SubInfo)sobj.GetSlot("info"));
pad.outer_stack.Add(Kernel.GetOuter(sobj));
pad.info_stack.Add(Kernel.GetInfo(sobj));
lads.Add(pad.info_stack[0].ltm.Reify(pad));
pad.outer_stack.Clear();
pad.info_stack.Clear();
Expand Down Expand Up @@ -830,8 +830,8 @@ public Cursor(P6any proto, string text, P6any actions)
CapInfo ci = null;
while (Kernel.IterHasFlat(iter, true)) {
P6any pair = iter.Shift().Fetch();
Variable k = (Variable)pair.GetSlot("key");
Variable v = (Variable)pair.GetSlot("value");
Variable k = (Variable)pair.GetSlot(Kernel.EnumMO, "key");
Variable v = (Variable)pair.GetSlot(Kernel.EnumMO, "value");
ci = new CapInfo(ci, new string[] {
k.Fetch().mo.mro_raw_Str.Get(k) }, v);
}
Expand Down Expand Up @@ -939,8 +939,8 @@ public Cursor(P6any proto, string text, P6any actions)
for (int i = 0; i < pos.Length; i++)
pos[i] = FixupList(posr[i]);

into.SetSlot("positionals", pos);
into.SetSlot("named", nam);
into.SetSlot(Kernel.CaptureMO, "positionals", pos);
into.SetSlot(Kernel.CaptureMO, "named", nam);
}

public Variable O(VarHash caps) {
Expand Down Expand Up @@ -1684,9 +1684,9 @@ public class LADDispatcher : LAD {
LAD[] opts = new LAD[cands.Length];

for (int i = 0; i < opts.Length; i++) {
pad.outer_stack.Add((Frame)cands[i].GetSlot("outer"));
pad.info_stack.Add((SubInfo)cands[i].GetSlot("info"));
opts[i] = ((SubInfo)cands[i].GetSlot("info")).ltm.Reify(pad);
pad.outer_stack.Add(Kernel.GetOuter(cands[i]));
pad.info_stack.Add(Kernel.GetInfo(cands[i]));
opts[i] = Kernel.GetInfo(cands[i]).ltm.Reify(pad);
pad.outer_stack.RemoveAt(pad.outer_stack.Count - 1);
pad.info_stack.RemoveAt(pad.info_stack.Count - 1);
}
Expand Down Expand Up @@ -1901,8 +1901,8 @@ public class Lexer {
LAD[] lads_p = new LAD[cands.Length];

for (int i = 0; i < lads_p.Length; i++) {
pad.outer_stack.Add((Frame)cands[i].GetSlot("outer"));
pad.info_stack.Add((SubInfo)cands[i].GetSlot("info"));
pad.outer_stack.Add(Kernel.GetOuter(cands[i]));
pad.info_stack.Add(Kernel.GetInfo(cands[i]));
lads_p[i] = pad.info_stack[0].ltm.Reify(pad);
pad.outer_stack.RemoveAt(pad.outer_stack.Count - 1);
pad.info_stack.RemoveAt(pad.info_stack.Count - 1);
Expand Down Expand Up @@ -2091,9 +2091,9 @@ public class Lexer {

public static P6any MakeDispatcher(string name, P6any proto, P6any[] cands) {
if (proto != null) {
SubInfo si = new SubInfo((SubInfo)proto.GetSlot("info"));
SubInfo si = new SubInfo(Kernel.GetInfo(proto));
si.param = new object[] { cands, null };
return Kernel.MakeSub(si, (Frame)proto.GetSlot("outer"));
return Kernel.MakeSub(si, Kernel.GetOuter(proto));
} else {
SubInfo si = new SubInfo(name, StandardProtoC);
si.param = new object[] { cands, null };
Expand Down
9 changes: 2 additions & 7 deletions lib/JSYNC.cs
Expand Up @@ -345,10 +345,7 @@ public class JsyncReader {
}
SkipWhite(true);
SkipChar(']');
P6any i = new P6opaque(Kernel.ArrayMO);
i.SetSlot("items", q);
i.SetSlot("rest", new VarDeque());
return Kernel.NewROScalar(i);
return Kernel.NewROScalar(Builtins.MakeArray(q, new VarDeque()));
} else if (look == '{') {
VarHash q = new VarHash();
int ct = 0;
Expand Down Expand Up @@ -503,9 +500,7 @@ public class JsyncReader {
Variable GetFromArray() {
SkipCharWS('[');
VarDeque kids = new VarDeque();
P6opaque obj = new P6opaque(Kernel.ArrayMO);
obj.SetSlot("items", kids);
obj.SetSlot("rest", new VarDeque());
P6any obj = Builtins.MakeArray(kids, new VarDeque());
bool comma = false;
string a_tag = null;

Expand Down

0 comments on commit 67bd4e6

Please sign in to comment.