Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add a place in the return sequence to hook in LEAVE.
  • Loading branch information
sorear committed Aug 3, 2011
1 parent f727731 commit 695339a
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 31 deletions.
8 changes: 4 additions & 4 deletions lib/Builtins.cs
Expand Up @@ -1747,7 +1747,7 @@ class CrossSource: ItemSource {
lst.slots[1] = new VarDeque(Kernel.NewROScalar(thunk));
th.caller.resultSlot = Kernel.NewRWListVar(lst);
th.lexi0 = 1;
return th.caller;
return th.Return();
}
if (pen == null) {
if (tailmode != 0)
Expand All @@ -1756,7 +1756,7 @@ class CrossSource: ItemSource {
lst.slots[0] = outq;
lst.slots[1] = new VarDeque();
th.caller.resultSlot = Kernel.NewRWListVar(lst);
return th.caller;
return th.Return();
}
th.lex3 = pen;
th.ip = 1;
Expand Down Expand Up @@ -1878,7 +1878,7 @@ class CrossSource: ItemSource {
lst.slots[1] = new VarDeque(Kernel.NewROScalar(thunk));
th.caller.resultSlot = Kernel.NewRWListVar(lst);
th.lexi0 = 1;
return th.caller;
return th.Return();
}
}
pen = src.Shift();
Expand All @@ -1890,7 +1890,7 @@ class CrossSource: ItemSource {
lst.slots[0] = outq;
lst.slots[1] = new VarDeque();
th.caller.resultSlot = Kernel.NewRWListVar(lst);
return th.caller;
return th.Return();
}
th.lex3 = pen;
th.ip = 1;
Expand Down
4 changes: 3 additions & 1 deletion lib/CLRBackend.cs
Expand Up @@ -1469,6 +1469,8 @@ sealed class Tokens {
RuntimeUnit.GetMethod("LoadLAD");
public static readonly MethodInfo RU_LoadLADArr =
RuntimeUnit.GetMethod("LoadLADArr");
public static readonly MethodInfo Frame_Return =
Frame.GetMethod("Return");

public static readonly FieldInfo P6any_mo =
P6any.GetField("mo");
Expand Down Expand Up @@ -2420,7 +2422,7 @@ class ClrCpsReturn : ClrOp {
cx.il.Emit(OpCodes.Stfld, Tokens.Frame_resultSlot);
}
cx.il.Emit(OpCodes.Ldarg_0);
cx.il.Emit(OpCodes.Ldfld, Tokens.Frame_caller);
cx.il.Emit(OpCodes.Call, Tokens.Frame_Return);
cx.il.Emit(OpCodes.Ret);
}
}
Expand Down
6 changes: 3 additions & 3 deletions lib/Cursor.cs
Expand Up @@ -201,7 +201,7 @@ public sealed class RxFrame {
th.caller.resultSlot = EmptyList;
}

return th.caller;
return th.Return();
} else {
th.ip = bt.ip;
st = bt.st;
Expand Down Expand Up @@ -476,7 +476,7 @@ public sealed class RxFrame {
if (st.pos > global.highwater)
global.IncHighwater(st.pos);
th.caller.resultSlot = Kernel.NewROScalar(_matchObj);
return th.caller;
return th.Return();
}
public Frame End(Frame th) {
return EndWith(th, _matchObj);
Expand Down Expand Up @@ -504,7 +504,7 @@ public sealed class RxFrame {
lst.slots[1 /*rest*/ ] = iss;
th.caller.resultSlot = Kernel.NewRWListVar(lst);
}
return th.caller;
return th.Return();
}
}

Expand Down
28 changes: 16 additions & 12 deletions lib/Kernel.cs
Expand Up @@ -1172,7 +1172,7 @@ public class SubInfo {
else
th.pos[th.lexi0] = (Variable)th.lex9;
th.caller.resultSlot = Kernel.NewROScalar(nj);
return th.caller;
return th.Return();
}

if (th.lexi0 == -2)
Expand Down Expand Up @@ -1504,6 +1504,10 @@ public class Frame: P6any {
while (spacey.Count <= ix) { spacey.Add(new String(' ', spacey.Count * 2)); }
return spacey[ix];
}

public Frame Return() {
return caller;
}
}

public class NieczaException: Exception {
Expand Down Expand Up @@ -2941,7 +2945,7 @@ public class Kernel {
post = new Variable[th.pos.Length - 1];
Array.Copy(th.pos, 1, post, 0, th.pos.Length - 1);
return CodeMO.mro_INVOKE.Invoke((P6opaque)th.pos[0].Fetch(),
th.caller, post, th.named);
th.Return(), post, th.named);
}

