Permalink
Browse files

Separate responsibilities of NewTypedScalar / NewAnyMuScalar

  • Loading branch information...
1 parent a2d37f7 commit f2586f949786d1f27f9d5c4014f2dc626da11295 @sorear committed Nov 13, 2012
Showing with 20 additions and 13 deletions.
  1. +9 −3 lib/CodeGen.cs
  2. +11 −10 lib/Kernel.cs
View
12 lib/CodeGen.cs
@@ -373,6 +373,8 @@ sealed class Tokens {
typeof(Kernel).GetMethod("NewRWScalar");
public static readonly MethodInfo Kernel_NewTypedScalar =
typeof(Kernel).GetMethod("NewTypedScalar");
+ public static readonly MethodInfo Kernel_NewMuAnyScalar =
+ typeof(Kernel).GetMethod("NewMuAnyScalar");
public static readonly MethodInfo Kernel_Assign =
typeof(Kernel).GetMethod("Assign");
public static readonly MethodInfo Kernel_CreateArray =
@@ -2335,6 +2337,8 @@ class NamProcessor {
let.Add(new object[] { "newhash" });
else if ((li.flags & LISimple.LIST) != 0)
let.Add(new object[] { "newarray" });
+ else if (li.type == null)
+ let.Add(new object[] { "newblankrwscalar" });
else
let.Add(new object[] { "_newoftype",
eu.TypeConstant(li.type) });
@@ -2499,6 +2503,8 @@ class NamProcessor {
init = CpsOp.MethodCall(Tokens.Kernel_CreateHash);
} else if ((flags & Parameter.IS_LIST) != 0) {
init = CpsOp.MethodCall(Tokens.Kernel_CreateArray);
+ } else if (type == null) {
+ init = CpsOp.MethodCall(Tokens.Kernel_NewMuAnyScalar);
} else {
init = CpsOp.MethodCall(Tokens.Kernel_NewTypedScalar,
eu.TypeConstant(type));
@@ -2847,9 +2853,7 @@ class NamProcessor {
return CpsOp.MethodCall(Tokens.Kernel_NewTypedScalar,
(CpsOp)z[1]); };
thandlers["newblankrwscalar"] = delegate(CpsOp[] z) {
- return CpsOp.MethodCall(Tokens.Kernel_NewTypedScalar,
- CpsOp.Null(Tokens.STable)); };
- thandlers["newtypedscalar"] = Methody(null, Tokens.Kernel_NewTypedScalar);
+ return CpsOp.MethodCall(Tokens.Kernel_NewMuAnyScalar); };
// XXX - wrong order - problem?
thandlers["fvarlist_item"] = delegate(CpsOp[] z) {
return CpsOp.Operator(Tokens.Variable, OpCodes.Ldelem_Ref,
@@ -3298,6 +3302,8 @@ class NamProcessor {
} else if ((f & (LISimple.HASH | LISimple.LIST)) != 0) {
bit = a(j( ((f & LISimple.HASH) != 0) ?
"newhash" : "newarray" ));
+ } else if (ls.type == null) {
+ bit = a(j("newblankrwscalar"));
} else {
bit = a(j("_newoftype"), tc);
}
View
21 lib/Kernel.cs
@@ -165,7 +165,7 @@ public class ArrayViviHook : ViviHook {
public override void Do(Variable toviv) {
VarDeque vd = (VarDeque) ary.GetSlot(ary.mo.setting.ListMO, "$!items");
while (vd.Count() <= key)
- vd.Push(Kernel.NewTypedScalar(null));
+ vd.Push(Kernel.NewMuAnyScalar());
vd[key] = toviv;
}
public override void Freeze(FreezeBuffer fb) {
@@ -190,7 +190,7 @@ public class NewArrayViviHook : ViviHook {
public override void Do(Variable toviv) {
VarDeque vd = new VarDeque();
while (vd.Count() <= key)
- vd.Push(Kernel.NewTypedScalar(null));
+ vd.Push(Kernel.NewMuAnyScalar());
vd[key] = toviv;
P6opaque d = new P6opaque(mo);
d.slots[0] = vd;
@@ -1293,7 +1293,7 @@ public class LISimple : LIVarish {
else if ((flags & HASH) != 0)
Set(f, owner.setting.CreateHash());
else
- Set(f, Kernel.NewTypedScalar(type));
+ Set(f, type == null ? Kernel.NewMuAnyScalar() : Kernel.NewTypedScalar(type));
}
}
@@ -2778,7 +2778,7 @@ public class Frame: P6any, IFixup {
src = Kernel.Assign(setting.CreateArray(),
Kernel.NewRWListVar(src.Fetch()));
else
- src = Kernel.Assign(Kernel.NewTypedScalar(type), src);
+ src = Kernel.Assign(type == null ? Kernel.NewMuAnyScalar() : Kernel.NewTypedScalar(type), src);
} else {
bool islist = ((flags & (Parameter.IS_HASH | Parameter.IS_LIST)) != 0);
bool rw = ((flags & Parameter.READWRITE) != 0) && !islist;
@@ -4125,7 +4125,7 @@ class IxListBindPos : BindHandler {
if (ix < 0)
throw new NieczaException("binding to out of range slot " + ix);
while (items.Count() <= ix) {
- items.Push(Kernel.NewTypedScalar(null));
+ items.Push(Kernel.NewMuAnyScalar());
}
return items[ix] = to;
}
@@ -4704,7 +4704,7 @@ public class Compartment {
return CreateArray();
if (name.Length >= 1 && name[0] == '%')
return CreateHash();
- return Kernel.NewTypedScalar(null);
+ return Kernel.NewMuAnyScalar();
}
public static Variable StashyMerge(Variable o, Variable n, string d1, string d2) {
@@ -4738,7 +4738,7 @@ public class Compartment {
} else if (name.StartsWith("%")) {
v.v = CreateHash();
} else {
- v.v = Kernel.NewTypedScalar(null);
+ v.v = Kernel.NewMuAnyScalar();
}
return v;
@@ -5413,10 +5413,11 @@ internal class MMDCandidate : MultiCandidate {
return new RWVariable(null, null, obj);
}
- public static Variable NewTypedScalar(STable t) {
- if (t == null)
- return new RWVariable(null, null, Compartment.Top.AnyMO.typeObj);
+ public static Variable NewMuAnyScalar() {
+ return new RWVariable(null, null, Compartment.Top.AnyMO.typeObj);
+ }
+ public static Variable NewTypedScalar(STable t) {
return new RWVariable(t, null, t.initObj);
}

0 comments on commit f2586f9

Please sign in to comment.