Skip to content

Commit 7d07f90

Browse files
committed
[Truffle] Adding Rubinius::ByteArray#set_byte method.
1 parent 9f60295 commit 7d07f90

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

test/mri_truffle.index

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ ruby/test_unicode_escape.rb
237237
ruby/test_variable.rb
238238
ruby/test_whileuntil.rb
239239
ruby/test_yield.rb
240-
# scanf/test_scanf.rb # cannot load such file -- scanf.rb
240+
# scanf/test_scanf.rb # difficult method name exclude
241241
# scanf/test_scanfblocks.rb
242242
# socket/test_basicsocket.rb
243243
# socket/test_nonblock.rb

truffle/src/main/java/org/jruby/truffle/nodes/rubinius/ByteArrayNodes.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@
99
*/
1010
package org.jruby.truffle.nodes.rubinius;
1111

12+
import com.oracle.truffle.api.CompilerDirectives;
1213
import com.oracle.truffle.api.dsl.Specialization;
1314
import com.oracle.truffle.api.source.SourceSection;
1415
import org.jruby.truffle.nodes.core.CoreClass;
1516
import org.jruby.truffle.nodes.core.CoreMethod;
1617
import org.jruby.truffle.nodes.core.CoreMethodNode;
1718
import org.jruby.truffle.runtime.RubyContext;
19+
import org.jruby.truffle.runtime.control.RaiseException;
1820
import org.jruby.truffle.runtime.core.RubyString;
1921
import org.jruby.truffle.runtime.rubinius.RubiniusByteArray;
2022
import org.jruby.util.ByteList;
@@ -40,6 +42,30 @@ public int getByte(RubiniusByteArray bytes, int index) {
4042

4143
}
4244

45+
@CoreMethod(names = "set_byte", required = 2, lowerFixnumParameters = {1, 2})
46+
public abstract static class SetByteNode extends CoreMethodNode {
47+
48+
public SetByteNode(RubyContext context, SourceSection sourceSection) {
49+
super(context, sourceSection);
50+
}
51+
52+
public SetByteNode(SetByteNode prev) {
53+
super(prev);
54+
}
55+
56+
@Specialization
57+
public Object setByte(RubiniusByteArray bytes, int index, int value) {
58+
if (index < 0 || index >= bytes.getBytes().getRealSize()) {
59+
CompilerDirectives.transferToInterpreter();
60+
throw new RaiseException(getContext().getCoreLibrary().indexError("index out of bounds", this));
61+
}
62+
63+
bytes.getBytes().set(index, value);
64+
return bytes.getBytes().get(index);
65+
}
66+
67+
}
68+
4369
@CoreMethod(names = "locate", required = 3)
4470
public abstract static class LocateNode extends CoreMethodNode {
4571

truffle/src/main/ruby/core/shims.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ def initialize(*args)
161161
class Rubinius::ByteArray
162162

163163
alias_method :[], :get_byte
164+
alias_method :[]=, :set_byte
164165

165166
end
166167

0 commit comments

Comments
 (0)