Skip to content

Commit

Permalink
[Truffle] Add Rubinius::ByteArray#{size,prepend}.
Browse files Browse the repository at this point in the history
  • Loading branch information
bjfish committed Apr 25, 2015
1 parent 28f9e82 commit 6120ead
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 3 deletions.
1 change: 1 addition & 0 deletions test/mri/excludes_truffle/TestDelegateClass.rb
Expand Up @@ -11,3 +11,4 @@
exclude :test_unset_simple_delegator, "needs investigation"
exclude :test_dir_in_delegator_class, "needs investigation"
exclude :test_dir_in_simple_delegator, "needs investigation"
exclude :test_global_function, "needs investigation"
1 change: 1 addition & 0 deletions test/mri/excludes_truffle/TestNotImplement.rb
Expand Up @@ -2,3 +2,4 @@
exclude :test_method_inspect_lchmod, "needs investigation"
exclude :test_respond_to_fork, "needs investigation"
exclude :test_respond_to_lchmod, "needs investigation"
exclude :test_call_lchmod, "needs investigation"
2 changes: 2 additions & 0 deletions test/mri/excludes_truffle/TestRequire.rb
Expand Up @@ -27,3 +27,5 @@
exclude :test_require_path_home_1, "needs investigation"
exclude :test_define_class_under, "needs investigation"
exclude :test_define_module, "needs investigation"
exclude :test_define_class, "needs investigation"
exclude :test_define_module_under, "needs investigation"
1 change: 1 addition & 0 deletions test/mri/excludes_truffle/TestString.rb
Expand Up @@ -55,3 +55,4 @@
exclude :test_splice! , "needs investigation"
exclude :test_split , "needs investigation"
exclude :test_sum , "needs investigation"
exclude :test_clone, "needs investigation"
1 change: 1 addition & 0 deletions test/mri/excludes_truffle/TestString2.rb
Expand Up @@ -52,3 +52,4 @@
exclude :test_splice! , "needs investigation"
exclude :test_split , "needs investigation"
exclude :test_sum , "needs investigation"
exclude :test_clone, "needs investigation"
2 changes: 1 addition & 1 deletion test/mri_truffle.index
Expand Up @@ -237,7 +237,7 @@ ruby/test_unicode_escape.rb
ruby/test_variable.rb
ruby/test_whileuntil.rb
ruby/test_yield.rb
# scanf/test_scanf.rb # difficult method name exclude
# scanf/test_scanf.rb # Fails when run as suite
# scanf/test_scanfblocks.rb
# socket/test_basicsocket.rb
# socket/test_nonblock.rb
Expand Down
Expand Up @@ -42,7 +42,31 @@ public int getByte(RubiniusByteArray bytes, int index) {

}

@CoreMethod(names = "set_byte", required = 2, lowerFixnumParameters = {1, 2})
@CoreMethod(names = "prepend", required = 1)
public abstract static class PrependNode extends CoreMethodNode {

public PrependNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

public PrependNode(PrependNode prev) {
super(prev);
}

@Specialization
public RubiniusByteArray prepend(RubiniusByteArray bytes, RubyString string) {
final int prependLength = string.getByteList().getUnsafeBytes().length;
final int originalLength = bytes.getBytes().getUnsafeBytes().length;
final int newLength = prependLength + originalLength;
final byte[] prependedBytes = new byte[newLength];
System.arraycopy(string.getByteList().getUnsafeBytes(), 0, prependedBytes, 0, prependLength);
System.arraycopy(bytes.getBytes().getUnsafeBytes(), 0, prependedBytes, prependLength, originalLength);
return new RubiniusByteArray(getContext().getCoreLibrary().getByteArrayClass(), new ByteList(prependedBytes));
}

}

@CoreMethod(names = "set_byte", required = 2, lowerFixnumParameters = {0, 1})
public abstract static class SetByteNode extends CoreMethodNode {

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

}

@CoreMethod(names = "size")
public abstract static class SizeNode extends CoreMethodNode {

public SizeNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

public SizeNode(SizeNode prev) {
super(prev);
}

@Specialization
public int size(RubiniusByteArray bytes) {
return bytes.getBytes().getRealSize();
}

}

@CoreMethod(names = "locate", required = 3)
public abstract static class LocateNode extends CoreMethodNode {

Expand Down
Expand Up @@ -1359,7 +1359,7 @@ private RubyString makeSubstring(RubyString string, int beg, int len) {

}

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

public StringFromByteArrayPrimitiveNode(RubyContext context, SourceSection sourceSection) {
Expand Down

0 comments on commit 6120ead

Please sign in to comment.