Skip to content

Commit

Permalink
[Truffle] Implementing additional Array#[]= example.
Browse files Browse the repository at this point in the history
  • Loading branch information
bjfish committed Mar 31, 2015
1 parent 2aded96 commit c3af11f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
1 change: 0 additions & 1 deletion spec/truffle/tags/core/array/element_set_tags.txt
@@ -1,4 +1,3 @@
fails:Array#[]= calls to_int on its start and length arguments
fails:Array#[]= sets elements in the range arguments when passed ranges
fails:Array#[]= does nothing if the section defined by range has negative width and the rhs is an empty array
fails:Array#[]= tries to convert Range elements to Integers using #to_int with [m..n] and [m...n]
Expand Down
10 changes: 10 additions & 0 deletions truffle/src/main/java/org/jruby/truffle/nodes/core/ArrayNodes.java
Expand Up @@ -427,6 +427,16 @@ public IndexSetNode(IndexSetNode prev) {
toIntNode = prev.toIntNode;
}

@Specialization(guards = {"!isInteger(arguments[1])", "!isIntegerFixnumRange(arguments[1])"})
public Object set(VirtualFrame frame, RubyArray array, Object indexObject, Object value, UndefinedPlaceholder unused) {
if (toIntNode == null) {
CompilerDirectives.transferToInterpreter();
toIntNode = insert(ToIntNodeFactory.create(getContext(), getSourceSection(), null));
}
final int index = toIntNode.executeIntegerFixnum(frame, indexObject);
return writeNode.executeWrite(frame, array, index, value);
}

@Specialization
public Object set(VirtualFrame frame, RubyArray array, int index, Object value, UndefinedPlaceholder unused) {
final int normalizedIndex = array.normalizeIndex(index);
Expand Down

0 comments on commit c3af11f

Please sign in to comment.