Skip to content

Commit

Permalink
Fix optimized ++ not autovivifying
Browse files Browse the repository at this point in the history
  • Loading branch information
sorear committed Nov 23, 2010
1 parent c67c2b0 commit e289709
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
15 changes: 14 additions & 1 deletion lib/Builtins.cs
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
2 changes: 1 addition & 1 deletion lib/Kernel.cs
Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions test2.pl
Expand Up @@ -32,6 +32,9 @@
}

ok G.parse("fOo"), ":i <sym> works";

my %h; %h<used>++;
is %h<used>, 1, "autoviv works with ++";
}

#is $?FILE, 'test.pl', '$?FILE works';
Expand Down

0 comments on commit e289709

Please sign in to comment.