Skip to content

Commit

Permalink
Implement multi-sub compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
sorear committed Oct 19, 2011
1 parent 893588d commit afac2df
Showing 1 changed file with 39 additions and 2 deletions.
41 changes: 39 additions & 2 deletions lib/Kernel.cs
Expand Up @@ -1024,12 +1024,41 @@ public class LIDispatch : LIVarish {
public LIDispatch() { }
internal LIDispatch(int index) { this.index = index; }
public override void Init(Frame f) {
throw new Exception("MMD NYI");
MakeDispatch(f);
}
internal override void DoFreeze(FreezeBuffer fb) {
fb.Byte((byte)LexSerCode.Dispatch);
fb.Int(index);
}

internal void MakeDispatch(Frame into) {
HashSet<string> names = new HashSet<string>();
List<P6any> cands = new List<P6any>();
string filter = name + ":";
string pn = name + ":(!proto)";

Frame f = into;
for (SubInfo csr = into.info; ; csr = csr.outer) {
bool brk = false;
foreach (KeyValuePair<string,LexInfo> kp in csr.dylex) {
if (Utils.StartsWithInvariant(filter, kp.Key) &&
kp.Key != pn &&
!names.Contains(kp.Key)) {
names.Add(kp.Key);
brk = true;
cands.Add(((Variable)kp.Value.Get(f)).Fetch());
}
}
if (csr.outer == null) break;
// don't go above nearest proto
if (csr.dylex.ContainsKey(pn)) break;
if (brk) cands.Add(null);
f = f.outer;
}

Set(into, Kernel.NewROScalar(Kernel.MakeDispatcher(name, null,
cands.ToArray())));
}
}

public class LIAlias : LexInfo {
Expand Down Expand Up @@ -1612,8 +1641,16 @@ public class UsedInScopeInfo {
li.BindFields();
if (name == "self")
self_key = li.SigIndex();
if (protopad != null)
if (protopad != null) {
li.Init(protopad);

int ix = name.IndexOf(':');
LexInfo disp;
if (ix >= 0 && dylex.TryGetValue(name.Substring(0, ix),
out disp) && disp is LIDispatch) {
((LIDispatch)disp).MakeDispatch(protopad);
}
}
}

internal void CreateProtopad() {
Expand Down

0 comments on commit afac2df

Please sign in to comment.