Skip to content

Commit 6120ead

Browse files
committed
[Truffle] Add Rubinius::ByteArray#{size,prepend}.
1 parent 28f9e82 commit 6120ead

8 files changed

Lines changed: 51 additions & 3 deletions

File tree

test/mri/excludes_truffle/TestDelegateClass.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@
1111
exclude :test_unset_simple_delegator, "needs investigation"
1212
exclude :test_dir_in_delegator_class, "needs investigation"
1313
exclude :test_dir_in_simple_delegator, "needs investigation"
14+
exclude :test_global_function, "needs investigation"

test/mri/excludes_truffle/TestNotImplement.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
exclude :test_method_inspect_lchmod, "needs investigation"
33
exclude :test_respond_to_fork, "needs investigation"
44
exclude :test_respond_to_lchmod, "needs investigation"
5+
exclude :test_call_lchmod, "needs investigation"

test/mri/excludes_truffle/TestRequire.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,5 @@
2727
exclude :test_require_path_home_1, "needs investigation"
2828
exclude :test_define_class_under, "needs investigation"
2929
exclude :test_define_module, "needs investigation"
30+
exclude :test_define_class, "needs investigation"
31+
exclude :test_define_module_under, "needs investigation"

test/mri/excludes_truffle/TestString.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,4 @@
5555
exclude :test_splice! , "needs investigation"
5656
exclude :test_split , "needs investigation"
5757
exclude :test_sum , "needs investigation"
58+
exclude :test_clone, "needs investigation"

test/mri/excludes_truffle/TestString2.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,4 @@
5252
exclude :test_splice! , "needs investigation"
5353
exclude :test_split , "needs investigation"
5454
exclude :test_sum , "needs investigation"
55+
exclude :test_clone, "needs investigation"

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 # difficult method name exclude
240+
# scanf/test_scanf.rb # Fails when run as suite
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: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,31 @@ public int getByte(RubiniusByteArray bytes, int index) {
4242

4343
}
4444

45-
@CoreMethod(names = "set_byte", required = 2, lowerFixnumParameters = {1, 2})
45+
@CoreMethod(names = "prepend", required = 1)
46+
public abstract static class PrependNode extends CoreMethodNode {
47+
48+
public PrependNode(RubyContext context, SourceSection sourceSection) {
49+
super(context, sourceSection);
50+
}
51+
52+
public PrependNode(PrependNode prev) {
53+
super(prev);
54+
}
55+
56+
@Specialization
57+
public RubiniusByteArray prepend(RubiniusByteArray bytes, RubyString string) {
58+
final int prependLength = string.getByteList().getUnsafeBytes().length;
59+
final int originalLength = bytes.getBytes().getUnsafeBytes().length;
60+
final int newLength = prependLength + originalLength;
61+
final byte[] prependedBytes = new byte[newLength];
62+
System.arraycopy(string.getByteList().getUnsafeBytes(), 0, prependedBytes, 0, prependLength);
63+
System.arraycopy(bytes.getBytes().getUnsafeBytes(), 0, prependedBytes, prependLength, originalLength);
64+
return new RubiniusByteArray(getContext().getCoreLibrary().getByteArrayClass(), new ByteList(prependedBytes));
65+
}
66+
67+
}
68+
69+
@CoreMethod(names = "set_byte", required = 2, lowerFixnumParameters = {0, 1})
4670
public abstract static class SetByteNode extends CoreMethodNode {
4771

4872
public SetByteNode(RubyContext context, SourceSection sourceSection) {
@@ -66,6 +90,24 @@ public Object setByte(RubiniusByteArray bytes, int index, int value) {
6690

6791
}
6892

93+
@CoreMethod(names = "size")
94+
public abstract static class SizeNode extends CoreMethodNode {
95+
96+
public SizeNode(RubyContext context, SourceSection sourceSection) {
97+
super(context, sourceSection);
98+
}
99+
100+
public SizeNode(SizeNode prev) {
101+
super(prev);
102+
}
103+
104+
@Specialization
105+
public int size(RubiniusByteArray bytes) {
106+
return bytes.getBytes().getRealSize();
107+
}
108+
109+
}
110+
69111
@CoreMethod(names = "locate", required = 3)
70112
public abstract static class LocateNode extends CoreMethodNode {
71113

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1359,7 +1359,7 @@ private RubyString makeSubstring(RubyString string, int beg, int len) {
13591359

13601360
}
13611361

1362-
@RubiniusPrimitive(name = "string_from_bytearray", needsSelf = false)
1362+
@RubiniusPrimitive(name = "string_from_bytearray", needsSelf = false, lowerFixnumParameters = {0, 1})
13631363
public static abstract class StringFromByteArrayPrimitiveNode extends RubiniusPrimitiveNode {
13641364

13651365
public StringFromByteArrayPrimitiveNode(RubyContext context, SourceSection sourceSection) {

0 commit comments

Comments
 (0)