Skip to content

Commit

Permalink
[Truffle] Add more Integer#downto specializations.
Browse files Browse the repository at this point in the history
  • Loading branch information
bjfish committed Apr 23, 2015
1 parent f8bc99c commit 73345e6
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
2 changes: 2 additions & 0 deletions test/mri/excludes_truffle/TestFixnum.rb
Expand Up @@ -2,3 +2,5 @@
exclude :test_pow2, "needs investigation"
exclude :test_power_of_0, "needs investigation"
exclude :test_remainder, "needs investigation"
exclude :test_xor_with_nonintegral_numeric, "needs investigation"
exclude :test_xor_with_rational, "needs investigation"
2 changes: 1 addition & 1 deletion test/mri_truffle.index
Expand Up @@ -250,7 +250,7 @@ test_delegate.rb
# test_ipaddr.rb # cannot load such file -- ipaddr
test_open3.rb
test_pp.rb
# test_prettyprint.rb # passes alone but not in suite, Integer.down_to int long proc
test_prettyprint.rb
test_prime.rb
# test_pstore.rb
# test_pty.rb
Expand Down
Expand Up @@ -77,6 +77,49 @@ public Object downto(VirtualFrame frame, int from, int to, RubyProc block) {
return nil();
}

@Specialization
public Object downto(VirtualFrame frame, long from, int to, RubyProc block) {
return downto(frame, from, (long) to, block);
}

@Specialization
public Object downto(VirtualFrame frame, int from, long to, RubyProc block) {
return downto(frame, (long) from, to, block);
}

@Specialization
public Object downto(VirtualFrame frame, long from, long to, RubyProc block) {
// TODO BJF 22-Apr-2015 how to handle reportLoopCount(long)
int count = 0;

try {
outer:
for (long i = from; i >= to; i--) {
while (true) {
if (CompilerDirectives.inInterpreter()) {
count++;
}

try {
yield(frame, block, i);
continue outer;
} catch (NextException e) {
nextProfile.enter();
continue outer;
} catch (RedoException e) {
redoProfile.enter();
}
}
}
} finally {
if (CompilerDirectives.inInterpreter()) {
getRootNode().reportLoopCount(count);
}
}

return nil();
}

@Specialization
public Object downto(VirtualFrame frame, int from, double to, RubyProc block) {
notDesignedForCompilation();
Expand Down

0 comments on commit 73345e6

Please sign in to comment.