private static SubInfo JunctionFallbackSI = new SubInfo("Junction.FALLBACK", JunctionFallbackC);
Expand All @@ -2968,7 +2972,7 @@ public class Kernel {
nj.slots[0] = th.lex2;
nj.slots[1] = Kernel.BoxRaw(dst, Kernel.ParcelMO);
th.caller.resultSlot = Kernel.NewROScalar(nj);
return th.caller;
return th.Return();
}

Variable[] npos = (Variable[]) th.lex4;
Expand Down Expand Up @@ -3308,7 +3312,7 @@ public class MMDCandidateLongname {
if (root == null)
return Kernel.Die(th, "No matching candidates to dispatch for " + dth.info.name);

if (tailcall) th = th.caller;
if (tailcall) th = th.Return();
return root.info.Binder(th, root.outer, root.ip6,
dth.pos, dth.named, false, root);
}
Expand Down Expand Up @@ -3537,7 +3541,7 @@ public class MMDCandidateLongname {

again: if (i == prog.Length) {
th.caller.resultSlot = NewROScalar(n);
return th.caller;
return th.Return();
}

Variable vx;
Expand Down Expand Up @@ -3806,7 +3810,7 @@ public class MMDCandidateLongname {
ContextHandler<Variable> cv, object cvb, object cvu) {
DynBlockDelegate dbd = delegate (Frame th) {
th.caller.resultSlot = cv.Get((Variable)th.lex0);
return th.caller;
return th.Return();
};
SubInfo si = new SubInfo("KERNEL " + kl.name + "." + name, dbd);
si.sig_i = new int[3] {
Expand All @@ -3823,7 +3827,7 @@ public class MMDCandidateLongname {
DynBlockDelegate dbd = delegate (Frame th) {
th.caller.resultSlot = cv.Get((Variable)th.lex0,
(Variable)th.lex1);
return th.caller;
return th.Return();
};
SubInfo si = new SubInfo("KERNEL " + kl.name + "." + name, dbd);
si.sig_i = new int[6] {
Expand All @@ -3843,7 +3847,7 @@ public class MMDCandidateLongname {
Variable[] chop = new Variable[fullpc.Length - 1];
Array.Copy(fullpc, 1, chop, 0, chop.Length);
th.caller.resultSlot = cv.Invoke((Variable)th.lex0, chop);
return th.caller;
return th.Return();
};
SubInfo si = new SubInfo("KERNEL " + kl.name + "." + name, dbd);
si.sig_i = new int[6] {
Expand Down Expand Up @@ -3883,7 +3887,7 @@ public class MMDCandidateLongname {
DynBlockDelegate dbd = delegate (Frame th) {
th.caller.resultSlot = DispIndexy(at, exist, del, bind,
th.named, (Variable)th.lex0, (Variable)th.lex1);
return th.caller;
return th.Return();
};

SubInfo si = new SubInfo("KERNEL " + kl.name + "." + name, dbd);
Expand Down Expand Up @@ -3941,7 +3945,7 @@ public class MMDCandidateLongname {
}
if (!cache_ok) {
return ((STable) th.lex0).mo.roleFactory.
Invoke(th.caller, to_pass, null);
Invoke(th.Return(), to_pass, null);
}
th.lex1 = s;
bool ok;
Expand All @@ -3951,7 +3955,7 @@ public class MMDCandidateLongname {
TryGetValue((string) th.lex1, out r);
if (ok) {
th.caller.resultSlot = NewROScalar(r);
return th.caller;
return th.Return();
}
th.ip = 1;
return ((STable) th.lex0).mo.roleFactory.
Expand All @@ -3963,7 +3967,7 @@ public class MMDCandidateLongname {
= ((Variable) th.resultSlot).Fetch();
}
th.caller.resultSlot = th.resultSlot;
return th.caller;
return th.Return();
default:
return Die(th, "Invalid IP");
}
Expand Down
13 changes: 2 additions & 11 deletions perf/std-20110528.pl6
Expand Up @@ -16,14 +16,5 @@ sub bench($name, $nr, $f) {
say "$name = {($time - $avg)*1e6}µs [{$time*$nr}s / $nr]";
}

"foo" ~~ /./;

my $f1 = sub () { $/ };
my $f2 = sub () { };
my $f3 = { $/ };
my $f4 = {; };

bench 'use $/ (sub)', 1000000, sub () { $f1() };
bench 'baseline (sub)', 1000000, sub () { $f2() };
bench 'use $/ (block)', 1000000, sub () { $f3() };
bench 'baseline (block)', 1000000, sub () { $f4() };
my $f = sub () { };
bench 'sub call', 1000000, sub () { $f() };

0 comments on commit 695339a

Please sign in to comment.