Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Eliminate top-level protosub fields, they do not pull their weight
  • Loading branch information
sorear committed May 23, 2011
1 parent d39d163 commit 583d03b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
37 changes: 22 additions & 15 deletions lib/CLRBackend.cs
Expand Up @@ -586,7 +586,6 @@ class StaticSub {
public readonly Dictionary<string,Lexical> l_lexicals;
public readonly object body;

public FieldInfo protosub;
public FieldInfo subinfo;
public FieldInfo protopad;
public int nlexn;
Expand Down Expand Up @@ -658,9 +657,6 @@ class StaticSub {
subinfo = binder(Unit.SharedName('I', ix, name), Tokens.SubInfo);
if ((flags & SPAD_EXISTS) != 0)
protopad = binder(Unit.SharedName('P', ix, name), Tokens.Frame);
if (outer == null || (outer.Resolve<StaticSub>().flags
& SPAD_EXISTS) != 0)
protosub = binder(Unit.SharedName('S', ix, name), Tokens.P6any);

nlexn = 0;
for (int i = 0; i < lexicals.Count; i++)
Expand Down Expand Up @@ -1142,6 +1138,8 @@ sealed class Tokens {
P6any.GetField("mo");
public static readonly FieldInfo BValue_v =
BValue.GetField("v");
public static readonly FieldInfo SubInfo_protosub =
SubInfo.GetField("protosub");
public static readonly FieldInfo SubInfo_mo =
SubInfo.GetField("mo");
public static readonly FieldInfo SubInfo_sig_i =
Expand Down Expand Up @@ -4096,8 +4094,10 @@ public class CLRBackend {
CpsOp.GetSField(obj.subinfo))));
}

if (obj.protosub != null) {
thaw.Add(CpsOp.SetSField(obj.protosub,
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) :
Expand All @@ -4108,7 +4108,8 @@ public class CLRBackend {
Resolve<ParametricRole>();
thaw.Add(CpsOp.MethodCall(Tokens.DMO_FillParametricRole,
CpsOp.GetSField(pr.metaObject),
CpsOp.GetSField(obj.protosub)));
CpsOp.GetField(Tokens.SubInfo_protosub,
CpsOp.GetSField(obj.subinfo))));
}
}
});
Expand All @@ -4133,12 +4134,14 @@ public class CLRBackend {
CpsOp.GetSField(m.metaObject),
CpsOp.IntLiteral(me.kind),
CpsOp.StringLiteral(me.name),
CpsOp.GetSField(me.body.Resolve<StaticSub>().protosub)
CpsOp.GetField(Tokens.SubInfo_protosub,
CpsOp.GetSField(me.body.Resolve<StaticSub>().subinfo))
));
}
foreach (Attribute a in attrs) {
CpsOp init = a.ibody == null ? CpsOp.Null(Tokens.P6any) :
CpsOp.GetSField(a.ibody.Resolve<StaticSub>().protosub);
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);
Expand All @@ -4160,15 +4163,17 @@ public class CLRBackend {
if (obj.is_phaser >= 0)
thaw.Add(CpsOp.MethodCall(Tokens.Kernel_AddPhaser,
CpsOp.IntLiteral(obj.is_phaser),
CpsOp.GetSField(obj.protosub)));
CpsOp.GetField(Tokens.SubInfo_protosub,
CpsOp.GetSField(obj.subinfo))));

if (obj.exports != null) {
foreach (object o in obj.exports) {
thaw.Add(CpsOp.SetField(Tokens.BValue_v,
CpsOp.MethodCall(Tokens.Kernel_GetVar,
CpsOp.StringArray(false, JScalar.SA(0,o))),
CpsOp.MethodCall(Tokens.Kernel_NewROScalar,
CpsOp.GetSField(obj.protosub))));
CpsOp.GetField(Tokens.SubInfo_protosub,
CpsOp.GetSField(obj.subinfo)))));
}
}

Expand All @@ -4188,8 +4193,8 @@ public class CLRBackend {
LexSub lx = (LexSub)l.Value;
if ((obj.flags & StaticSub.SPAD_EXISTS) == 0) continue;
SetProtolex(obj, l.Key, lx, CpsOp.MethodCall(
Tokens.Kernel_NewROScalar,
CpsOp.GetSField(lx.def.Resolve<StaticSub>().protosub)));
Tokens.Kernel_NewROScalar, CpsOp.GetField(Tokens.SubInfo_protosub,
CpsOp.GetSField(lx.def.Resolve<StaticSub>().subinfo))));
} else if (l.Value is LexSimple) {
LexSimple lx = (LexSimple)l.Value;
if ((obj.flags & StaticSub.SPAD_EXISTS) == 0) continue;
Expand Down Expand Up @@ -4249,13 +4254,15 @@ public class CLRBackend {
CpsOp.GetField(lex, CpsOp.CallFrame()),
CpsOp.StringLiteral("*resume_" + s),
CpsOp.MethodCall(Tokens.Kernel_NewROScalar,
CpsOp.GetSField(m.protosub))));
CpsOp.GetField(Tokens.SubInfo_protosub,
CpsOp.GetSField(m.subinfo)))));
Unit su = CLRBackend.GetUnit(s);
s = su.setting;
m = su.mainline_ref.Resolve<StaticSub>();
}
thaw.Add(CpsOp.CpsReturn(CpsOp.SubyCall(false,"",
CpsOp.GetSField(m.protosub))));
CpsOp.GetField(Tokens.SubInfo_protosub,
CpsOp.GetSField(m.subinfo)))));
} else {
thaw.Add(CpsOp.CpsReturn(
CpsOp.MethodCall(Tokens.Kernel_NewROScalar,
Expand Down
1 change: 1 addition & 0 deletions lib/Kernel.cs
Expand Up @@ -337,6 +337,7 @@ public class SubInfo {
public STable mo;
// for inheriting hints
public SubInfo outer;
public P6any protosub;
public string name;
public Dictionary<string, BValue> hints;
// maybe should be a hint
Expand Down

0 comments on commit 583d03b

Please sign in to comment.