Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Pass test 39.
The pointy block to for can take multiple arguments.
  • Loading branch information
pmurias committed Dec 3, 2014
1 parent 5fc70e5 commit 74871a6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
24 changes: 18 additions & 6 deletions src/vm/js/QAST/Compiler.nqp
Expand Up @@ -670,6 +670,8 @@ class QAST::OperationsJS {
}

add_op('for', sub ($comp, $node, :$want) {
# TODO redo etc.

my $handler := 1;
my @operands;
my $label;
Expand All @@ -687,21 +689,27 @@ class QAST::OperationsJS {
}

my $iterator := $*BLOCK.add_tmp();
my $iterval := $*BLOCK.add_tmp();

my $list := $comp.as_js(@operands[0], :want($T_OBJ));

# TODO think if creating the block once, and the calling it multiple times would be faster

my @body_args;
my $arity := @operands[1].arity || 1;
while $arity > 0 {
my $iterval := $*BLOCK.add_tmp();
@body_args.push(Chunk.new($T_OBJ, $iterval, ["$iterval = $iterator.shift();\n"]));
$arity := $arity - 1;
}

my $outer := try $*BLOCK;
my $body := $comp.compile_block(@operands[1], $outer, :want($T_VOID), :arg($iterval));
my $body := $comp.compile_block(@operands[1], $outer, :want($T_VOID), :extra_args(@body_args));


Chunk.new($T_VOID, '', [
$list,
"$iterator = nqp.op.iterator({$list.expr});\n",
"while ($iterator.idx < $iterator.target) \{\n",
"$iterval = $iterator.shift();\n",
$body,
"\}\n"
], :node($node));
Expand Down Expand Up @@ -1287,7 +1295,7 @@ class QAST::CompilerJS does DWIMYNameMangling does SerializeOnce {
}
}

method compile_block(QAST::Block $node, $outer, :$want, :$arg='') {
method compile_block(QAST::Block $node, $outer, :$want, :@extra_args=[]) {
my $cuid := self.mangled_cuid($node.cuid);

my $setup;
Expand Down Expand Up @@ -1320,8 +1328,12 @@ class QAST::CompilerJS does DWIMYNameMangling does SerializeOnce {
}

if $node.blocktype eq 'immediate' {
my $extra_args := $arg ?? ",$arg" !! '';
self.stored_result(Chunk.new($want, $cuid~".\$call({$outer.ctx},\{\}$extra_args)", $setup, :$node), :$want);
my @args := [$outer.ctx,'{}'];
for @extra_args -> $arg {
@args.push($arg.expr);
$setup.push($arg);
}
self.stored_result(Chunk.new($want, $cuid~".\$call({nqp::join(',', @args)})", $setup, :$node), :$want);
} else {
Chunk.new($T_OBJ, $cuid, $setup);
}
Expand Down
2 changes: 1 addition & 1 deletion src/vm/js/bin/run_tests
@@ -1,5 +1,5 @@
#!/bin/bash
# 19 and 30 where moved out as they were parrot specific, 52,54 is missing, we can't pass 49 till we are bootstraped
#echo 'No tests pass as we are in the early stages of a rewrite/refactor'
prove -e './nqp-js' t/nqp/{01..18}* t/nqp/{20,22,23,25,26,36,37,38,40,41,42,46,48,53,59,63,68,81,83}* t/js/getcomp-js.t
prove -e './nqp-js' t/nqp/{01..18}* t/nqp/{20,22,23,25,26,36,37,38,39,40,41,42,46,48,53,59,63,68,81,83}* t/js/getcomp-js.t
#prove -e './nqp-js' t/nqp/{01..29}*.t t/nqp/{31..48}* t/nqp/{50,51,53}* t/nqp/{55..81}* t/nqp/83* t/serialization/0{2,3}*.t

0 comments on commit 74871a6

Please sign in to comment.