Permalink
Browse files

Refactor anomalous interpolation of Nil

  • Loading branch information...
sorear committed May 27, 2012
1 parent 51f3253 commit 8af78932e403cdc973a4b72c7a7c14e4d78cd3c2
Showing with 22 additions and 18 deletions.
  1. +2 −2 lib/CodeGen.cs
  2. +2 −2 lib/Cursor.cs
  3. +13 −9 lib/Kernel.cs
  4. +2 −2 lib/NieczaCLR.cs
  5. +2 −2 lib/Perl5Interpreter.cs
  6. +1 −1 lib/Serialize.cs
View
@@ -4375,8 +4375,8 @@ public class DowncallReceiver : CallReceiver {
nst.typeVar = nst.typeObj;
if (ru.name == "CORE" && name == "Nil") {
- // this anomalous type object is iterable
- nst.typeVar = Kernel.NewRWListVar(nst.typeObj);
+ // anomalously requires an iterable value
+ Kernel.Nil = Kernel.NewRWListVar(nst.typeObj);
}
if (pf != null)
View
@@ -546,7 +546,7 @@ public sealed class RxFrame: IFreeze {
if (Exact(o.mo.mro_raw_Str.Get(var))) {
th.resultSlot = MakeCursorV();
} else {
- th.resultSlot = Kernel.NilP.mo.typeVar;
+ th.resultSlot = Kernel.Nil;
}
return th;
}
@@ -959,7 +959,7 @@ public Cursor(P6any proto, string text, P6any actions)
CC.Word.Accepts(backing[p-1])) {
if (Trace)
Console.WriteLine("! no match <ws> at {0}", pos);
- return Kernel.NilP.mo.typeVar;
+ return Kernel.Nil;
} else {
while (p != l && Char.IsWhiteSpace(backing, p)) { p++; }
if (Trace)
View
@@ -1489,10 +1489,14 @@ public class LIAttrAlias : LexInfo {
public class LIPackage : LexInfo {
public STable pkg;
public LIPackage(STable pkg) { this.pkg = pkg; }
- public override object Get(Frame f) { return pkg.typeVar; }
+ public override object Get(Frame f) {
+ return pkg == Kernel.NilP.mo ? Kernel.Nil : pkg.typeVar;
+ }
public override void Init(Frame f) { }
internal override ClrOp GetCode(int up) {
- return EmitUnit.Current.TypeConstantV(pkg).head;
+ return pkg == Kernel.NilP.mo ?
+ EmitUnit.Current.RefConstant("Nil", "L", Kernel.Nil, typeof(Variable)).head :
+ EmitUnit.Current.TypeConstantV(pkg).head;
}
internal override void DoFreeze(FreezeBuffer fb) {
fb.Byte((byte)LexSerCode.Package);
@@ -4841,6 +4845,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 P6any AnyP;
[CORESaved] public static P6any ArrayP;
[CORESaved] public static P6any EMPTYP;
@@ -5186,7 +5191,7 @@ internal class MMDCandidate : MultiCandidate {
return new BoxObject<T>(v, proto);
}
- public static P6any BoxRaw<T>(T v, STable proto) {
+ public static BoxObject<T> BoxRaw<T>(T v, STable proto) {
return new BoxObject<T>(v, proto);
}
@@ -5240,7 +5245,7 @@ internal class MMDCandidate : MultiCandidate {
return new SimpleVariable(t, null, t.initObj);
}
- public static Variable NewRWListVar(P6any container) {
+ public static SimpleVariable NewRWListVar(P6any container) {
return new SimpleVariable(container);
}
@@ -6165,8 +6170,8 @@ class LastFrameNode {
new STable[] { BoolMO });
TrueV = BoxRaw<int>(1, BoolMO);
FalseV = BoxRaw<int>(0, BoolMO);
- FalseV.Fetch().SetSlot(BoolMO, "$!index", BoxAnyMO(0, IntMO));
- TrueV.Fetch().SetSlot(BoolMO, "$!index", BoxAnyMO(1, IntMO));
+ FalseV.SetSlot(BoolMO, "$!index", BoxAnyMO(0, IntMO));
+ TrueV.SetSlot(BoolMO, "$!index", BoxAnyMO(1, IntMO));
Handler_Vonly(StrMO, "Str", new CtxReturnSelf(),
new CtxJustUnbox<string>(""));
@@ -6493,8 +6498,7 @@ class LastFrameNode {
} else {
if (csr.caller == null) Panic(csr.info.name + " has no caller?");
// TODO: catch generated exceptions and add to @!
- csr.caller.resultSlot = Kernel.NilP == null ? null :
- Kernel.NilP.mo.typeVar;
+ csr.caller.resultSlot = Kernel.Nil;
Kernel.SetTopFrame(csr);
csr = csr.Return();
}
@@ -6535,7 +6539,7 @@ class LastFrameNode {
if (tip < 0) {
// catch IP of -1 means to force an immediate return, as
// when a CATCH phaser is triggered.
- tf.caller.resultSlot = Kernel.NilP.mo.typeVar;
+ tf.caller.resultSlot = Kernel.Nil;
return tf.Return();
} else {
return tf;
View
@@ -638,7 +638,7 @@ public class CLRWrapperProvider {
if (th.ip == 0) { th.ip = 1; return Frame.Binder(th); }
object o = Kernel.UnboxAny<object>(((Variable)th.lex0).Fetch());
((IDisposable)o).Dispose();
- th.caller.resultSlot = Kernel.NilP.mo.typeVar;
+ th.caller.resultSlot = Kernel.Nil;
return th.caller;
}
@@ -772,7 +772,7 @@ public class CLRWrapperProvider {
public static Variable BoxResult(Type cty, object ret) {
if (cty == typeof(void))
- return Kernel.NewRWListVar(Kernel.NilP);
+ return Kernel.Nil;
if (cty == typeof(sbyte))
return Builtins.MakeInt((sbyte)ret);
if (cty == typeof(byte))
View
@@ -83,10 +83,10 @@ int argument_n
public static Variable SVToVariable(IntPtr sv) {
if (sv == IntPtr.Zero) {
//TODO: check - cargo culted
- return Kernel.NilP.mo.typeVar;
+ return Kernel.Nil;
}
if (SvOK(sv) == 0) {
- return Kernel.NilP.mo.typeVar;
+ return Kernel.Nil;
}
if (SvIOKp(sv) != 0) {
View
@@ -70,7 +70,7 @@ struct ObjRef {
new Dictionary<string,Dictionary<string,MethodInfo>>();
static readonly string signature = "Niecza-Serialized-Module";
- static readonly int version = 26;
+ static readonly int version = 27;
// Routines for use by serialization code
public bool CheckWriteObject(SerUnit into, object o,

0 comments on commit 8af7893

Please sign in to comment.