Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
When constant folding multis, call the dispatcher, not the proto. :)
  • Loading branch information
sorear committed May 26, 2012
1 parent 877296d commit 75abc9a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
9 changes: 6 additions & 3 deletions lib/CodeGen.cs
Expand Up @@ -3856,7 +3856,7 @@ public class DowncallReceiver : CallReceiver {
return false;
}
public static object unit_constant_fold(object[] args) {
var callee = (SubInfo)Handle.Unbox(args[2]);
var callee = Handle.Unbox(args[2]);
var pos = new List<Variable>();
var nam = new VarHash();

Expand All @@ -3877,7 +3877,9 @@ public class DowncallReceiver : CallReceiver {

object r = null;
try {
r = Handle.Wrap(Kernel.RunInferior(callee.protosub.Invoke(
P6any tocall = (callee is Variable) ?
((Variable)callee).Fetch() : ((SubInfo)callee).protosub;
r = Handle.Wrap(Kernel.RunInferior(tocall.Invoke(
Kernel.GetInferiorRoot(), pos.ToArray(), nam)));
} catch (Exception ex) {
r = ex.ToString();
Expand Down Expand Up @@ -4057,7 +4059,8 @@ public class DowncallReceiver : CallReceiver {
r = new object[] { "simple",null,null,null, lsimp.flags, Handle.Wrap(lsimp.type) };
var ldisp = li as LIDispatch;
if (ldisp != null)
r = new object[] { "dispatch",null,null,null, Handle.Wrap(csr) };
r = new object[] { "dispatch",null,null,null, Handle.Wrap(csr),
Handle.Wrap(ldisp.Get(csr.protopad)) };
var llab = li as LILabel;
if (llab != null)
r = new object[] { "label",null,null,null };
Expand Down
6 changes: 5 additions & 1 deletion src/NieczaPassSimplifier.pm6
Expand Up @@ -179,7 +179,11 @@ sub run_optree($body, $op, $nv) {
return $op unless @inv_lex[0] eq 'sub';

if @inv_lex[4].get_extend('pure') {
if check_folding($body, @inv_lex[4], $op) -> $nop { return $nop }
# note, we have to use the real dispatcher here! don't look past it
# to the proto
my @real_lex = $body.lookup_lex($invname);
my $sub = @real_lex[0] eq 'sub' ?? @real_lex[4] !! @real_lex[5];
if check_folding($body, $sub, $op) -> $nop { return $nop }
}

if @inv_lex[4].get_extend('builtin') -> $B {
Expand Down

0 comments on commit 75abc9a

Please sign in to comment.