Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Encapsulate variable property accessors

  • Loading branch information...
commit f1da0623dcfd1635c87bbba547d00860e8bd6249 1 parent 5d10b5f
@sorear authored
View
33 lib/Builtins.cs
@@ -136,9 +136,6 @@ class SubstrLValue: Variable {
this.backing = backing;
this.from = from;
this.length = length;
- // XXX Should binding a substr lvalue count as binding the original?
- this.whence = null;
- this.rw = backing.rw;
}
public override P6any Fetch() {
@@ -278,15 +275,6 @@ public partial class Builtins {
avs[jpivot] = n; return dgt(avs[0], avs[1], avs[2]); });
}
- // Assign a value to a variable, while handling list variables sensibly
- public static void AssignV(Variable lhs, P6any rhs) {
- if (!lhs.islist) {
- lhs.Store(rhs);
- } else {
- lhs.Fetch().mo.mro_LISTSTORE.Get(lhs, Kernel.NewROScalar(rhs));
- }
- }
-
// Truncating substrings useful in some places
public static string LaxSubstring(string str, int from) {
if (from < 0 || from > str.Length)
@@ -1522,27 +1510,27 @@ public partial class Builtins {
public static Variable postinc(Variable v) {
P6any o1 = v.Fetch();
- AssignV(v, o1.mo.mro_succ.Get(v));
+ v.AssignO(o1.mo.mro_succ.Get(v), false);
if (!o1.IsDefined()) // note: slightly wrong for my Bool $x; $x++
o1 = Kernel.BoxRaw<int>(0, Kernel.IntMO);
return Kernel.NewROScalar(o1);
}
public static Variable preinc(Variable v) {
- AssignV(v, v.Fetch().mo.mro_succ.Get(v));
+ v.AssignO(v.Fetch().mo.mro_succ.Get(v), false);
return v;
}
public static Variable postdec(Variable v) {
P6any o1 = v.Fetch();
- AssignV(v, o1.mo.mro_pred.Get(v));
+ v.AssignO(o1.mo.mro_pred.Get(v), false);
if (!o1.IsDefined()) // note: slightly wrong for my Bool $x; $x--
o1 = Kernel.BoxRaw<int>(0, Kernel.IntMO);
return Kernel.NewROScalar(o1);
}
public static Variable predec(Variable v) {
- AssignV(v, v.Fetch().mo.mro_pred.Get(v));
+ v.AssignO(v.Fetch().mo.mro_pred.Get(v), false);
return v;
}
@@ -1618,7 +1606,7 @@ public partial class Builtins {
if (type >= 8) {
type -= 8;
foreach (Variable e in elems)
- if (e.islist) goto need_flatten;
+ if (e.List) goto need_flatten;
goto flat_enough;
need_flatten:;
VarDeque iter = new VarDeque(elems);
@@ -1949,7 +1937,7 @@ public partial class Builtins {
}
public static VarDeque start_iter(Variable thing) {
- if (thing.islist)
+ if (thing.List)
return thing.Fetch().mo.mro_raw_iterator.Get(thing);
else
return new VarDeque(thing);
@@ -2036,7 +2024,7 @@ class ItemSource {
P6any i = v.Fetch();
if (i.mo.HasType(Kernel.IterCursorMO))
return 0;
- if (v.islist) {
+ if (v.List) {
items.Shift();
items.UnshiftD(i.mo.mro_raw_iterator.Get(v));
goto again;
@@ -2463,7 +2451,7 @@ class CrossSource: ItemSource {
if ((mode & 2) != 0) {
fr.PushLeave(type, v.Fetch());
}
- else if (v.islist) {
+ else if (v.List) {
fr.PushLeave(type, Kernel.RunInferior(v.Fetch().InvokeMethod(
Kernel.GetInferiorRoot(), "TEMP",
new Variable[] { v }, null)).Fetch());
@@ -2701,7 +2689,7 @@ class CrossSource: ItemSource {
Kernel.CreateHash() : Kernel.CreateArray();
if (vx != null) {
// https://github.com/sorear/niecza/issues/104
- if (!vx.islist)
+ if (!vx.List)
vx = Kernel.NewRWListVar(vx.Fetch());
Kernel.Assign(obj, vx);
}
@@ -2785,7 +2773,7 @@ public class Blackhole : Variable {
P6any value;
private Blackhole() {}
- public Blackhole(P6any value) { this.value = value; rw = true; }
+ public Blackhole(P6any value) { this.value = value; }
public override P6any Fetch() { return value; }
public override void Store(P6any v) { }
@@ -2802,7 +2790,6 @@ public class Blackhole : Variable {
var n = new Blackhole();
tb.Register(n);
n.value = (P6any) tb.ObjRef();
- n.rw = true;
return n;
}
}
View
16 lib/CodeGen.cs
@@ -3063,8 +3063,8 @@ class NamProcessor {
.GetMethod(name.Substring(ix+1), tx);
return CpsOp.CpsCall(cpsrt, mi, JScalar.A<CpsOp>(2, z, th.Scan)); };
- thandlers["var_islist"] = FieldGet(Tokens.Variable, "islist");
- thandlers["var_is_rw"] = FieldGet(Tokens.Variable, "rw");
+ thandlers["var_islist"] = Methody(null, Tokens.Variable.GetMethod("get_List"));
+ thandlers["var_is_rw"] = Methody(null, Tokens.Variable.GetMethod("get_Rw"));
thandlers["llhow_name"] = FieldGet(Tokens.STable, "name");
thandlers["stab_what"] = FieldGet(Tokens.STable, "typeObject");
thandlers["obj_llhow"] = FieldGet(Tokens.P6any, "mo");
@@ -3862,7 +3862,7 @@ public class DowncallReceiver : CallReceiver {
for (int ix = 3; ix < args.Length; ix += 2) {
var v = (Variable)Handle.Unbox(args[ix+1]);
- if (v.rw) return null;
+ if (v.Rw) return null;
// this next one is a bit of a hack to get the right results
// while compiling the setting...
if (v.Fetch().mo.FindMethod("immutable") != null &&
@@ -4164,7 +4164,7 @@ public class DowncallReceiver : CallReceiver {
StashEnt v;
string hkey = (char)who.Length + who + key;
if (c.globals.TryGetValue(hkey, out v)) {
- if (v.v.rw || v.v.Fetch().IsDefined())
+ if (v.v.Rw || v.v.Fetch().IsDefined())
return new Exception((who + "::" + key).Substring(2) + " names a non-package");
pkg = v.v.Fetch().mo;
} else if (!auto) {
@@ -4190,9 +4190,9 @@ public class DowncallReceiver : CallReceiver {
r.Add(kv.Key.Substring(filter.Length));
StashEnt b = kv.Value;
- if (!b.v.rw && !b.v.Fetch().IsDefined()) {
+ if (!b.v.Rw && !b.v.Fetch().IsDefined()) {
r.Add(new Handle(b.v.Fetch().mo));
- } else if (!b.v.rw && b.v.Fetch().Isa(Kernel.CodeMO)) {
+ } else if (!b.v.Rw && b.v.Fetch().Isa(Kernel.CodeMO)) {
r.Add(new Handle(b.v.Fetch().GetSlot(Kernel.CodeMO, "$!info")));
} else {
r.Add(null);
@@ -4207,9 +4207,9 @@ public class DowncallReceiver : CallReceiver {
string hkey = (char)who.Length + who + key;
StashEnt b;
if (ru.globals.TryGetValue(hkey, out b)) {
- if (!b.v.rw && !b.v.Fetch().IsDefined()) {
+ if (!b.v.Rw && !b.v.Fetch().IsDefined()) {
return new Handle(b.v.Fetch().mo);
- } else if (!b.v.rw && b.v.Fetch().Isa(Kernel.CodeMO)) {
+ } else if (!b.v.Rw && b.v.Fetch().Isa(Kernel.CodeMO)) {
return new Handle(b.v.Fetch().GetSlot(Kernel.CodeMO, "$!info"));
} else return null;
} else {
View
2  lib/Cursor.cs
@@ -1642,7 +1642,7 @@ public class LADParam : LAD {
P6any ob = vr.Fetch();
- if (!vr.rw && ob.IsDefined() && ob.mo == Kernel.StrMO) {
+ if (!vr.Rw && ob.IsDefined() && ob.mo == Kernel.StrMO) {
if (Lexer.LtmTrace)
Console.WriteLine("Resolved {0} to \"{1}\"", name,
Kernel.UnboxAny<string>(ob));
View
2  lib/JSYNC.cs
@@ -632,7 +632,7 @@ public class JsyncReader {
Variable v_cursor = Kernel.GetVar(s2.Substring(0, cut),
s2.Substring(cut+2)).v;
- if (v_cursor.rw)
+ if (v_cursor.Rw)
Err(s2.Substring(2) + " does not name a loaded global class");
P6any p_cursor = v_cursor.Fetch();
View
181 lib/Kernel.cs
@@ -57,13 +57,23 @@ public sealed class DispatchEnt : IFreeze {
// A Variable is the meaning of function arguments, of any subexpression
// except the targets of := and ::=.
- [StructLayout(LayoutKind.Sequential, Pack = 1)]
public abstract class Variable : IFreeze {
- public ViviHook whence;
+ public const int RO = 0;
+ public const int RW = 1;
+ public const int LIST = 2;
- // these should be treated as ro for the life of the variable
- public bool rw;
- public bool islist;
+ public virtual int Mode { get { return RW; } }
+ public bool Rw { get { return Mode == RW; } }
+ public bool List { get { return Mode == LIST; } }
+ public virtual void Vivify() { }
+ public virtual Variable Assign(Variable inp) {
+ Store(inp.Fetch());
+ return this;
+ }
+ public virtual Variable AssignO(P6any inp, bool listishly) {
+ Store(inp);
+ return this;
+ }
public abstract P6any Fetch();
public abstract void Store(P6any v);
@@ -200,23 +210,43 @@ public class NewArrayViviHook : ViviHook {
}
}
+ [StructLayout(LayoutKind.Sequential, Pack = 1)]
public sealed class SimpleVariable: Variable {
STable type; // null for Any/Mu variables, and roish
P6any val;
+ ViviHook whence;
+ int mode;
private SimpleVariable() { }
public SimpleVariable(bool rw, bool islist, STable type, ViviHook whence, P6any val) {
- this.val = val; this.whence = whence; this.rw = rw;
- this.islist = islist; this.type = type;
+ this.val = val; this.whence = whence;
+ this.type = type;
+ mode = rw ? RW : islist ? LIST : RO;
}
public SimpleVariable(P6any val) { this.val = val; }
public SimpleVariable(bool islist, P6any val) {
- this.islist = islist; this.val = val;
+ this.mode = islist ? LIST : RO; this.val = val;
}
public override P6any Fetch() { return val; }
+ public override Variable Assign(Variable inp) {
+ if (mode == LIST) {
+ val.mo.mro_LISTSTORE.Get(this, inp);
+ } else {
+ Store(inp.Fetch());
+ }
+ return this;
+ }
+ public override Variable AssignO(P6any inp, bool listishly) {
+ if (mode == LIST) {
+ val.mo.mro_LISTSTORE.Get(this, new SimpleVariable(listishly, inp));
+ } else {
+ Store(inp);
+ }
+ return this;
+ }
public override void Store(P6any v) {
- if (!rw) {
+ if (mode != RW) {
throw new NieczaException("Writing to readonly scalar");
}
if (v == Kernel.NilP) {
@@ -237,6 +267,13 @@ public sealed class SimpleVariable: Variable {
return Kernel.BoxAnyMO<Variable>(this, Kernel.ScalarMO);
}
+ public override int Mode { get { return mode; } }
+ public override void Vivify() {
+ ViviHook w = whence;
+ whence = null;
+ if (w != null) w.Do(this);
+ }
+
const int S_RO = 0;
const int S_LIST = 1;
const int S_RW = 2;
@@ -244,11 +281,11 @@ public sealed class SimpleVariable: Variable {
public override void Freeze(FreezeBuffer fb) {
int code = ((int)SerializationCode.SimpleVariable) +
- (islist ? S_LIST : !rw ? S_RO : whence == null ? S_RW : S_VIV);
+ (mode == LIST ? S_LIST : mode == RO ? S_RO : whence == null ? S_RW : S_VIV);
fb.Byte((byte)code);
if (whence != null) fb.ObjRef(whence);
- if (rw) fb.ObjRef(type);
+ if (mode == RW) fb.ObjRef(type);
fb.ObjRef(val);
}
internal static SimpleVariable Thaw(ThawBuffer tb, int subcode) {
@@ -260,13 +297,13 @@ public sealed class SimpleVariable: Variable {
// rw = false islist = false whence = null type = null
break;
case S_LIST:
- n.islist = true;
+ n.mode = LIST;
break;
case S_VIV:
n.whence = (ViviHook) tb.ObjRef();
goto case S_RW;
case S_RW:
- n.rw = true;
+ n.mode = RW;
n.type = (STable) tb.ObjRef();
break;
}
@@ -278,13 +315,13 @@ public sealed class SimpleVariable: Variable {
public sealed class TiedVariable: Variable {
P6any fetch;
P6any store;
+ ViviHook whence;
private TiedVariable() { }
public TiedVariable(P6any whsub, P6any fetch, P6any store) {
this.fetch = fetch;
this.store = store;
this.whence = whsub.IsDefined() ? new SubViviHook(whsub) : null;
- this.rw = true;
}
public override P6any Fetch() {
@@ -303,6 +340,11 @@ public sealed class TiedVariable: Variable {
new [] { Kernel.AnyMO.typeVar, Kernel.NewROScalar(v) }, null));
}
+ public override void Vivify() {
+ ViviHook w = whence;
+ whence = null;
+ if (w != null) w.Do(this);
+ }
public override Variable GetVar() {
return Kernel.BoxAnyMO<Variable>(this, Kernel.ScalarMO);
}
@@ -841,7 +883,7 @@ public sealed class RuntimeUnit : IFreeze {
}
static bool IsEmptyAggr(Variable v) {
- if (!v.islist) return false;
+ if (v.Mode != Variable.LIST) return false;
P6any p = v.Fetch();
if (p.mo == Kernel.ArrayMO) {
return ((VarDeque)p.GetSlot(Kernel.ListMO, "$!items")).Count() == 0 &&
@@ -862,18 +904,20 @@ public sealed class RuntimeUnit : IFreeze {
P6any oseo = ose.v.Fetch();
bool nseod = nseo.IsDefined();
bool oseod = oseo.IsDefined();
+ int omode = ose.v.Mode;
+ int nmode = nse.v.Mode;
// lowest priority are empty common symbols
- if (nse.v.rw && !nseod || !nse.constant && IsEmptyAggr(nse.v)) {
+ if (nmode == Variable.RW && !nseod || !nse.constant && IsEmptyAggr(nse.v)) {
nse = ose;
return null;
}
- if (ose.v.rw && !oseod || !ose.constant && IsEmptyAggr(ose.v)) {
+ if (omode == Variable.RW && !oseod || !ose.constant && IsEmptyAggr(ose.v)) {
return null;
}
// no conflict if items are identical
- if (ose.v == nse.v || !ose.v.rw && !nse.v.rw &&
- ose.v.islist == nse.v.islist && oseo == nseo) {
+ if (ose.v == nse.v || omode != Variable.RW &&
+ omode == nmode && oseo == nseo) {
nse = ose;
return null;
}
@@ -2782,10 +2826,9 @@ public class Frame: P6any, IFixup {
}
if (rw) {
- if (src.rw) {
+ if (src.Rw) {
// this will be a functional RW binding
- if (src.whence != null)
- Kernel.Vivify(src);
+ src.Vivify();
goto bound;
} else {
if (quiet) return false;
@@ -2793,7 +2836,7 @@ public class Frame: P6any, IFixup {
}
}
else {
- if (!src.rw && islist == src.islist)
+ if (src.Mode == (islist ? Variable.LIST : Variable.RO))
goto bound;
src = new SimpleVariable(islist, srco);
}
@@ -3163,22 +3206,22 @@ class CtxReturnSelf : ContextHandler<Variable> {
class CtxReturnSelfList : ContextHandler<Variable> {
public override Variable Get(Variable obj) {
- if (obj.islist) return obj;
+ if (obj.Mode == Variable.LIST) return obj;
return Kernel.NewRWListVar(obj.Fetch());
}
}
class CtxReturnSelfItem : ContextHandler<Variable> {
public override Variable Get(Variable obj) {
- if (!obj.islist) return obj;
+ if (obj.Mode != Variable.LIST) return obj;
return Kernel.NewROScalar(obj.Fetch());
}
}
class CtxAnyList : ContextHandler<Variable> {
public override Variable Get(Variable obj) {
- VarDeque itr = new VarDeque(
- obj.islist ? Kernel.NewROScalar(obj.Fetch()) : obj);
+ VarDeque itr = new VarDeque(obj.Mode == Variable.LIST ?
+ Kernel.NewROScalar(obj.Fetch()) : obj);
P6any l = new P6opaque(Kernel.ListMO);
Kernel.IterToList(l, itr);
return Kernel.NewRWListVar(l);
@@ -3197,7 +3240,7 @@ class IxParcelLISTSTORE : IndexHandler {
for (int i = 0; i < dsts.Length; i++) {
Variable d = dsts[i];
- if (d.islist) {
+ if (d.Mode == Variable.LIST) {
srcs[i] = new P6opaque(Kernel.ListMO);
Kernel.IterToList(srcs[i], src);
src = new VarDeque();
@@ -3208,13 +3251,7 @@ class IxParcelLISTSTORE : IndexHandler {
}
for (int i = 0; i < dsts.Length; i++) {
- Variable d = dsts[i];
- if (d.islist) {
- d.Fetch().mo.mro_LISTSTORE.Get(d,
- Kernel.NewRWListVar(srcs[i]));
- } else {
- d.Store(srcs[i]);
- }
+ dsts[i].AssignO(srcs[i], true);
}
return lhs;
@@ -3849,7 +3886,7 @@ class KeySlicer : IndexHandler {
public override Variable Get(Variable obj, Variable key) {
P6any ks = key.Fetch();
- if (key.islist || !ks.mo.is_any && ks.mo.HasType(Kernel.JunctionMO))
+ if (key.List || !ks.mo.is_any && ks.mo.HasType(Kernel.JunctionMO))
return Slice(obj, key);
else if (ks.mo.HasType(Kernel.WhateverMO))
return GetAll(obj);
@@ -3865,7 +3902,7 @@ class KeySlicer : IndexHandler {
class IxAnyDeleteKey : IndexHandler {
public override Variable Get(Variable obj, Variable key) {
P6any ks = key.Fetch();
- if (key.islist || !ks.mo.is_any && ks.mo.HasType(Kernel.JunctionMO))
+ if (key.List || !ks.mo.is_any && ks.mo.HasType(Kernel.JunctionMO))
return Slice(obj, key);
P6any os = obj.Fetch();
@@ -3878,7 +3915,7 @@ class IxAnyDeleteKey : IndexHandler {
class IxAnyExistsKey : IndexHandler {
public override Variable Get(Variable obj, Variable key) {
P6any ks = key.Fetch();
- if (key.islist || !ks.mo.is_any && ks.mo.HasType(Kernel.JunctionMO))
+ if (key.List || !ks.mo.is_any && ks.mo.HasType(Kernel.JunctionMO))
return Slice(obj, key);
P6any os = obj.Fetch();
@@ -3911,7 +3948,7 @@ class IxAnyBindPos : BindHandler {
class IxAnyAtKey : IndexHandler {
public override Variable Get(Variable obj, Variable key) {
P6any ks = key.Fetch();
- if (key.islist || !ks.mo.is_any && ks.mo.HasType(Kernel.JunctionMO))
+ if (key.List || !ks.mo.is_any && ks.mo.HasType(Kernel.JunctionMO))
return Slice(obj, key);
else if (ks.mo.HasType(Kernel.WhateverMO))
return GetAll(obj);
@@ -3926,7 +3963,7 @@ class IxAnyAtKey : IndexHandler {
class IxAnyAtPos : IndexHandler {
public override Variable Get(Variable obj, Variable key) {
P6any ks = key.Fetch();
- if (key.islist || !ks.mo.is_any && ks.mo.HasType(Kernel.JunctionMO))
+ if (key.List || !ks.mo.is_any && ks.mo.HasType(Kernel.JunctionMO))
return Slice(obj, key);
else if (ks.mo.HasType(Kernel.WhateverMO))
return GetAll(obj);
@@ -3951,7 +3988,7 @@ class IxAnyAtPos : IndexHandler {
class IxCursorAtKey : IndexHandler {
public override Variable Get(Variable obj, Variable key) {
P6any ks = key.Fetch();
- if (key.islist || !ks.mo.is_any && ks.mo.HasType(Kernel.JunctionMO))
+ if (key.List || !ks.mo.is_any && ks.mo.HasType(Kernel.JunctionMO))
return Slice(obj, key);
else if (ks.mo.HasType(Kernel.WhateverMO))
return GetAll(obj);
@@ -3966,7 +4003,7 @@ class IxCursorAtKey : IndexHandler {
class IxCursorAtPos : IndexHandler {
public override Variable Get(Variable obj, Variable key) {
P6any ks = key.Fetch();
- if (key.islist || !ks.mo.is_any && ks.mo.HasType(Kernel.JunctionMO))
+ if (key.List || !ks.mo.is_any && ks.mo.HasType(Kernel.JunctionMO))
return Slice(obj, key);
else if (ks.mo.HasType(Kernel.WhateverMO))
return GetAll(obj);
@@ -3982,7 +4019,7 @@ class IxCursorAtPos : IndexHandler {
class IxHashBindKey : BindHandler {
public override Variable Bind(Variable obj, Variable key, Variable to) {
- if (key.islist)
+ if (key.List)
throw new NieczaException("Cannot bind to a hash slice");
P6any ks = key.Fetch();
P6any os = obj.Fetch();
@@ -3997,7 +4034,7 @@ class IxHashBindKey : BindHandler {
class IxHashAtKey : IndexHandler {
public override Variable Get(Variable obj, Variable key) {
P6any ks = key.Fetch();
- if (key.islist || !ks.mo.is_any && ks.mo.HasType(Kernel.JunctionMO))
+ if (key.List || !ks.mo.is_any && ks.mo.HasType(Kernel.JunctionMO))
return Slice(obj, key);
else if (ks.mo.HasType(Kernel.WhateverMO))
return GetAll(obj);
@@ -4017,7 +4054,7 @@ class IxHashAtKey : IndexHandler {
class IxHashExistsKey : IndexHandler {
public override Variable Get(Variable obj, Variable key) {
P6any ks = key.Fetch();
- if (key.islist || !ks.mo.is_any && ks.mo.HasType(Kernel.JunctionMO))
+ if (key.List || !ks.mo.is_any && ks.mo.HasType(Kernel.JunctionMO))
return Slice(obj, key);
P6any os = obj.Fetch();
if (!os.IsDefined()) return Kernel.FalseV;
@@ -4029,7 +4066,7 @@ class IxHashExistsKey : IndexHandler {
class IxHashDeleteKey : IndexHandler {
public override Variable Get(Variable obj, Variable key) {
P6any ks = key.Fetch();
- if (key.islist || !ks.mo.is_any && ks.mo.HasType(Kernel.JunctionMO))
+ if (key.List || !ks.mo.is_any && ks.mo.HasType(Kernel.JunctionMO))
return Slice(obj, key);
P6any os = obj.Fetch();
if (!os.IsDefined()) return Kernel.AnyMO.typeVar;
@@ -4054,7 +4091,7 @@ class IxListAtPos : IndexHandler {
public override Variable Get(Variable obj, Variable key) {
P6any ks = key.Fetch();
- if (key.islist || !ks.mo.is_any && ks.mo.HasType(Kernel.JunctionMO))
+ if (key.List || !ks.mo.is_any && ks.mo.HasType(Kernel.JunctionMO))
return Slice(obj, key);
else if (ks.mo.HasType(Kernel.WhateverMO))
return GetAll(obj);
@@ -4094,7 +4131,7 @@ class IxListAtPos : IndexHandler {
class IxListBindPos : BindHandler {
public override Variable Bind(Variable obj, Variable key, Variable to) {
- if (key.islist)
+ if (key.List)
throw new NieczaException("Cannot bind to a list slice");
P6any ks = key.Fetch();
P6any os = obj.Fetch();
@@ -4314,7 +4351,7 @@ public struct StashCursor {
if (final) return;
- if (v.rw && !v.Fetch().IsDefined()) {
+ if (v.Rw && !v.Fetch().IsDefined()) {
if (!who.Isa(Kernel.StashMO))
throw new NieczaException("Autovivification only implemented for normal-type stashes");
string name = Kernel.UnboxAny<string>(who);
@@ -4324,7 +4361,7 @@ public struct StashCursor {
sc.p1 = new_who;
return;
}
- else if (v.rw || v.Fetch().IsDefined()) {
+ else if (v.Rw || v.Fetch().IsDefined()) {
throw new NieczaException(key + " does not point to a package");
}
else {
@@ -4437,7 +4474,7 @@ public struct StashCursor {
have_v:
if (final) return;
- if (v.rw || v.Fetch().IsDefined())
+ if (v.Rw || v.Fetch().IsDefined())
throw new NieczaException(key + " is not a stash");
sc.type = WHO;
sc.p1 = v.Fetch().mo.who;
@@ -5159,23 +5196,17 @@ internal class MMDCandidate : MultiCandidate {
return new BoxObject<T>(v, proto);
}
- // check whence before calling
- public static void Vivify(Variable v) {
- ViviHook w = v.whence;
- v.whence = null;
- w.Do(v);
- }
-
public static Variable Decontainerize(Variable rhs) {
- if (!rhs.rw) return rhs;
- return new SimpleVariable(rhs.islist, rhs.Fetch());
+ if (!rhs.Rw) return rhs;
+ return new SimpleVariable(false, rhs.Fetch());
}
public const int NBV_RO = 0;
public const int NBV_RW = 1;
public const int NBV_LIST = 2;
public static Variable NewBoundVar(int mode, STable type, Variable rhs) {
- bool rw = rhs.rw && (mode & NBV_RW) != 0;
+ int omode = rhs.Mode;
+ bool rw = omode == Variable.RW && (mode & NBV_RW) != 0;
// we always have to fetch, because of subsets (XXX?)
P6any rhso = rhs.Fetch();
if (!rhso.Does(type))
@@ -5184,28 +5215,20 @@ internal class MMDCandidate : MultiCandidate {
if (rw) {
// working RW bind implies !rhs.islist, !islist; will return
// rhs if successful
- if (rhs.whence != null) Vivify(rhs);
+ rhs.Vivify();
return rhs;
}
bool islist = (mode & NBV_LIST) != 0;
// if source is !rw, we may not need to fetch it
- if (!rhs.rw && islist == rhs.islist)
+ if (omode == (islist ? Variable.LIST : Variable.RO))
return rhs;
return new SimpleVariable(islist, rhso);
}
public static Variable Assign(Variable lhs, Variable rhs) {
- if (!lhs.islist) {
- if (!lhs.rw)
- throw new NieczaException("assigning to readonly value");
-
- lhs.Store(rhs.Fetch());
- } else {
- lhs.Fetch().mo.mro_LISTSTORE.Get(lhs, rhs);
- }
- return lhs;
+ return lhs.Assign(rhs);
}
// ro, not rebindable
@@ -5364,7 +5387,7 @@ internal class MMDCandidate : MultiCandidate {
}
public static Frame PromoteToList(Frame th, Variable v) {
- if (!v.islist) {
+ if (!v.List) {
P6opaque lst = new P6opaque(Kernel.ListMO);
lst.slots[0 /*items*/] = new VarDeque(v);
lst.slots[1 /*rest*/ ] = new VarDeque();
@@ -5416,7 +5439,7 @@ internal class MMDCandidate : MultiCandidate {
throw new NieczaException("Circular data dependency in list iteration, or last fetch threw exception");
}
inq0 = inq0v.Fetch();
- if (inq0v.islist) {
+ if (inq0v.List) {
inq.Shift();
inq.UnshiftD(inq0.mo.mro_raw_iterator.Get(inq0v));
goto again;
@@ -5453,7 +5476,7 @@ internal class MMDCandidate : MultiCandidate {
if (i0 == null) {
throw new NieczaException("Circular data dependency in list iteration, or last fetch threw exception");
}
- if (i0.islist && flat) {
+ if (i0.List && flat) {
iter[0] = null;
iter.Shift_UnshiftD(i0.Fetch().mo.mro_raw_iterator.Get(i0));
continue;
@@ -5470,7 +5493,7 @@ internal class MMDCandidate : MultiCandidate {
}
public static Variable GetFirst(Variable lst) {
- if (!lst.islist) {
+ if (!lst.List) {
return lst;
}
P6opaque dyl = lst.Fetch() as P6opaque;
@@ -5504,8 +5527,8 @@ internal class MMDCandidate : MultiCandidate {
}
public static Variable StashyMerge(Variable o, Variable n, string d1, string d2) {
- if (n.rw || n.islist) return o;
- if (o.rw || o.islist) return n;
+ if (n.Mode != Variable.RO) return o;
+ if (o.Mode != Variable.RO) return n;
P6any oo = o.Fetch();
P6any nn = n.Fetch();
@@ -5640,7 +5663,7 @@ internal class MMDCandidate : MultiCandidate {
npos, n);
} else if (index == null) {
// TODO: handle adverbs on Zen slices (XXX does this make sense?)
- res = self.islist ? self : Kernel.NewRWListVar(self.Fetch());
+ res = self.List ? self : Kernel.NewRWListVar(self.Fetch());
} else if (n == null) {
res = ((IndexHandler)p[0]).Get(self, index);
} else if (p[1] != null && n.ContainsKey("exists")) {
View
6 lib/NieczaCLR.cs
@@ -247,8 +247,6 @@ sealed class PropertyProxy : Variable {
object[] argv;
public PropertyProxy(PropertyInfo prop, object obj, object[] argv) {
- this.rw = true; // make sure Fetch is called repeatedly
- this.islist = false;
this.prop = prop;
this.obj = obj;
this.argv = argv;
@@ -286,8 +284,6 @@ sealed class FieldProxy : Variable {
object obj;
public FieldProxy(FieldInfo field, object obj) {
- this.rw = true; // make sure Fetch is called repeatedly
- this.islist = false;
this.field = field;
this.obj = obj;
}
@@ -411,7 +407,7 @@ class OverloadCandidate : MultiCandidate {
object dummy;
for (int i = 0; i < args.Length; i++)
if (!CLRWrapperProvider.CoerceArgument(out dummy, args[i], pos[i+1])
- || (refs[i] && !pos[i+1].rw))
+ || (refs[i] && !pos[i+1].Rw))
return false;
// XXX: maybe param arrays should be treated as slurpies?
for (int i = args.Length; i < pos.Length - 1; i++)
Please sign in to comment.
Something went wrong with that request. Please try again.