Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
initVar and typeVar no longer have any reason to exist
  • Loading branch information
sorear committed May 27, 2012
1 parent 8af7893 commit 36b12c7
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 85 deletions.
24 changes: 10 additions & 14 deletions lib/Builtins.cs
Expand Up @@ -726,7 +726,7 @@ public partial class Builtins {
int len = substr_len(v1, pos, v3);
string str = v1.Fetch().mo.mro_raw_Str.Get(v1);
string sub = Builtins.LaxSubstring2(str, pos, len);
return sub == null ? Kernel.StrMO.typeVar : MakeStr(sub);
return sub == null ? Kernel.StrMO.typeObj : MakeStr(sub);
}

static readonly Func<Variable,Variable,Variable> plus_d = plus;
Expand Down Expand Up @@ -1574,7 +1574,7 @@ public partial class Builtins {

string r = o1.mo.mro_raw_Str.Get(v);
// XXX Failure
if (r.Length == 0) return Kernel.AnyMO.typeVar;
if (r.Length == 0) return Kernel.AnyP;
else if (r.Length >= 2 &&
r[0] >= (char)0xD800 && r[0] <= (char)0xDBFF &&
r[1] >= (char)0xDC00 && r[1] <= (char)0xDFFF)
Expand All @@ -1591,7 +1591,7 @@ public partial class Builtins {

int r = (int)o1.mo.mro_raw_Numeric.Get(v);
if (r >= 0x110000)
return Kernel.AnyMO.typeVar; // XXX failure
return Kernel.AnyP; // XXX failure
return Kernel.BoxAnyMO(Utils.Chr(r), Kernel.StrMO);
}

Expand Down Expand Up @@ -2428,7 +2428,7 @@ class CrossSource: ItemSource {
lkey = (char)lkey.Length + lkey + key;
StashEnt r;
if (!Kernel.currentGlobals.TryGetValue(lkey, out r))
return Kernel.AnyMO.typeVar;
return Kernel.AnyP;
Kernel.currentGlobals.Remove(key);
return r.v;
}
Expand Down Expand Up @@ -2637,7 +2637,6 @@ class CrossSource: ItemSource {

n.how = Kernel.BoxAny<STable>(n, obj.mo.how).Fetch();
n.typeObj = n.initObj = new P6opaque(n);
n.typeVar = n.initVar = n.typeObj;
((P6opaque)n.typeObj).slots = null;

n.mo.superclasses.Add(obj.mo);
Expand All @@ -2646,7 +2645,7 @@ class CrossSource: ItemSource {
newtype.Store(n.typeObj);

string aname = null;
if (init != Kernel.AnyMO.typeVar) {
if (init != Kernel.AnyP) {
if (!obj.IsDefined())
throw new NieczaException("Cannot initialize a slot when mixing into a type object");
if (n.mo.local_attr.Count != 1 || (n.mo.local_attr[0].flags & P6how.A_PUBLIC) == 0)
Expand All @@ -2662,7 +2661,7 @@ class CrossSource: ItemSource {
Kernel.Assign((Variable)obj.GetSlot(n, aname), init);
return obj;
} else {
return n.typeVar;
return n.typeObj;
}
}

Expand Down Expand Up @@ -2723,23 +2722,21 @@ class CrossSource: ItemSource {
STable r = new STable('{' + name + '}');
r.mo.FillRole(new STable[0], null);
r.typeObj = r.initObj = new P6opaque(r);
r.typeVar = r.initVar = r.typeObj;
r.mo.AddMethod(0, name, meth);
r.mo.Revalidate();
r.SetupVTables();
return r.typeVar;
return r.typeObj;
}

// TODO: merge
public static Variable cat_mixin_role(string name, P6any meth) {
STable r = new STable('{' + name + '}');
r.mo.FillRole(new STable[0], null);
r.typeObj = r.initObj = new P6opaque(r);
r.typeVar = r.initVar = r.typeObj;
r.mo.AddMethod(P6how.M_MULTI, name, meth);
r.mo.Revalidate();
r.SetupVTables();
return r.typeVar;
return r.typeObj;
}

public static Variable type_mixin_role(Variable type, Variable meth) {
Expand All @@ -2749,12 +2746,11 @@ class CrossSource: ItemSource {

r.mo.FillRole(new STable[0], null);
r.typeObj = r.initObj = new P6opaque(r);
r.typeVar = r.initVar = r.typeObj;
r.mo.AddMethod(0, name, meth.Fetch());
r.mo.AddMethod(P6how.V_PRIVATE, name, meth.Fetch());
r.mo.AddAttribute(name, P6how.A_PUBLIC, null, stype);
r.mo.Revalidate();
return r.typeVar;
return r.typeObj;
}

public static void raise(string sig) { PosixWrapper.raise(sig); }
Expand Down Expand Up @@ -2835,7 +2831,7 @@ public class Blackhole : Variable {
}

public static Variable param_type(P6any param) {
return (((Parameter)param).type ?? Kernel.AnyMO).typeVar;
return (((Parameter)param).type ?? Kernel.AnyMO).typeObj;
}

public static P6any param_subsig(P6any param) {
Expand Down
17 changes: 4 additions & 13 deletions lib/CodeGen.cs
Expand Up @@ -482,12 +482,8 @@ sealed class Tokens {
P6opaque.GetField("slots");
public static readonly FieldInfo DMO_typeObj =
STable.GetField("typeObj");
public static readonly FieldInfo DMO_typeVar =
STable.GetField("typeVar");
public static readonly FieldInfo DMO_initObj =
STable.GetField("initObj");
public static readonly FieldInfo DMO_initVar =
STable.GetField("initVar");
public static readonly FieldInfo DMO_how =
STable.GetField("how");
public static readonly FieldInfo Kernel_NumMO =
Expand Down Expand Up @@ -2506,7 +2502,7 @@ class NamProcessor {
} else if ((flags & Parameter.DEFOUTER) != 0) {
get = th.RawAccessLex("outerlex", lex, null);
} else if ((flags & Parameter.OPTIONAL) != 0) {
get = eu.TypeConstantV(type);
get = eu.TypeConstantP(type);
} else {
get = CpsOp.CpsCall(Tokens.Variable, Tokens.Kernel_Die,
CpsOp.StringLiteral("No value in "+name+" available for parameter "+sig.parms[i].name));
Expand Down Expand Up @@ -2721,8 +2717,6 @@ class NamProcessor {
}
if (kind == "mo")
return th.cpb.eu.TypeConstant(m);
if (kind == "typeVar")
return th.cpb.eu.TypeConstantV(m);
if (kind == "typeObj")
return th.cpb.eu.TypeConstantP(m);
throw new NotImplementedException("class_ref " + kind);
Expand Down Expand Up @@ -3326,7 +3320,7 @@ class NamProcessor {
object bit;
CpsOp tc = EmitUnit.Current.TypeConstant(ls.type);
if ((f & LISimple.ROINIT) != 0) {
bit = a(j("class_ref"), j("typeVar"), Kernel.AnyMO);
bit = a(j("class_ref"), j("typeObj"), Kernel.AnyMO);
} else if ((f & LISimple.DEFOUTER) != 0) {
bit = a(j("outerlex"), j(kv.Key));
} else if ((f & (LISimple.HASH | LISimple.LIST)) != 0) {
Expand Down Expand Up @@ -4223,7 +4217,7 @@ public class DowncallReceiver : CallReceiver {

Variable vitm = null;
if (item is STable)
vitm = ((STable)item).typeVar;
vitm = ((STable)item).typeObj;
else if (item is SubInfo)
vitm = ((SubInfo)item).protosub;
else if (item == null)
Expand Down Expand Up @@ -4372,7 +4366,6 @@ public class DowncallReceiver : CallReceiver {
if (nst.typeObj == null) // AnyMO.typeObj is set up early
nst.typeObj = new P6opaque(nst, 0);
((P6opaque)nst.typeObj).slots = null;
nst.typeVar = nst.typeObj;

if (ru.name == "CORE" && name == "Nil") {
// anomalously requires an iterable value
Expand All @@ -4382,7 +4375,6 @@ public class DowncallReceiver : CallReceiver {
if (pf != null)
pf.SetValue(null, nst.typeObj);

nst.initVar = nst.typeVar;
nst.initObj = nst.typeObj;
nst.who = Kernel.BoxRaw(who, Kernel.StashMO);
nst.how = Kernel.BoxRaw<STable>(nst, Kernel.ClassHOWMO);
Expand All @@ -4407,14 +4399,13 @@ public class DowncallReceiver : CallReceiver {

subset.mo.FillSubset(basety);
subset.initObj = basety.initObj;
subset.initVar = basety.initVar;
return null;
}
public static object type_get_basetype(object[] args) {
return Handle.Wrap(((STable)Handle.Unbox(args[1])).mo.superclasses[0]);
}
public static object type_get_type_var(object[] args) {
return Handle.Wrap(((STable)Handle.Unbox(args[1])).typeVar);
return Handle.Wrap(((STable)Handle.Unbox(args[1])).typeObj);
}
public static object type_set_where(object[] args) {
STable subset = (STable)Handle.Unbox(args[1]);
Expand Down
4 changes: 2 additions & 2 deletions lib/Cursor.cs
Expand Up @@ -870,7 +870,7 @@ public Cursor(P6any proto, string text, P6any actions)
l.slots[1 /*rest*/ ] = new VarDeque();
return l;
} else {
return caps.Count() != 0 ? caps[0] : Kernel.AnyMO.typeVar;
return caps.Count() != 0 ? caps[0] : Kernel.AnyP;
}
}

Expand Down Expand Up @@ -1632,7 +1632,7 @@ public class LADParam : LAD {
// alternatively, we could generalize to any variable, and add rechecks
Frame outer = pad.outer_stack[pad.outer_stack.Count - 1];

Variable vr = outer == null ? Kernel.AnyMO.typeVar :
Variable vr = outer == null ? Kernel.AnyP :
outer.LexicalFind(name);

P6any ob = vr.Fetch();
Expand Down

0 comments on commit 36b12c7

Please sign in to comment.