Permalink
Browse files

Top removal: iterators, substrings

  • Loading branch information...
1 parent eafdf64 commit d874a8e100caf120576787821adc77e93f3bd56b @sorear committed Nov 6, 2012
Showing with 25 additions and 21 deletions.
  1. +16 −14 lib/Builtins.cs
  2. +9 −7 lib/Kernel.cs
View
@@ -142,21 +142,23 @@ class SubstrLValue: Variable {
}
public override P6any Fetch() {
- string str = backing.Fetch().mo.mro_raw_Str.Get(backing);
+ var mo = backing.Fetch().mo;
+ string str = mo.mro_raw_Str.Get(backing);
string sub = Builtins.LaxSubstring2(str, from, length);
- return sub == null ? Compartment.Top.StrMO.typeObj :
- Kernel.BoxRaw(sub,Compartment.Top.StrMO);
+ return sub == null ? mo.setting.StrMO.typeObj :
+ Kernel.BoxRaw(sub, mo.setting.StrMO);
}
public override void Store(P6any v) {
- string str = backing.Fetch().mo.mro_raw_Str.Get(backing);
+ var mo = backing.Fetch().mo;
+ string str = mo.mro_raw_Str.Get(backing);
int left = (from < 0) ? 0 : (from > str.Length) ? str.Length : from;
int right = ((length > (str.Length - left)) ? (str.Length - left) :
(length < 0) ? 0 : length) + left;
string lfr = str.Substring(0, left);
string mfr = v.mo.mro_raw_Str.Get(v);
string rfr = str.Substring(right);
- backing.Store(Kernel.BoxRaw<string>(lfr + mfr + rfr, Compartment.Top.StrMO));
+ backing.Store(Kernel.BoxRaw<string>(lfr + mfr + rfr, mo.setting.StrMO));
}
public override void Freeze(Niecza.Serialization.FreezeBuffer fb) {
@@ -193,11 +195,11 @@ public partial class Builtins {
// When calling builtins, the binder is often bypassed, so we need to
// check arguement types ourselves. This is the really simple version
// that doesn't handle junctions, not often used.
- public static P6any NominalCheck(string name, STable mo, Variable v) {
+ public static P6any NominalCheck(string name, Variable v) {
P6any r = v.Fetch();
- if (!r.mo.HasType(mo))
+ if (!r.mo.is_any)
throw new NieczaException("Nominal type check failed for " + name +
- " needed " + mo.name + " got " + r.mo.name);
+ " needed Any got " + r.mo.name);
return r;
}
@@ -312,7 +314,7 @@ public partial class Builtins {
if (o.mo.num_rank >= 0) {
rank = o.mo.num_rank;
} else {
- if (o.Does(Compartment.Top.RealMO)) {
+ if (o.Does(o.mo.setting.RealMO)) {
rank = NR_FLOAT;
o = Kernel.RunInferior(o.InvokeMethod(Kernel.GetInferiorRoot(), "Bridge", new Variable[] { v }, null)).Fetch();
return o;
@@ -1633,8 +1635,8 @@ public partial class Builtins {
// only called from .Rat
[ImplicitConsts] public static Variable rat_approx(Constants c, Variable v1, Variable v2) {
- NominalCheck("$x", c.setting.AnyMO, v1);
- NominalCheck("$y", c.setting.AnyMO, v2);
+ NominalCheck("$x", v1);
+ NominalCheck("$y", v2);
BigInteger nc, dc, ne, de, na, da;
GetAsRational(v1, out nc, out dc);
@@ -1758,7 +1760,7 @@ public partial class Builtins {
}
[ImplicitConsts] public static Variable UniCat(Constants c, Variable v) {
- P6any o1 = NominalCheck("$x", c.setting.AnyMO, v);
+ P6any o1 = NominalCheck("$x", v);
char ch = (char) o1.mo.mro_raw_Numeric.Get(v);
int ix = (int) char.GetUnicodeCategory(ch);
return MakeInt(ix);
@@ -1793,7 +1795,7 @@ public partial class Builtins {
}
public static VarDeque HashIterRaw(int mode, Variable v) {
- P6any o = NominalCheck("$x", Compartment.Top.AnyMO, v);
+ P6any o = NominalCheck("$x", v);
VarHash d = Kernel.UnboxAny<VarHash>(o);
VarDeque lv = new VarDeque();
@@ -2848,7 +2850,7 @@ class CrossSource: ItemSource {
if ((ai.flags & P6how.A_TYPE) == P6how.A_SCALAR) {
if (ai.type == null)
obj = Kernel.NewMuScalar(
- vx != null ? vx.Fetch() : Compartment.Top.AnyMO.typeObj);
+ vx != null ? vx.Fetch() : n.mo.setting.AnyMO.typeObj);
else
obj = Kernel.NewRWScalar(ai.type,
vx != null ? vx.Fetch() : ai.type.initObj);
View
@@ -5447,16 +5447,17 @@ internal class MMDCandidate : MultiCandidate {
public static void IterToList(P6any list, VarDeque iter) {
VarDeque items = new VarDeque();
P6any item;
+ var s = list.mo.setting;
while (iter.Count() != 0) {
item = iter[0].Fetch();
- if (item.mo.HasType(Compartment.Top.IterCursorMO)) {
+ if (item.mo.HasType(s.IterCursorMO)) {
break;
} else {
items.Push(iter.Shift());
}
}
- list.SetSlot(Compartment.Top.ListMO, "$!items", items);
- list.SetSlot(Compartment.Top.ListMO, "$!rest", iter);
+ list.SetSlot(s.ListMO, "$!items", items);
+ list.SetSlot(s.ListMO, "$!rest", iter);
}
public static VarDeque IterFlatten(VarDeque inq) {
@@ -5477,13 +5478,14 @@ internal class MMDCandidate : MultiCandidate {
inq.UnshiftD(inq0.mo.mro_raw_iterator.Get(inq0v));
goto again;
}
- if (inq0.mo.HasType(Compartment.Top.IterCursorMO)) {
- Frame th = new Frame(null, null, Compartment.Top.IF_SI, Compartment.Top.AnyP);
+ var s = inq0.mo.setting;
+ if (inq0.mo.HasType(s.IterCursorMO)) {
+ Frame th = new Frame(null, null, s.IF_SI, s.AnyP);
th.lex0 = inq;
- P6opaque thunk = new P6opaque(Compartment.Top.GatherIteratorMO);
+ P6opaque thunk = new P6opaque(s.GatherIteratorMO);
th.coro_return = th;
thunk.slots[0] = NewMuScalar(th);
- thunk.slots[1] = NewMuScalar(Compartment.Top.AnyP);
+ thunk.slots[1] = NewMuScalar(s.AnyP);
outq.Push(thunk);
return outq;
}

0 comments on commit d874a8e

Please sign in to comment.