Permalink
Browse files

Regularize Any/Mu variable handling

It turned out that 'type' was not a necessary part of the public
API.  Removing it simplified other things.  Also fixes coretest;
changes Nil to reset variables to Any default.
  • Loading branch information...
1 parent 853ca5d commit 9ceaa8e1cc0d44c385622348512efc89d831c767 @sorear committed Oct 27, 2011
Showing with 28 additions and 43 deletions.
  1. +1 −1 Makefile
  2. +0 −1 lib/Builtins.cs
  3. +2 −2 lib/CORE.setting
  4. +1 −2 lib/CodeGen.cs
  5. +19 −30 lib/Kernel.cs
  6. +0 −2 lib/NieczaCLR.cs
  7. +5 −5 test.pl
View
@@ -64,7 +64,7 @@ aot: all
test: all
$(RUN_CLR) run/Niecza.exe -c test.pl
- prove -e "$(RUN_CLR)" obj/MAIN.exe
+ prove -e "$(RUN_CLR)" obj/Run.MAIN.exe
spectest: all
@t/run_spectests
View
@@ -106,7 +106,6 @@ class SubstrLValue: Variable {
// XXX Should binding a substr lvalue count as binding the original?
this.whence = null;
this.rw = backing.rw;
- this.type = Kernel.StrMO;
}
public override P6any Fetch() {
View
@@ -1371,8 +1371,8 @@ sub first(Mu $test, *@bits) { @bits.first($test) }
sub _hash_constructor(\$parcel) { my $r := (anon %hash = $parcel); $r }
sub _make_capture(|$c) { $c }
-sub _newtiedscalar(Mu $type, $bind, $fetch, $store) {
- Q:CgOp { (var_new_tied (obj_llhow (@ {$type})) (@ {$bind}) (@ {$fetch}) (@ {$store})) }
+sub _newtiedscalar($bind, $fetch, $store) {
+ Q:CgOp { (var_new_tied (@ {$bind}) (@ {$fetch}) (@ {$store})) }
}
sub infix:<X>(\|$pcl) is Niecza::absprec<f=> is assoc<list> {
View
@@ -3136,7 +3136,7 @@ class NamProcessor {
thandlers["cross"] = Methody(Tokens.Variable, Tokens.Builtins.GetMethod("MECross"));
thandlers["zip"] = Methody(Tokens.Variable, Tokens.Builtins.GetMethod("MEZip"));
thandlers["var_get_var"] = Methody(null, Tokens.Variable.GetMethod("GetVar"));
- thandlers["var_new_tied"] = Constructy(typeof(TiedVariable).GetConstructor(new Type[] { Tokens.STable, Tokens.P6any, Tokens.P6any, Tokens.P6any }));
+ thandlers["var_new_tied"] = Constructy(typeof(TiedVariable).GetConstructor(new Type[] { Tokens.P6any, Tokens.P6any, Tokens.P6any }));
thandlers["obj_typename"] = Methody(null, Tokens.P6any.GetMethod("GetTypeName"));
thandlers["fetch"] = Methody(null, Tokens.Variable_Fetch);
thandlers["bget"] = FieldGet(Tokens.BValue, "v");
@@ -3862,7 +3862,6 @@ public class DowncallReceiver : CallReceiver {
ret.Add(kv.Key);
ret.Add(kv.Value.pos);
}
- s.used_in_scope = null;
return ret.ToArray();
} else if (cmd == "unit_stubbed_stashes") {
RuntimeUnit u = (RuntimeUnit)Handle.Unbox(args[1]);
View
@@ -60,7 +60,6 @@ public abstract class Variable : IFreeze {
public ViviHook whence;
// these should be treated as ro for the life of the variable
- public STable type;
public bool rw;
public bool islist;
@@ -199,24 +198,29 @@ public class NewArrayViviHook : ViviHook {
}
}
- public sealed class SimpleVariable: Variable, IFixup {
+ public sealed class SimpleVariable: Variable {
+ STable type; // null for Any/Mu variables, and roish
P6any val;
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;
}
+ public SimpleVariable(P6any val) { this.val = val; }
+ public SimpleVariable(bool islist, P6any val) {
+ this.islist = islist; this.val = val;
+ }
public override P6any Fetch() { return val; }
public override void Store(P6any v) {
if (!rw) {
throw new NieczaException("Writing to readonly scalar");
}
if (v == Kernel.NilP) {
- v = type.initObject;
+ v = type == null ? Kernel.AnyP : type.initObject;
}
- if (!v.Does(type)) {
+ 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");
}
if (whence != null) {
@@ -245,20 +249,15 @@ public sealed class SimpleVariable: Variable, IFixup {
if (rw) fb.ObjRef(type);
fb.ObjRef(val);
}
- void IFixup.Fixup() {
- type = val.mo;
- }
internal static SimpleVariable Thaw(ThawBuffer tb, int subcode) {
SimpleVariable n = new SimpleVariable();
tb.Register(n);
switch (subcode) {
default: throw new ArgumentException(subcode.ToString());
case S_RO:
// rw = false islist = false whence = null type = null
- tb.PushFixup(n);
break;
case S_LIST:
- tb.PushFixup(n);
n.islist = true;
break;
case S_VIV:
@@ -279,22 +278,17 @@ public sealed class TiedVariable: Variable {
P6any store;
private TiedVariable() { }
- public TiedVariable(STable type, P6any whsub, P6any fetch, P6any store) {
+ 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;
- this.type = type;
}
public override P6any Fetch() {
Variable vr = Kernel.RunInferior(fetch.Invoke(
Kernel.GetInferiorRoot(), None, null));
- P6any vl = vr.Fetch();
- if (!vl.Does(type))
- throw new NieczaException("Tied variable of type " + type +
- " returned value of type " + vl.mo.name + " instead");
- return vl;
+ return vr.Fetch();
}
public override void Store(P6any v) {
@@ -312,15 +306,13 @@ public sealed class TiedVariable: Variable {
}
public override void Freeze(FreezeBuffer fb) {
fb.Byte((byte)SerializationCode.TiedVariable);
- fb.ObjRef(type);
fb.ObjRef(fetch);
fb.ObjRef(store);
fb.ObjRef(whence);
}
internal static TiedVariable Thaw(ThawBuffer tb) {
TiedVariable n = new TiedVariable();
tb.Register(n);
- n.type = (STable) tb.ObjRef();
n.fetch = (P6any) tb.ObjRef();
n.store = (P6any) tb.ObjRef();
n.whence = (ViviHook) tb.ObjRef();
@@ -1598,8 +1590,7 @@ public class UsedInScopeInfo {
else {
if (!src.rw && islist == src.islist)
goto bound;
- src = new SimpleVariable(false, islist, srco.mo,
- null, srco);
+ src = new SimpleVariable(islist, srco);
}
bound: ;
}
@@ -3422,7 +3413,7 @@ class IxHashAtKey : IndexHandler {
Variable r;
if (h.TryGetValue(kss, out r))
return r;
- return new SimpleVariable(true, false, Kernel.MuMO,
+ return new SimpleVariable(true, false, null,
new HashViviHook(os, kss), Kernel.AnyP);
}
}
@@ -3492,7 +3483,7 @@ class IxListAtPos : IndexHandler {
return Kernel.AnyMO.typeVar;
if (items.Count() <= ix) {
if (extend) {
- return new SimpleVariable(true, false, Kernel.MuMO,
+ return new SimpleVariable(true, false, null,
new ArrayViviHook(os, ix), Kernel.AnyP);
} else {
return Kernel.AnyMO.typeVar;
@@ -4541,8 +4532,7 @@ public class MMDCandidateLongname {
public static Variable Decontainerize(Variable rhs) {
if (!rhs.rw) return rhs;
- P6any v = rhs.Fetch();
- return new SimpleVariable(false, rhs.islist, v.mo, null, v);
+ return new SimpleVariable(rhs.islist, rhs.Fetch());
}
public const int NBV_RO = 0;
@@ -4567,7 +4557,7 @@ public class MMDCandidateLongname {
if (!rhs.rw && islist == rhs.islist)
return rhs;
- return new SimpleVariable(false, islist, rhso.mo, null, rhso);
+ return new SimpleVariable(islist, rhso);
}
public static Variable Assign(Variable lhs, Variable rhs) {
@@ -4584,28 +4574,27 @@ public class MMDCandidateLongname {
// ro, not rebindable
public static Variable NewROScalar(P6any obj) {
- return new SimpleVariable(false, false, obj.mo, null, obj);
+ return new SimpleVariable(obj);
}
public static Variable NewRWScalar(STable t, P6any obj) {
return new SimpleVariable(true, false, t, null, obj);
}
public static Variable NewMuScalar(P6any obj) {
- return new SimpleVariable(true, false, MuMO, null, obj);
+ return new SimpleVariable(true, false, null, null, obj);
}
public static Variable NewTypedScalar(STable t) {
if (t == null)
- return new SimpleVariable(true, false, MuMO, null,
+ return new SimpleVariable(true, false, null, null,
AnyMO.typeObject);
return new SimpleVariable(true, false, t, null, t.initObject);
}
public static Variable NewRWListVar(P6any container) {
- return new SimpleVariable(false, true, container.mo, null,
- container);
+ return new SimpleVariable(true, container);
}
public static VarDeque SlurpyHelper(Frame th, int from) {
View
@@ -178,7 +178,6 @@ sealed class PropertyProxy : Variable {
object[] argv;
public PropertyProxy(PropertyInfo prop, object obj, object[] argv) {
- this.type = Kernel.AnyMO; // XXX because of coercion
this.rw = true; // make sure Fetch is called repeatedly
this.islist = false;
this.prop = prop;
@@ -218,7 +217,6 @@ sealed class FieldProxy : Variable {
object obj;
public FieldProxy(FieldInfo field, object obj) {
- this.type = Kernel.AnyMO; // XXX because of coercion
this.rw = true; // make sure Fetch is called repeatedly
this.islist = false;
this.field = field;
View
@@ -1829,7 +1829,7 @@
{
my $log = '';
my $ret = '';
- my $var := _newtiedscalar(Any, Any, { $log ~= "F"; $ret }, { $log ~= $_ });
+ my $var := _newtiedscalar(Any, { $log ~= "F"; $ret }, { $log ~= $_ });
$ret = 5; $log = "";
my $a = $var;
@@ -1841,19 +1841,19 @@
is $log, "9", "stores work";
$log = "";
- $a = _newtiedscalar(Any, { $log ~= "B" }, { Any }, { Any });
+ $a = _newtiedscalar({ $log ~= "B" }, { Any }, { Any });
is $log, "", "bind not called spuriously (1)";
$log = "";
- $a ::= _newtiedscalar(Any, { $log ~= "B" }, { Any }, { Any });
+ $a ::= _newtiedscalar({ $log ~= "B" }, { Any }, { Any });
is $log, "", "bind not called spuriously (2)";
$log = "";
- my $b := _newtiedscalar(Any, { $log ~= "B" }, { Any }, { Any }); #OK
+ my $b := _newtiedscalar({ $log ~= "B" }, { Any }, { Any }); #OK
is $log, "B", "bind called when needed (bind)";
$log = "";
- _newtiedscalar(Any, { $log ~= "B" }, { Any }, { Any }) = 5;
+ _newtiedscalar({ $log ~= "B" }, { Any }, { Any }) = 5;
is $log, "B", "bind called when needed (write)";
}

0 comments on commit 9ceaa8e

Please sign in to comment.