Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Incremental method table generation for single inheritance
  • Loading branch information
sorear committed Apr 1, 2011
1 parent 8caf924 commit 891ede5
Showing 1 changed file with 33 additions and 12 deletions.
45 changes: 33 additions & 12 deletions lib/Kernel.cs
Expand Up @@ -1251,6 +1251,7 @@ public struct MethodInfo {
public InvokeHandler mro_INVOKE;

public Dictionary<string, DispatchEnt> mro_methods;
public Dictionary<string, DispatchEnt> inherit_methods;
public Dictionary<string, P6any> private_mro;

public STable[] local_does;
Expand Down Expand Up @@ -1282,39 +1283,59 @@ public List<STable> superclasses
isa = new HashSet<STable>();
}

private void Revalidate() {
mro_methods = new Dictionary<string,DispatchEnt>();
void Revalidate() {
inherit_methods = mro_methods =
new Dictionary<string,DispatchEnt>();
private_mro = new Dictionary<string,P6any>();

if (mro == null)
return;
if (isRole)
return;

for (int kx = mro.Length - 1; kx >= 0; kx--) {
STable k = mro[kx];
foreach (MethodInfo m in k.lmethods) {
DispatchEnt de;
if ((m.flags & V_MASK) != V_PUBLIC)
continue;
string n = m.Name();
mro_methods.TryGetValue(n, out de);
mro_methods[n] = new DispatchEnt(de, m.impl);
}
if (superclasses.Count == 1) {
inherit_methods = mro_methods =
new Dictionary<string,DispatchEnt>(
superclasses[0].inherit_methods);
SetupMRO(this);
} else {
for (int kx = mro.Length - 1; kx >= 0; kx--)
SetupMRO(mro[kx]);
}

SetupPrivates();
SetupVTables();
}

void SetupMRO(STable k) {
foreach (MethodInfo m in k.lmethods) {
DispatchEnt de;
if ((m.flags & V_MASK) != V_PUBLIC)
continue;
string n = m.Name();
inherit_methods.TryGetValue(n, out de);
inherit_methods[n] = new DispatchEnt(de, m.impl);
}
}

void SetupPrivates() {
foreach (MethodInfo m in lmethods) {
string n = m.Name();
if ((m.flags & V_MASK) == V_PRIVATE) {
private_mro[n] = m.impl;
}
else if ((m.flags & V_MASK) == V_SUBMETHOD) {
DispatchEnt de;
if (mro_methods == inherit_methods)
mro_methods = new Dictionary<string,DispatchEnt>(
inherit_methods);
mro_methods.TryGetValue(n, out de);
mro_methods[n] = new DispatchEnt(de, m.impl);
}
}
}

void SetupVTables() {
mro_at_key = _GetVT("at-key") as IndexHandler ?? CallAtKey;
mro_at_pos = _GetVT("at-pos") as IndexHandler ?? CallAtPos;
mro_Bool = _GetVT("Bool") as ContextHandler<Variable> ?? CallBool;
Expand Down

0 comments on commit 891ede5

Please sign in to comment.