Skip to content

Commit

Permalink
Refactor anomalous interpolation of Nil
Browse files Browse the repository at this point in the history
  • Loading branch information
sorear committed May 27, 2012
1 parent 51f3253 commit 8af7893
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 18 deletions.
4 changes: 2 additions & 2 deletions lib/CodeGen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4375,8 +4375,8 @@ public static object type_create(object[] args) {
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)
Expand Down
4 changes: 2 additions & 2 deletions lib/Cursor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ Frame scalar_common(bool eval, Frame th, Variable var) {
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;
}
Expand Down Expand Up @@ -959,7 +959,7 @@ public Variable SimpleWS() {
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)
Expand Down
22 changes: 13 additions & 9 deletions lib/Kernel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1489,10 +1489,14 @@ internal override void DoFreeze(FreezeBuffer fb) {
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);
Expand Down Expand Up @@ -4841,6 +4845,7 @@ internal static void InitCompartment() {
[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;
Expand Down Expand Up @@ -5186,7 +5191,7 @@ public static Variable BoxAnyMO<T>(T v, STable proto) {
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);
}

Expand Down Expand Up @@ -5240,7 +5245,7 @@ public static Variable NewTypedScalar(STable t) {
return new SimpleVariable(t, null, t.initObj);
}

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

Expand Down Expand Up @@ -6165,8 +6170,8 @@ internal static void CreateBasicTypes() {
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>(""));
Expand Down Expand Up @@ -6493,8 +6498,7 @@ public static Frame Unwind(Frame th, int type, Frame tf, int tip,
} 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();
}
Expand Down Expand Up @@ -6535,7 +6539,7 @@ public static Frame Unwind(Frame th, int type, Frame tf, int tip,
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;
Expand Down
4 changes: 2 additions & 2 deletions lib/NieczaCLR.cs
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ static Frame dispose_handler(Frame th) {
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;
}

Expand Down Expand Up @@ -772,7 +772,7 @@ Dictionary<string,List<MultiCandidate>> allMembers

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))
Expand Down
4 changes: 2 additions & 2 deletions lib/Perl5Interpreter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ public static string UnmarshalString(IntPtr sv) {
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) {
Expand Down
2 changes: 1 addition & 1 deletion lib/Serialize.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 8af7893

Please sign in to comment.