Skip to content
Permalink
Browse files

Split ListVariable out of SimpleVariable

  • Loading branch information...
sorear committed May 27, 2012
1 parent 0750bf7 commit 40e177962d44dcf956985780d32c228cbba085a1
Showing with 71 additions and 100 deletions.
  1. +0 −7 lib/Builtins.cs
  2. +1 −1 lib/CodeGen.cs
  3. +58 −68 lib/Kernel.cs
  4. +0 −7 lib/NieczaCLR.cs
  5. +2 −2 lib/ObjModel.cs
  6. +0 −4 lib/Perl5Interpreter.cs
  7. +10 −11 lib/Serialize.cs
@@ -156,9 +156,6 @@ class SubstrLValue: Variable {
backing.Store(Kernel.BoxRaw<string>(lfr + mfr + rfr, Kernel.StrMO));
}

public override Variable GetVar() {
return Kernel.BoxAnyMO<Variable>(this, Kernel.ScalarMO);
}
public override void Freeze(Niecza.Serialization.FreezeBuffer fb) {
fb.Byte((byte)Niecza.Serialization.SerializationCode.SubstrLValue);
fb.ObjRef(backing);
@@ -2774,10 +2771,6 @@ public class Blackhole : Variable {
public override P6any Fetch() { return value; }
public override void Store(P6any v) { }

public override Variable GetVar() {
return Kernel.BoxAnyMO<Variable>(this, Kernel.ScalarMO);
}

public override void Freeze(Niecza.Serialization.FreezeBuffer fb) {
fb.Byte((byte)Niecza.Serialization.SerializationCode.Blackhole);
fb.ObjRef(value);
@@ -316,7 +316,7 @@ sealed class Tokens {
public static readonly ConstructorInfo RxFrame_ctor =
RxFrame.GetConstructor(new Type[] { String, Cursor, Boolean });
public static readonly ConstructorInfo SV_ctor =
typeof(SimpleVariable).GetConstructor(new Type[] {
typeof(RWVariable).GetConstructor(new Type[] {
STable, typeof(ViviHook), P6any });
public static readonly ConstructorInfo SubViviHook_ctor =
typeof(SubViviHook).GetConstructor(new Type[] { P6any });
@@ -78,7 +78,9 @@ public abstract class Variable : IFreeze {
public abstract P6any Fetch();
public abstract void Store(P6any v);

public abstract Variable GetVar();
public virtual Variable GetVar() {
return Kernel.BoxAnyMO<Variable>(this, Kernel.ScalarMO);
}

public abstract void Freeze(FreezeBuffer fb);

@@ -210,43 +212,57 @@ public class NewArrayViviHook : ViviHook {
}
}

[StructLayout(LayoutKind.Sequential, Pack = 1)]
public sealed class SimpleVariable: Variable {
public sealed class ListVariable: Variable {
P6any val;
public override int Mode { get { return LIST; } }

public ListVariable(P6any val) { this.val = val; }

public override P6any Fetch() { return val; }
public override Variable Assign(Variable inp) {
val.mo.mro_LISTSTORE.Get(this, inp);
return this;
}
public override Variable AssignO(P6any inp, bool listishly) {
val.mo.mro_LISTSTORE.Get(this, listishly ?
(Variable)new ListVariable(inp) : inp);
return this;
}
public override void Store(P6any v) {
throw new NieczaException("Writing to readonly scalar");
}
public override void Freeze(FreezeBuffer fb) {
fb.Byte((byte)SerializationCode.ListVariable);
fb.ObjRef(val);
}
internal static ListVariable Thaw(ThawBuffer tb) {
ListVariable n = new ListVariable(null);
tb.Register(n);
n.val = (P6any) tb.ObjRef();
return n;
}
}

public sealed class RWVariable: Variable {
STable type; // null for Any/Mu variables, and roish
P6any val;
ViviHook whence;
int mode;

private SimpleVariable() { }
public SimpleVariable(STable type, ViviHook whence, P6any val) {
public RWVariable(STable type, ViviHook whence, P6any val) {
this.val = val; this.whence = whence;
this.type = type;
mode = RW;
}
public SimpleVariable(P6any val) { this.mode = LIST; 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());
}
Store(inp.Fetch());
return this;
}
public override Variable AssignO(P6any inp, bool listishly) {
if (mode == LIST) {
val.mo.mro_LISTSTORE.Get(this, listishly ?
(Variable)new SimpleVariable(inp) : inp);
} else {
Store(inp);
}
Store(inp);
return this;
}
public override void Store(P6any v) {
if (mode != RW) {
throw new NieczaException("Writing to readonly scalar");
}
if (v == Kernel.NilP) {
v = type == null ? Kernel.AnyP : type.initObj;
}
@@ -261,50 +277,27 @@ public sealed class SimpleVariable: Variable {
val = v;
}

public override Variable GetVar() {
return Kernel.BoxAnyMO<Variable>(this, Kernel.ScalarMO);
}

public override int Mode { get { return mode; } }
public override int Mode { get { return RW; } }
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;
const int S_VIV = 3;

public override void Freeze(FreezeBuffer fb) {
int code = ((int)SerializationCode.SimpleVariable) +
(mode == LIST ? S_LIST : mode == RO ? S_RO : whence == null ? S_RW : S_VIV);
int code = ((int)SerializationCode.RWVariable) +
(whence != null ? 1 : 0);
fb.Byte((byte)code);

if (whence != null) fb.ObjRef(whence);
if (mode == RW) fb.ObjRef(type);
fb.ObjRef(type);
fb.ObjRef(val);
}
internal static SimpleVariable Thaw(ThawBuffer tb, int subcode) {
SimpleVariable n = new SimpleVariable();
internal static RWVariable Thaw(ThawBuffer tb, int subcode) {
RWVariable n = new RWVariable(null, null, null);
tb.Register(n);
switch (subcode) {
default: throw new ArgumentException(subcode.ToString());
case S_RO:
// rw = false islist = false whence = null type = null
break;
case S_LIST:
n.mode = LIST;
break;
case S_VIV:
n.whence = (ViviHook) tb.ObjRef();
goto case S_RW;
case S_RW:
n.mode = RW;
n.type = (STable) tb.ObjRef();
break;
}
if (subcode != 0) n.whence = (ViviHook) tb.ObjRef();
n.type = (STable) tb.ObjRef();
n.val = (P6any) tb.ObjRef();
return n;
}
@@ -343,9 +336,6 @@ public sealed class TiedVariable: Variable {
whence = null;
if (w != null) w.Do(this);
}
public override Variable GetVar() {
return Kernel.BoxAnyMO<Variable>(this, Kernel.ScalarMO);
}
public override void Freeze(FreezeBuffer fb) {
fb.Byte((byte)SerializationCode.TiedVariable);
fb.ObjRef(fetch);
@@ -2835,7 +2825,7 @@ public class Frame: P6any, IFixup {
else {
if (src.Mode == (islist ? Variable.LIST : Variable.RO))
goto bound;
src = islist ? (Variable)new SimpleVariable(srco) : srco;
src = islist ? (Variable)new ListVariable(srco) : srco;
}
bound: ;
}
@@ -4043,7 +4033,7 @@ class IxHashAtKey : IndexHandler {
Variable r;
if (h.TryGetValue(kss, out r))
return r;
return new SimpleVariable(null, new HashViviHook(os, kss),
return new RWVariable(null, new HashViviHook(os, kss),
Kernel.AnyP);
}
}
@@ -4115,8 +4105,8 @@ class IxListAtPos : IndexHandler {
return Kernel.AnyP;
if (items.Count() <= ix) {
if (extend) {
return new SimpleVariable(null,
new ArrayViviHook(os, ix), Kernel.AnyP);
return new RWVariable(null, new ArrayViviHook(os, ix),
Kernel.AnyP);
} else {
return Kernel.AnyP;
}
@@ -4841,7 +4831,7 @@ public class Kernel {
[CORESaved] public static STable GatherIteratorMO;
[CORESaved] public static STable IterCursorMO;
[CORESaved] public static P6any NilP;
[CORESaved] public static SimpleVariable Nil;
[CORESaved] public static ListVariable Nil;
[CORESaved] public static P6any AnyP;
[CORESaved] public static P6any ArrayP;
[CORESaved] public static P6any EMPTYP;
@@ -5219,30 +5209,30 @@ internal class MMDCandidate : MultiCandidate {
if (omode == (islist ? Variable.LIST : Variable.RO))
return rhs;

return islist ? (Variable)new SimpleVariable(rhso) : rhso;
return islist ? (Variable)new ListVariable(rhso) : rhso;
}

public static Variable Assign(Variable lhs, Variable rhs) {
return lhs.Assign(rhs);
}

public static Variable NewRWScalar(STable t, P6any obj) {
return new SimpleVariable(t, null, obj);
return new RWVariable(t, null, obj);
}

public static Variable NewMuScalar(P6any obj) {
return new SimpleVariable(null, null, obj);
return new RWVariable(null, null, obj);
}

public static Variable NewTypedScalar(STable t) {
if (t == null)
return new SimpleVariable(null, null, AnyMO.typeObj);
return new RWVariable(null, null, AnyMO.typeObj);

return new SimpleVariable(t, null, t.initObj);
return new RWVariable(t, null, t.initObj);
}

public static SimpleVariable NewRWListVar(P6any container) {
return new SimpleVariable(container);
public static ListVariable NewRWListVar(P6any container) {
return new ListVariable(container);
}

public static VarDeque SlurpyHelper(Variable[] pos, int from) {
@@ -272,10 +272,6 @@ sealed class PropertyProxy : Variable {
mi.Invoke(obj, argv_);
}

public override Variable GetVar() {
return Kernel.BoxAnyMO<Variable>(this, Kernel.ScalarMO);
}

public override void Freeze(Niecza.Serialization.FreezeBuffer fb) { throw new NotImplementedException(); }
}

@@ -302,9 +298,6 @@ sealed class FieldProxy : Variable {
field.SetValue(obj, clr);
}

public override Variable GetVar() {
return Kernel.BoxAnyMO<Variable>(this, Kernel.ScalarMO);
}
public override void Freeze(Niecza.Serialization.FreezeBuffer fb) { throw new NotImplementedException(); }
}

@@ -112,12 +112,12 @@ public abstract class IndexHandler : ReflectObj {
}

public static Variable ViviHash(Variable obj, Variable key) {
return new SimpleVariable(Kernel.MuMO,
return new RWVariable(Kernel.MuMO,
new NewHashViviHook(obj, key.Fetch().mo.mro_raw_Str.Get(key)),
Kernel.AnyP);
}
public static Variable ViviArray(Variable obj, Variable key) {
return new SimpleVariable(Kernel.MuMO,
return new RWVariable(Kernel.MuMO,
new NewArrayViviHook(obj, (int)key.Fetch().mo.mro_raw_Numeric.Get(key)),
Kernel.AnyP);
}
@@ -150,10 +150,6 @@ public class SVVariable : Variable {
return new SVany(sv);
}
public override void Store(P6any v) {
}
public override Variable GetVar() {
return Kernel.BoxAnyMO<Variable>(this, Kernel.ScalarMO);

}
public override void Freeze(FreezeBuffer fb) {
throw new NieczaException("Freezing perl5 SV* NYI.");
@@ -70,7 +70,7 @@ struct ObjRef {
new Dictionary<string,Dictionary<string,MethodInfo>>();

static readonly string signature = "Niecza-Serialized-Module";
static readonly int version = 28;
static readonly int version = 29;

// Routines for use by serialization code
public bool CheckWriteObject(SerUnit into, object o,
@@ -271,10 +271,9 @@ enum SerializationCode : byte {
Type,

// variables
SimpleVariable, // allow 4 for flags
SimpleVariable_1,
SimpleVariable_2,
SimpleVariable_3,
RWVariable, // allow 2 for flag
RWVariable_1,
ListVariable,
SubstrLValue,
TiedVariable,
Blackhole,
@@ -770,12 +769,12 @@ class ThawBuffer {
case SerializationCode.Type:
return Register(Type.GetType(String(), true));

case SerializationCode.SimpleVariable:
case SerializationCode.SimpleVariable_1:
case SerializationCode.SimpleVariable_2:
case SerializationCode.SimpleVariable_3:
return SimpleVariable.Thaw(this,
(int)tag - (int)SerializationCode.SimpleVariable);
case SerializationCode.ListVariable:
return ListVariable.Thaw(this);
case SerializationCode.RWVariable:
case SerializationCode.RWVariable_1:
return RWVariable.Thaw(this,
(int)tag - (int)SerializationCode.RWVariable);
case SerializationCode.SubstrLValue:
return SubstrLValue.Thaw(this);
case SerializationCode.TiedVariable:

0 comments on commit 40e1779

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.