From e289709269f9308b3b84f3c0787df3bc40932956 Mon Sep 17 00:00:00 2001 From: Stefan O'Rear Date: Tue, 23 Nov 2010 00:26:56 -0800 Subject: [PATCH] Fix optimized ++ not autovivifying --- lib/Builtins.cs | 15 ++++++++++++++- lib/Kernel.cs | 2 +- test2.pl | 3 +++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/Builtins.cs b/lib/Builtins.cs index 96378ff5..941a214d 100644 --- a/lib/Builtins.cs +++ b/lib/Builtins.cs @@ -3,6 +3,19 @@ using System.Collections.Generic; public class Builtins { + public static void AssignV(Variable lhs, IP6 rhs) { + if (lhs.whence == null && !lhs.islist) { + if (!lhs.rw) + throw new NieczaException("assigning to readonly value"); + + lhs.Store(rhs); + } else { + Frame n = new Frame(null, null, Kernel.ExitRunloopSI).MakeChild(null, Kernel.AssignSI); + n.pos = new Variable[2] { lhs, Kernel.NewROScalar(rhs) }; + Kernel.RunCore(n); + } + } + public static string LaxSubstring(string str, int from) { if (from <= 0) return str; @@ -33,7 +46,7 @@ public class Builtins { IP6 o1 = v.Fetch(); double d = o1.mo.mro_raw_defined.Get(v) ? o1.mo.mro_raw_Numeric.Get(v) : 0; - v.Store(Kernel.BoxRaw(d + 1, Kernel.NumMO)); + AssignV(v, Kernel.BoxRaw(d + 1, Kernel.NumMO)); return Kernel.NewROScalar(o1); } } diff --git a/lib/Kernel.cs b/lib/Kernel.cs index 89fe211f..cc2b6d32 100644 --- a/lib/Kernel.cs +++ b/lib/Kernel.cs @@ -963,7 +963,7 @@ public class Kernel { } // This isn't just a fetch and a store... - private static SubInfo AssignSI = new SubInfo("Assign", AssignC); + public static SubInfo AssignSI = new SubInfo("Assign", AssignC); private static Frame AssignC(Frame th) { switch (th.ip) { case 0: diff --git a/test2.pl b/test2.pl index feb0a0d6..9ef0606e 100644 --- a/test2.pl +++ b/test2.pl @@ -32,6 +32,9 @@ } ok G.parse("fOo"), ":i works"; + + my %h; %h++; + is %h, 1, "autoviv works with ++"; } #is $?FILE, 'test.pl', '$?FILE works';