Skip to content

Commit

Permalink
Encapsulate variable property accessors
Browse files Browse the repository at this point in the history
  • Loading branch information
sorear committed May 27, 2012
1 parent 5d10b5f commit f1da062
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 117 deletions.
33 changes: 10 additions & 23 deletions lib/Builtins.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,6 @@ public SubstrLValue(Variable backing, int from, int length) {
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() {
Expand Down Expand Up @@ -278,15 +275,6 @@ public static Variable HandleSpecial3(Variable av0, Variable av1,
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)
Expand Down Expand Up @@ -1522,27 +1510,27 @@ public static Variable rat_approx(Variable v1, Variable v2) {

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;
}

Expand Down Expand Up @@ -1618,7 +1606,7 @@ public static Variable MakeJunction(int type, Variable[] elems) {
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);
Expand Down Expand Up @@ -1949,7 +1937,7 @@ public static Variable pair(Variable key, Variable value) {
}

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);
Expand Down Expand Up @@ -2036,7 +2024,7 @@ protected static int TryOne(VarDeque items, bool block) {
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;
Expand Down Expand Up @@ -2463,7 +2451,7 @@ public static Variable temporize(Variable v, Frame fr, int mode) {
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());
Expand Down Expand Up @@ -2701,7 +2689,7 @@ public static void EstablishSlot(P6any n, P6how.AttrInfo ai,
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);
}
Expand Down Expand Up @@ -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) { }
Expand All @@ -2802,7 +2790,6 @@ internal static object Thaw(Niecza.Serialization.ThawBuffer tb) {
var n = new Blackhole();
tb.Register(n);
n.value = (P6any) tb.ObjRef();
n.rw = true;
return n;
}
}
Expand Down
16 changes: 8 additions & 8 deletions lib/CodeGen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3063,8 +3063,8 @@ static 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");
Expand Down Expand Up @@ -3862,7 +3862,7 @@ public static object unit_constant_fold(object[] args) {

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 &&
Expand Down Expand Up @@ -4164,7 +4164,7 @@ public static object unit_rel_pkg(object[] args) {
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) {
Expand All @@ -4190,9 +4190,9 @@ public static object unit_list_stash(object[] args) {
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);
Expand All @@ -4207,9 +4207,9 @@ public static object unit_get(object[] args) {
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 {
Expand Down
2 changes: 1 addition & 1 deletion lib/Cursor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1642,7 +1642,7 @@ public string GetText(NFA pad) {

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));
Expand Down
2 changes: 1 addition & 1 deletion lib/JSYNC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ Variable GetFromHash() {
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();

Expand Down
Loading

0 comments on commit f1da062

Please sign in to comment.