Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Replace virtual method calls with type checks
  • Loading branch information
sorear committed May 27, 2012
1 parent 16054c7 commit 9852003
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
21 changes: 9 additions & 12 deletions lib/Kernel.cs
Expand Up @@ -62,9 +62,9 @@ public abstract class Variable : IFreeze {
public const int RW = 1;
public const int LIST = 2;

public virtual int Mode { get { return RW; } }
public bool Rw { get { return Mode == RW; } }
public bool List { get { return Mode == LIST; } }
public virtual int Mode { get { return (this is ListVariable) ? LIST : (this is P6any) ? RO : RW; } }
public bool Rw { get { return !(this is P6any); } }
public bool List { get { return this is ListVariable; } }
public virtual void Vivify() { }
public virtual Variable Assign(Variable inp) {
Store(inp.Fetch());
Expand Down Expand Up @@ -214,7 +214,6 @@ public class NewArrayViviHook : ViviHook {

public sealed class ListVariable: Variable {
P6any val;
public override int Mode { get { return LIST; } }

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

Expand Down Expand Up @@ -277,7 +276,6 @@ public sealed class RWVariable: Variable {
val = v;
}

public override int Mode { get { return RW; } }
public override void Vivify() {
ViviHook w = whence;
whence = null;
Expand Down Expand Up @@ -867,7 +865,7 @@ public sealed class RuntimeUnit : IFreeze {
}

static bool IsEmptyAggr(Variable v) {
if (v.Mode != Variable.LIST) return false;
if (!v.List) return false;
P6any p = v.Fetch();
if (p.mo == Kernel.ArrayMO) {
return ((VarDeque)p.GetSlot(Kernel.ListMO, "$!items")).Count() == 0 &&
Expand Down Expand Up @@ -3226,7 +3224,7 @@ class IxParcelLISTSTORE : IndexHandler {

for (int i = 0; i < dsts.Length; i++) {
Variable d = dsts[i];
if (d.Mode == Variable.LIST) {
if (d.List) {
srcs[i] = new P6opaque(Kernel.ListMO);
Kernel.IterToList(srcs[i], src);
src = new VarDeque();
Expand Down Expand Up @@ -5505,12 +5503,11 @@ internal class MMDCandidate : MultiCandidate {
}

public static Variable StashyMerge(Variable o, Variable n, string d1, string d2) {
if (n.Mode != Variable.RO) return o;
if (o.Mode != Variable.RO) return n;

P6any oo = o.Fetch();
P6any nn = n.Fetch();
P6any oo = o as P6any;
P6any nn = n as P6any;

if (oo == null) return n;
if (nn == null) return o;
if (oo == nn) return o;

if (!oo.IsDefined() && !nn.IsDefined() && oo.mo.who == nn.mo.who) {
Expand Down
1 change: 0 additions & 1 deletion lib/ObjModel.cs
Expand Up @@ -12,7 +12,6 @@ public abstract class P6any: Variable, IFreeze {
throw new NieczaException("Writing to readonly scalar");
}
public override Variable GetVar() { return this; }
public override int Mode { get { return RO; } }

public virtual object GetSlot(STable type, string name) {
throw new NieczaException("Representation " + ReprName() + " does not support attributes");
Expand Down

0 comments on commit 9852003

Please sign in to comment.