Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Generate class member info as blobs
  • Loading branch information
sorear committed May 23, 2011
1 parent 481e8ca commit 280737c
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 19 deletions.
38 changes: 19 additions & 19 deletions lib/CLRBackend.cs
Expand Up @@ -330,6 +330,10 @@ class Unit {
}

public void EmitXref(Xref x) {
if (x == null) {
EmitUShort(0xFFFF);
return;
}
EmitUShort(tdep_to_id[x.unit]);
EmitInt(x.index);
}
Expand Down Expand Up @@ -1150,6 +1154,8 @@ sealed class Tokens {
typeof(object).GetMethod("ToString", new Type[0]);
public static readonly MethodInfo RU_LoadStrArray =
RuntimeUnit.GetMethod("LoadStrArray");
public static readonly MethodInfo RU_LoadClassMembers =
RuntimeUnit.GetMethod("LoadClassMembers");
public static readonly MethodInfo RU_LoadSubInfo =
RuntimeUnit.GetMethod("LoadSubInfo");
public static readonly MethodInfo RU_LoadSignature =
Expand Down Expand Up @@ -4199,29 +4205,23 @@ public class CLRBackend {
((Role)m).methods;
Attribute[] attrs = (m is Class) ? ((Class)m).attributes :
((Role)m).attributes;
int b = unit.thaw_heap.Count;
unit.EmitInt(ix);
unit.EmitInt(methods.Length);
foreach (Method me in methods) {
thaw.Add(CpsOp.MethodCall(Tokens.DMO_AddMethod,
CpsOp.GetSField(m.metaObject),
CpsOp.IntLiteral(me.kind),
CpsOp.StringLiteral(me.name),
CpsOp.GetField(Tokens.SubInfo_protosub,
CpsOp.GetSField(me.body.Resolve<StaticSub>().subinfo))
));
unit.EmitInt(me.kind);
unit.EmitStr(me.name);
unit.EmitXref(me.body);
}
unit.EmitInt(attrs.Length);
foreach (Attribute a in attrs) {
CpsOp init = a.ibody == null ? CpsOp.Null(Tokens.P6any) :
CpsOp.GetField(Tokens.SubInfo_protosub,
CpsOp.GetSField(a.ibody.Resolve<StaticSub>().subinfo));
CpsOp type = a.type == null ?
CpsOp.GetSField(Tokens.Kernel_AnyMO) :
CpsOp.GetSField(a.type.Resolve<Class>().metaObject);
thaw.Add(CpsOp.MethodCall(Tokens.DMO_AddAttribute,
CpsOp.GetSField(m.metaObject),
CpsOp.StringLiteral(a.name),
CpsOp.BoolLiteral(a.publ), init, type));
unit.EmitStr(a.name);
unit.EmitByte(a.publ ? 1 : 0);
unit.EmitXref(a.ibody);
unit.EmitXref(a.type);
}
thaw.Add(CpsOp.MethodCall(Tokens.DMO_Invalidate,
CpsOp.GetSField(m.metaObject)));
thaw.Add(CpsOp.MethodCall(Tokens.RU_LoadClassMembers,
CpsOp.GetSField(unit.rtunit), CpsOp.IntLiteral(b)));
thaw.Add(CpsOp.SetField(Tokens.DMO_how, CpsOp.GetSField(m.metaObject),
CpsOp.MethodCall(Tokens.Kernel.GetMethod("BoxRaw").MakeGenericMethod(Tokens.STable), CpsOp.GetSField(m.metaObject), CpsOp.GetSField( ((Class) unit.GetCorePackage("ClassHOW")).metaObject))));
});
Expand Down
25 changes: 25 additions & 0 deletions lib/Kernel.cs
Expand Up @@ -209,6 +209,7 @@ public sealed class RuntimeUnit {

public object ReadXref(ref int from) {
int unit = ReadShort(ref from);
if (unit == 0xFFFF) return null;
RuntimeUnit ru = depends[unit] == null ? this : depends[unit];
return ru.xref[ReadInt(ref from)];
}
Expand Down Expand Up @@ -327,6 +328,30 @@ public sealed class RuntimeUnit {
for (int i = 0; i < r.Length; i++) r[i] = ReadLAD(ref from);
return r;
}

public void LoadClassMembers(int from) {
STable into = (STable) xref[ReadInt(ref from)];
int nmethods = ReadInt(ref from);

for (int i = 0; i < nmethods; i++) {
into.AddMethod(ReadInt(ref from), ReadStr(ref from),
((SubInfo)ReadXref(ref from)).protosub);
}

int nattr = ReadInt(ref from);

for (int i = 0; i < nattr; i++) {
string name = ReadStr(ref from);
bool pub = heap[from++] != 0;
SubInfo init = ReadXref(ref from) as SubInfo;
STable type = ReadXref(ref from) as STable;
into.AddAttribute(name, pub,
init != null ? init.protosub : null,
type != null ? type : Kernel.AnyMO);
}

into.Invalidate();
}
}

// This stores all the invariant stuff about a Sub, i.e. everything
Expand Down

0 comments on commit 280737c

Please sign in to comment.