Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Save delegates for kernel-defined subs
  • Loading branch information
sorear committed Oct 16, 2011
1 parent 3f80fca commit 6dd5b76
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
13 changes: 12 additions & 1 deletion lib/Kernel.cs
Expand Up @@ -1590,7 +1590,18 @@ public class UsedInScopeInfo {

void IFreeze.Freeze(FreezeBuffer fb) {
fb.Byte((byte)SerializationCode.SubInfo);
// TODO: make serialization work with the code
// TODO - saving constant pools NYI
string mn = null;
string tn = null;
if (code != null) {
Type t = code.Method.DeclaringType;
if (t.Assembly == typeof(Kernel).Assembly) {
tn = t.FullName;
mn = code.Method.Name;
}
}
fb.String(mn);
fb.String(tn);
fb.Int(nspill);
fb.Ints(sig_i);
if (sig_i != null) {
Expand Down
28 changes: 12 additions & 16 deletions lib/NieczaCLR.cs
Expand Up @@ -170,16 +170,6 @@ class CandidateSet {

return ret;
}

internal Frame Binder(Frame th) {
Variable[] rpos = new Variable[th.pos.Length - 1];
Array.Copy(th.pos, 1, rpos, 0, rpos.Length);
OverloadCandidate oc = (OverloadCandidate)
DoDispatch(rpos, th.named);
th.caller.resultSlot = oc.Invoke(Kernel.UnboxAny<object>(
th.pos[0].Fetch()), rpos, th.named);
return th.caller;
}
}

sealed class PropertyProxy : Variable {
Expand Down Expand Up @@ -483,10 +473,14 @@ public class CLRWrapperProvider {
OverloadCandidate.MakeCandidates(mi, pi, l);
}

static DynBlockDelegate BindGroup(string n, List<MultiCandidate> mc) {
CandidateSet cs = new CandidateSet(n, mc.ToArray());

return cs.Binder;
static Frame Binder(Frame th) {
Variable[] rpos = new Variable[th.pos.Length - 1];
Array.Copy(th.pos, 1, rpos, 0, rpos.Length);
OverloadCandidate oc = (OverloadCandidate)
(th.info.param[0] as CandidateSet).DoDispatch(rpos, th.named);
th.caller.resultSlot = oc.Invoke(Kernel.UnboxAny<object>(
th.pos[0].Fetch()), rpos, th.named);
return th.caller;
}

/*
Expand Down Expand Up @@ -689,10 +683,12 @@ public class CLRWrapperProvider {
foreach (string n in needNewWrapper) {
string siname = string.Format("{0}.{1}", m.name, n);

DynBlockDelegate method = BindGroup(siname, allMembers[n]);
SubInfo si = new SubInfo(siname, Binder);
si.param = new object[] {
new CandidateSet(siname, allMembers[n].ToArray()) };
if (CLROpts.Debug)
Console.WriteLine("Installing {0}", siname);
P6any sub = Kernel.MakeSub(new SubInfo(siname, method), null);
P6any sub = Kernel.MakeSub(si, null);
m.AddMethod(0, n, sub);
if (n == "Invoke" && typeof(Delegate).IsAssignableFrom(t))
m.AddMethod(0, "postcircumfix:<( )>", sub);
Expand Down

0 comments on commit 6dd5b76

Please sign in to comment.