Skip to content

Commit

Permalink
Refactor out args groups merging.
Browse files Browse the repository at this point in the history
  • Loading branch information
pmurias committed Sep 17, 2014
1 parent 1acca08 commit 20af910
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/vm/js/QAST/Compiler.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,21 @@ class QAST::OperationsJS {
});
add_simple_op('ishash', $T_INT, [$T_OBJ], sub ($obj) {"nqp.op.ishash($obj)"});

sub merge_arg_groups($groups) {
if nqp::islist($groups) {
my @exprs;

my @setup := [];

for $groups -> $group {
@exprs.push($group.expr);
@setup.push($group);
}

Chunk.new($T_NONVAL, @exprs.shift ~ '.concat(' ~ nqp::join(',', @exprs) ~ ')', $groups);
}
}

add_op('call', sub ($comp, $node, :$want) {
if $*BLOCK.is_local_lexotic($node.name) {
my $value := $comp.as_js($node[0], :want($T_OBJ));
Expand All @@ -399,14 +414,9 @@ class QAST::OperationsJS {

my $call;
if nqp::islist($compiled_args) {
my @exprs;
my @setup := [$callee];
for $compiled_args -> $group {
@exprs.push($group.expr);
@setup.push($group);
}
my $merged_args := merge_arg_groups($compiled_args);
$comp.stored_result(
Chunk.new($T_OBJ, "{$callee.expr}.apply(undefined,{@exprs.shift ~ '.concat(' ~ nqp::join(',', @exprs)}))" , @setup, :$node), :$want);
Chunk.new($T_OBJ, "{$callee.expr}.apply(undefined,{$merged_args.expr})" , [$callee, $merged_args], :$node), :$want);
} else {
$comp.stored_result(
Chunk.new($T_OBJ, "{$callee.expr}({$compiled_args.expr})" , [$callee, $compiled_args], :$node), :$want);
Expand Down

0 comments on commit 20af910

Please sign in to comment.