Permalink
Browse files

STable knows own setting, more Top removal

  • Loading branch information...
1 parent 9840f57 commit 9acb21f322ffa63012c297320bc4e6f84d0d755d @sorear committed Sep 26, 2012
Showing with 42 additions and 42 deletions.
  1. +3 −3 lib/CodeGen.cs
  2. +22 −23 lib/Kernel.cs
  3. +17 −16 lib/ObjModel.cs
View
@@ -4443,7 +4443,6 @@ public class DowncallReceiver : CallReceiver {
if (outer == null) {
/* Hack - embed build information */
- var li = new LIConstant();
var info = new VarHash();
info["name"] = Builtins.MakeStr("niecza");
string vers = "(unknown)\n";
@@ -4458,7 +4457,7 @@ public class DowncallReceiver : CallReceiver {
vers.Substring(0, vers.Length - 1));
info["build-time"] = Builtins.now();
- li.value = Kernel.BoxAnyMO(info, ru.setting.HashMO);
+ var li = new LIConstant(Kernel.BoxAnyMO(info, ru.setting.HashMO));
n.AddLexical("$?PERL", li);
}
@@ -4472,7 +4471,8 @@ public class DowncallReceiver : CallReceiver {
return AddLexical(args, new LISimple(flags, type));
}
public static object add_hint(object[] args) {
- return AddLexical(args, new LIConstant());
+ SubInfo sub = (SubInfo)Handle.Unbox(args[1]);
+ return AddLexical(args, new LIConstant(sub.setting.AnyP));
}
public static object add_label(object[] args) {
return AddLexical(args, new LILabel());
View
@@ -262,8 +262,8 @@ public sealed class RWVariable: Variable {
return this;
}
public override void Store(P6any v) {
- if (v == Compartment.Top.NilP) {
- v = type == null ? Compartment.Top.AnyP : type.initObj;
+ if (v == v.mo.setting.NilP) {
+ v = type == null ? v.mo.setting.AnyP : type.initObj;
}
if (type != null && !v.Does(type)) {
throw new NieczaException("Nominal type check failed for scalar store; got " + v.mo.name + ", needed " + type.name + " or subtype");
@@ -315,7 +315,7 @@ public sealed class TiedVariable: Variable {
public override P6any Fetch() {
Variable vr = Kernel.RunInferior(fetch.Invoke(
- Kernel.GetInferiorRoot(), new [] {Compartment.Top.AnyP}, null));
+ Kernel.GetInferiorRoot(), new [] {fetch.mo.setting.AnyP}, null));
return vr.Fetch();
}
@@ -326,7 +326,7 @@ public sealed class TiedVariable: Variable {
vh.Do(this);
}
Kernel.RunInferior(store.Invoke(Kernel.GetInferiorRoot(),
- new [] { Compartment.Top.AnyP, v }, null));
+ new [] { store.mo.setting.AnyP, v }, null));
}
public override void Vivify() {
@@ -1226,8 +1226,7 @@ public class LICommon : LexInfo {
public class LIConstant : LexInfo {
public Variable value;
- public LIConstant() { this.value = Compartment.Top.AnyP; }
- internal LIConstant(Variable value) { this.value = value; }
+ public LIConstant(Variable value) { this.value = value; }
public override void Init(Frame f) { }
public override void BindFields() { }
@@ -1292,7 +1291,7 @@ public class LISimple : LIVarish {
if ((flags & NOINIT) != 0)
return;
if ((flags & ROINIT) != 0)
- Set(f, Compartment.Top.AnyP);
+ Set(f, owner.setting.AnyP);
else if ((flags & DEFOUTER) != 0)
Set(f, f.info.GetOuterTopic(f));
else if ((flags & LIST) != 0)
@@ -1474,12 +1473,12 @@ public class LIPackage : LexInfo {
public STable pkg;
public LIPackage(STable pkg) { this.pkg = pkg; }
public override object Get(Frame f) {
- return pkg == Compartment.Top.NilP.mo ? (Variable)Compartment.Top.Nil : pkg.typeObj;
+ return pkg == owner.setting.NilP.mo ? (Variable)owner.setting.Nil : pkg.typeObj;
}
public override void Init(Frame f) { }
internal override ClrOp GetCode(int up) {
- return pkg == Compartment.Top.NilP.mo ?
- EmitUnit.Current.RefConstant("Nil", "L", Compartment.Top.Nil, typeof(Variable)).head :
+ return pkg == owner.setting.NilP.mo ?
+ EmitUnit.Current.RefConstant("Nil", "L", owner.setting.Nil, typeof(Variable)).head :
EmitUnit.Current.TypeConstantP(pkg).head;
}
internal override void DoFreeze(FreezeBuffer fb) {
@@ -4741,9 +4740,9 @@ public class Kernel {
if (co != null) {
return co.value;
} else {
- if (typeof(T) == typeof(string) && o.Does(Compartment.Top.PseudoStrMO)) {
+ if (typeof(T) == typeof(string) && o.Does(o.mo.setting.PseudoStrMO)) {
// Truly vile hack to make dualvars work.
- return (T)o.GetSlot(Compartment.Top.PseudoStrMO, "$!value");
+ return (T)o.GetSlot(o.mo.setting.PseudoStrMO, "$!value");
} else {
throw new NieczaException("Cannot unbox a {0} from an object of repr {1}", typeof(T).Name, o.ReprName());
}
@@ -4930,18 +4929,18 @@ public class Kernel {
}
public static P6any MakeSub(SubInfo info, Frame outer) {
- P6opaque n = new P6opaque(info.mo ?? Compartment.Top.CodeMO, 2);
+ P6opaque n = new P6opaque(info.mo ?? info.setting.CodeMO, 2);
n.slots[0] = outer;
if (outer != null) outer.MarkShared();
n.slots[1] = info;
return n;
}
public static SubInfo GetInfo(P6any sub) {
- return (SubInfo)sub.GetSlot(Compartment.Top.CodeMO, "$!info");
+ return (SubInfo)sub.GetSlot(sub.mo.setting.CodeMO, "$!info");
}
public static Frame GetOuter(P6any sub) {
- return (Frame)sub.GetSlot(Compartment.Top.CodeMO, "$!outer");
+ return (Frame)sub.GetSlot(sub.mo.setting.CodeMO, "$!outer");
}
public class MMDParameter {
@@ -5058,7 +5057,7 @@ internal class MMDCandidate : MultiCandidate {
this.impl = impl;
this.group_n = group_n;
this.filter_n = filter_n;
- info = (SubInfo) impl.GetSlot(Compartment.Top.CodeMO, "$!info");
+ info = (SubInfo) impl.GetSlot(impl.mo.setting.CodeMO, "$!info");
pos = new List<MMDParameter>();
nam = new Dictionary<string,MMDParameter>();
@@ -5742,14 +5741,14 @@ internal class MMDCandidate : MultiCandidate {
public static STable DoInstantiateRole(STable prole, Variable alist) {
// get argument list - TODO make this saner
P6any argv = alist.Fetch();
- Variable[] args = argv.mo == Compartment.Top.ParcelMO ?
+ Variable[] args = argv.mo == prole.setting.ParcelMO ?
UnboxAny<Variable[]>(argv) : new Variable[] { alist };
STable r = new STable(prole.name + "[curried]");
r.mo.roleFactory = prole.mo.roleFactory;
r.mo.curriedArgs = args;
r.mo.FillRole(prole.mo.superclasses.ToArray(), null);
- r.how = new BoxObject<STable>(r, Compartment.Top.ClassHOWMO, 0);
+ r.how = new BoxObject<STable>(r, prole.setting.ClassHOWMO, 0);
r.mo.type = P6how.CURRIED_ROLE;
r.mo.rtype = "crole";
r.useAcceptsType = true;
@@ -5787,7 +5786,7 @@ internal class MMDCandidate : MultiCandidate {
r = new STable(arg.name + "[...]");
r.mo.FillRole(arg.mo.superclasses.ToArray(), null);
- r.how = new BoxObject<STable>(r, Compartment.Top.ClassHOWMO, 0);
+ r.how = new BoxObject<STable>(r, arg.setting.ClassHOWMO, 0);
r.mo.type = P6how.ROLE;
r.mo.rtype = "role";
r.mo.role_typecheck_list = arg.mo.role_typecheck_list;
@@ -5884,7 +5883,7 @@ internal class MMDCandidate : MultiCandidate {
foreach (STable r in roles) {
foreach (P6how.MethodInfo mi in r.mo.lmethods) {
var name = Prod.C(mi.flags & P6how.V_MASK, mi.short_name);
- SubInfo info = mi.impl.Isa(Compartment.Top.CodeMO) ?
+ SubInfo info = mi.impl.Isa(r.setting.CodeMO) ?
GetInfo(mi.impl) : null;
if ((mi.flags & P6how.M_MASK) != P6how.M_ONLY) {
// multi methods from roles are not suppressed and
@@ -6094,9 +6093,9 @@ class LastFrameNode {
public static void AddCap(List<Variable> p,
VarHash n, P6any cap) {
- Variable[] fp = cap.GetSlot(Compartment.Top.CaptureMO, "$!positionals") as Variable[];
- VarHash fn = cap.GetSlot(Compartment.Top.CaptureMO, "$!named")
- as VarHash;
+ var mo = cap.mo.setting.CaptureMO;
+ Variable[] fp = cap.GetSlot(mo, "$!positionals") as Variable[];
+ VarHash fn = cap.GetSlot(mo, "$!named") as VarHash;
p.AddRange(fp);
if (fn != null) AddMany(n, fn);
}
View
@@ -57,7 +57,7 @@ public abstract class P6any: Variable, IFreeze {
Variable[] npos = new Variable[pos.Length + 1];
Array.Copy(pos, 1, npos, 2, pos.Length - 1);
npos[0] = pos[0];
- npos[1] = Kernel.BoxAnyMO(name, Compartment.Top.StrMO);
+ npos[1] = Kernel.BoxAnyMO(name, mo.setting.StrMO);
return m.info.SetupCall(caller, m.outer, m.ip6,
npos, named, false, m);
}
@@ -564,13 +564,13 @@ public class DispatchSet {
this.superclasses = new List<STable>(superclasses);
local_roles = new List<STable>(cronies ?? new STable[0]);
type = ROLE; rtype = "role";
- SetMRO(Compartment.Top.AnyMO.mo.mro);
+ SetMRO(stable.setting.AnyMO.mo.mro);
}
public void FillParametricRole(P6any factory) {
type = PARAMETRIZED_ROLE; rtype = "prole";
roleFactory = factory;
- SetMRO(Compartment.Top.AnyMO.mo.mro);
+ SetMRO(stable.setting.AnyMO.mo.mro);
}
string C3State(int[] pointers, List<STable> into, STable[][] from) {
@@ -674,7 +674,7 @@ public class DispatchSet {
foreach (STable s2 in local_roles)
foreach (STable s3 in s2.mo.role_typecheck_list)
role_typecheck_list.Add(s3);
- SetMRO(Compartment.Top.AnyMO.mo.mro);
+ SetMRO(stable.setting.AnyMO.mo.mro);
Revalidate();
stable.SetupVTables();
return null;
@@ -686,9 +686,9 @@ public class DispatchSet {
Kernel.ApplyRoleToClass(stable, local_roles.ToArray());
}
- if (superclasses.Count == 0 && stable != Compartment.Top.MuMO) {
- superclasses.Add(type == GRAMMAR ? Compartment.Top.GrammarMO :
- Compartment.Top.AnyMO);
+ if (superclasses.Count == 0 && stable != stable.setting.MuMO) {
+ superclasses.Add(type == GRAMMAR ? stable.setting.GrammarMO :
+ stable.setting.AnyMO);
}
if ((err = ComputeMRO()) != null) return err;
@@ -717,7 +717,7 @@ public class DispatchSet {
if (pun != null) return pun;
STable n = new STable(stable.name);
- n.how = Kernel.BoxAnyMO<STable>(n, Compartment.Top.ClassHOWMO).Fetch();
+ n.how = Kernel.BoxAnyMO<STable>(n, stable.setting.ClassHOWMO).Fetch();
n.typeObj = n.initObj = new P6opaque(n);
((P6opaque)n.typeObj).slots = null;
@@ -843,6 +843,7 @@ public class STable: IFreeze {
public bool useAcceptsType;
public Type box_type;
+ internal Compartment setting = Compartment.Top;
/// }}}
/// compositon-created cache {{{
@@ -926,7 +927,7 @@ public class STable: IFreeze {
}
internal void SetupVTables() {
- var s = Compartment.Top;
+ var s = setting;
mro_push = _GetVT("push") as PushyHandler ?? s.CallPush;
mro_unshift = _GetVT("unshift") as PushyHandler ?? s.CallUnshift;
mro_shift = _GetVT("shift") as ContextHandler<Variable> ?? s.CallShift;
@@ -957,20 +958,20 @@ public class STable: IFreeze {
mro_succ = _GetVTU("succ") as ContextHandler<P6any> ?? s.CallSucc;
mro_to_clr = _GetVT("to-clr") as ContextHandler<object>;
- if (Compartment.Top.ComplexMO != null && HasType(Compartment.Top.ComplexMO))
+ if (s.ComplexMO != null && HasType(s.ComplexMO))
num_rank = Builtins.NR_COMPLEX;
- else if (Compartment.Top.NumMO != null && HasType(Compartment.Top.NumMO))
+ else if (s.NumMO != null && HasType(s.NumMO))
num_rank = Builtins.NR_FLOAT;
- else if (Compartment.Top.FatRatMO != null && HasType(Compartment.Top.FatRatMO))
+ else if (s.FatRatMO != null && HasType(s.FatRatMO))
num_rank = Builtins.NR_FATRAT;
- else if (Compartment.Top.RatMO != null && HasType(Compartment.Top.RatMO))
+ else if (s.RatMO != null && HasType(s.RatMO))
num_rank = Builtins.NR_FIXRAT;
- else if (Compartment.Top.IntMO != null && HasType(Compartment.Top.IntMO))
+ else if (s.IntMO != null && HasType(s.IntMO))
num_rank = Builtins.NR_FIXINT;
else
num_rank = -1;
- is_any = Compartment.Top.AnyMO != null && HasType(Compartment.Top.AnyMO);
+ is_any = s.AnyMO != null && HasType(s.AnyMO);
}
private object _GetVT(string name) { return _GetVTi(name, 1); }
@@ -1004,7 +1005,7 @@ public class STable: IFreeze {
if (mo.type == P6how.ROLE || mo.type == P6how.CURRIED_ROLE ||
mo.type == P6how.PARAMETRIZED_ROLE) {
if (name == "ACCEPTS" || name == "defined")
- return Compartment.Top.MuMO.FindMethod(name);
+ return setting.MuMO.FindMethod(name);
var pun = mo.PunRole();
var punfunc = Kernel.GetVar("::GLOBAL::Niecza", "&autopun").v;
var clone = Kernel.RunInferior(punfunc.Fetch().Invoke(

0 comments on commit 9acb21f

Please sign in to comment.