Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Move more of the sub2 logic into LoadSubInfo
  • Loading branch information
sorear committed May 23, 2011
1 parent 280737c commit 77f924c
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 52 deletions.
88 changes: 39 additions & 49 deletions lib/CLRBackend.cs
Expand Up @@ -202,8 +202,10 @@ class Unit {
xref[i] = new StaticSub(this, xr, (code != null &&
i < code.Length) ? (object[])code[i] : null);
} else {
xref[i] = Package.From(xr);
(xref[i] as Package).NoteExports(exp_pkg);
Package p = Package.From(xr);
xref[i] = p;
p.own_xref = new Xref(name, i, p.name);
p.NoteExports(exp_pkg);
}
}
tdeps = from[8] as object[];
Expand Down Expand Up @@ -428,6 +430,9 @@ class Xref {
public static Xref from(object x) {
return (x == null) ? null : new Xref(x as object[]);
}
public Xref(string unit, int index, string name) {
this.unit = unit; this.index = index; this.name = name;
}
public Xref(object[] from) : this(from, 0) {}
public Xref(object[] from, int ofs) {
unit = ((JScalar)from[ofs+0]).str;
Expand All @@ -438,6 +443,7 @@ class Xref {
}

class Package {
public Xref own_xref;
public readonly string name;
public readonly string type;
public readonly object[] exports;
Expand Down Expand Up @@ -1171,6 +1177,8 @@ sealed class Tokens {
BValue.GetField("v");
public static readonly FieldInfo SubInfo_protosub =
SubInfo.GetField("protosub");
public static readonly FieldInfo SubInfo_protopad =
SubInfo.GetField("protopad");
public static readonly FieldInfo SubInfo_mo =
SubInfo.GetField("mo");
public static readonly FieldInfo SubInfo_sig_i =
Expand Down Expand Up @@ -3715,21 +3723,32 @@ class NamProcessor {
CpsOp.GetSField(sub.unit.rtunit), CpsOp.IntLiteral(o));
}

public CpsOp SubInfoCtor() {
CpsOp[] args = new CpsOp[4];
public void SubInfoCtor(int ix, List<CpsOp> thaw) {
CpsOp[] args = new CpsOp[3];

int b = sub.unit.thaw_heap.Count;

int spec = 0;

if ((sub.flags & StaticSub.UNSAFE) != 0)
spec |= RuntimeUnit.SUB_IS_UNSAFE;
if (sub.sclass != "Sub")
spec |= RuntimeUnit.SUB_HAS_TYPE;
if (sub.protopad != null)
spec |= RuntimeUnit.MAKE_PROTOPAD;
if (sub.parametric_role_hack != null)
spec |= RuntimeUnit.SUB_IS_PARAM_ROLE;

args[0] = CpsOp.GetSField(sub.unit.rtunit);
args[1] = CpsOp.IntLiteral(b);
args[2] = CpsOp.DBDLiteral(cpb.mb);
args[3] = (sub.outer != null) ?
CpsOp.GetSField(sub.outer.Resolve<StaticSub>().subinfo) :
CpsOp.Null(Tokens.SubInfo);

sub.unit.EmitInt(ix);
sub.unit.EmitByte(spec);
sub.unit.EmitStr(sub.unit.name + " " +
(sub.name == "ANON" ? cpb.mb.Name : sub.name));
sub.unit.EmitIntArray(cpb.cx.lineBuffer.ToArray());
sub.unit.EmitXref(sub.outer);
sub.unit.EmitLAD(sub.ltm);
sub.unit.EmitIntArray(cpb.cx.ehspanBuffer.ToArray());
sub.unit.EmitStrArray(cpb.cx.ehlabelBuffer.ToArray());
Expand All @@ -3748,7 +3767,18 @@ class NamProcessor {
sub.unit.EmitStrArray(dylexn.ToArray());
sub.unit.EmitIntArray(dylexi.ToArray());

return CpsOp.MethodCall(Tokens.RU_LoadSubInfo, args);
if ((spec & RuntimeUnit.SUB_HAS_TYPE) != 0)
sub.unit.EmitXref(sub.GetCorePackage(sub.sclass).own_xref);

if (sub.parametric_role_hack != null)
sub.unit.EmitXref(sub.parametric_role_hack);

thaw.Add(CpsOp.SetSField(sub.subinfo,
CpsOp.MethodCall(Tokens.RU_LoadSubInfo, args)));
if (sub.protopad != null)
thaw.Add(CpsOp.SetSField(sub.protopad,
CpsOp.GetField(Tokens.SubInfo_protopad,
CpsOp.GetSField(sub.subinfo))));
}

void EnterCode(List<object> frags) {
Expand Down Expand Up @@ -4147,47 +4177,7 @@ public class CLRBackend {

unit.VisitSubsPreorder(delegate(int ix, StaticSub obj) {
if (Verbose > 0) Console.WriteLine("sub2 {0}", obj.name);
thaw.Add(CpsOp.SetSField(obj.subinfo, aux[ix].SubInfoCtor()));
thaw.Add(CpsOp.Operator(Tokens.Void, OpCodes.Stelem_Ref,
CpsOp.GetField(Tokens.RU_xref,CpsOp.GetSField(unit.rtunit)),
CpsOp.IntLiteral(ix), CpsOp.GetSField(obj.subinfo)));
if ((obj.flags & StaticSub.UNSAFE) != 0)
thaw.Add(CpsOp.MethodCall(Tokens.Kernel_CheckUnsafe,
CpsOp.GetSField(obj.subinfo)));
if (obj.sclass != "Sub") {
Class c = (Class) obj.GetCorePackage(obj.sclass);
thaw.Add(CpsOp.SetField(Tokens.SubInfo_mo,
CpsOp.GetSField(obj.subinfo),
CpsOp.GetSField(c.metaObject)));
}

if (obj.protopad != null) {
thaw.Add(CpsOp.SetSField(obj.protopad,
CpsOp.ConstructorCall(Tokens.Frame_ctor,
CpsOp.Null(Tokens.Frame),
(obj.outer == null ? CpsOp.Null(Tokens.Frame) :
CpsOp.GetSField(obj.outer.Resolve<StaticSub>().protopad)),
CpsOp.GetSField(obj.subinfo))));
}

if (obj.outer == null || (obj.outer.Resolve<StaticSub>().flags
& StaticSub.SPAD_EXISTS) != 0) {
thaw.Add(CpsOp.SetField(Tokens.SubInfo_protosub,
CpsOp.GetSField(obj.subinfo),
CpsOp.MethodCall(Tokens.Kernel_MakeSub,
CpsOp.GetSField(obj.subinfo),
(obj.outer == null ? CpsOp.Null(Tokens.Frame) :
CpsOp.GetSField(obj.outer.Resolve<StaticSub>().protopad)))));

if (obj.parametric_role_hack != null) {
ParametricRole pr = obj.parametric_role_hack.
Resolve<ParametricRole>();
thaw.Add(CpsOp.MethodCall(Tokens.DMO_FillParametricRole,
CpsOp.GetSField(pr.metaObject),
CpsOp.GetField(Tokens.SubInfo_protosub,
CpsOp.GetSField(obj.subinfo))));
}
}
aux[ix].SubInfoCtor(ix, thaw);
});

unit.VisitPackages(delegate(int ix, Package p) {
Expand Down
31 changes: 28 additions & 3 deletions lib/Kernel.cs
Expand Up @@ -279,18 +279,42 @@ public sealed class RuntimeUnit {
return new string(r);
}

public SubInfo LoadSubInfo(int from, DynBlockDelegate code, SubInfo outer) {
return new SubInfo(
public const int MAKE_PROTOPAD = 2;
public const int SUB_HAS_TYPE = 4;
public const int SUB_IS_UNSAFE = 8;
public const int SUB_IS_PARAM_ROLE = 16;

public SubInfo LoadSubInfo(int from, DynBlockDelegate code) {
int ix = ReadInt(ref from);
byte spec = heap[from++];
SubInfo ns = new SubInfo(
ReadStr(ref from), /*name*/
ReadIntArray(ref from), /*lines*/
code,
outer,
(SubInfo)ReadXref(ref from), /*outer*/
ReadLAD(ref from),
ReadIntArray(ref from), /*ehspan*/
ReadStrArray(ref from), /*ehlabel*/
ReadInt(ref from), /*nspill*/
ReadStrArray(ref from), /*dylexn*/
ReadIntArray(ref from)); /*dylexi*/

xref[ix] = ns;

if ((spec & SUB_IS_UNSAFE) != 0)
Kernel.CheckUnsafe(ns);
if ((spec & SUB_HAS_TYPE) != 0)
ns.mo = (STable) ReadXref(ref from);
if ((spec & MAKE_PROTOPAD) != 0)
ns.protopad = new Frame(null,
ns.outer == null ? null : ns.outer.protopad, ns);
if (ns.outer == null || ns.outer.protopad != null)
ns.protosub = Kernel.MakeSub(ns,
ns.outer == null ? null : ns.outer.protopad);
if ((spec & SUB_IS_PARAM_ROLE) != 0)
((STable) ReadXref(ref from)).FillParametricRole(ns.protosub);

return ns;
}

public LAD LoadLAD(int from) {
Expand Down Expand Up @@ -376,6 +400,7 @@ public class SubInfo {
// for inheriting hints
public SubInfo outer;
public P6any protosub;
public Frame protopad;
public string name;
public Dictionary<string, BValue> hints;
// maybe should be a hint
Expand Down

0 comments on commit 77f924c

Please sign in to comment.