Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 000fe098ea1a
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: f165f9f846b1
Choose a head ref
  • 14 commits
  • 130 files changed
  • 1 contributor

Commits on Nov 28, 2014

  1. Update RubySpec from rubyspec/rubyspec @ dfb927d4.

    RubySpec should be updated from canonical repo and
    Rubinius' copy should be merged regularly as in
    https://github.com/rubyspec/rubyspec/pull/295.
    
    Keep the .gitignore since it correclty ignores
    the automatically generated CAPI version file
    spec/ruby/optional/capi/ext/rubyspec_version.h.
    eregon committed Nov 28, 2014
    Copy the full SHA
    a8fb4c9 View commit details
  2. Update to latest mspec.

    eregon committed Nov 28, 2014
    Copy the full SHA
    d98798b View commit details
  3. Copy the full SHA
    dc9bc41 View commit details
  4. Copy the full SHA
    c29f283 View commit details
  5. [Truffle] Implement String#rstrip.

    * For RubySpec's evaluate.
    eregon committed Nov 28, 2014
    Copy the full SHA
    480a9bb View commit details
  6. Copy the full SHA
    b3cf481 View commit details
  7. Copy the full SHA
    e84c663 View commit details
  8. [Truffle] Fix String#{sub,gsub}(String) to escape it.

    * We could also try to have a smarter string replace directly wihtout Regexp.
    eregon committed Nov 28, 2014
    Copy the full SHA
    824b157 View commit details
  9. [Truffle] Fix String#[](int).

    eregon committed Nov 28, 2014
    Copy the full SHA
    4c66640 View commit details
  10. Copy the full SHA
    ce0bece View commit details
  11. [Truffle] Fix String#[rng] and Array#[rng].

    * Remove getInclusiveEnd since unused and dangerous.
    * getExclusiveEnd should only ever be used on RangeNodes,
      other uses need to normalize index first before considering
      exclusion status.
    eregon committed Nov 28, 2014
    Copy the full SHA
    659d281 View commit details
  12. Copy the full SHA
    fb1e016 View commit details
  13. Copy the full SHA
    20b4767 View commit details
  14. Copy the full SHA
    f165f9f View commit details
Showing with 5,830 additions and 2,102 deletions.
  1. +4 −0 core/src/main/java/org/jruby/ast/ComplexNode.java
  2. +16 −2 core/src/main/java/org/jruby/parser/ParserSupport.java
  3. +20 −4 core/src/main/java/org/jruby/truffle/nodes/core/ArrayNodes.java
  4. +26 −1 core/src/main/java/org/jruby/truffle/nodes/core/RegexpNodes.java
  5. +112 −17 core/src/main/java/org/jruby/truffle/nodes/core/StringNodes.java
  6. +1 −0 core/src/main/java/org/jruby/truffle/runtime/core/CoreLibrary.java
  7. +10 −8 core/src/main/java/org/jruby/truffle/runtime/core/RubyArray.java
  8. +0 −16 core/src/main/java/org/jruby/truffle/runtime/core/RubyRange.java
  9. +23 −3 core/src/main/java/org/jruby/truffle/runtime/core/RubyRegexp.java
  10. +2 −2 core/src/main/java/org/jruby/truffle/runtime/core/RubyString.java
  11. +1 −1 spec/mspec/README
  12. +3 −1 spec/mspec/lib/mspec/commands/mspec.rb
  13. +2 −0 spec/mspec/lib/mspec/guards/guard.rb
  14. +8 −6 spec/mspec/lib/mspec/guards/version.rb
  15. +0 −1 spec/mspec/lib/mspec/helpers.rb
  16. +0 −15 spec/mspec/lib/mspec/helpers/fmode.rb
  17. +2 −2 spec/mspec/lib/mspec/helpers/fs.rb
  18. +5 −1 spec/mspec/lib/mspec/helpers/io.rb
  19. +0 −30 spec/mspec/lib/mspec/helpers/language_version.rb
  20. +2 −2 spec/mspec/lib/mspec/helpers/ruby_exe.rb
  21. +1 −1 spec/mspec/lib/mspec/helpers/tmp.rb
  22. +1 −0 spec/mspec/lib/mspec/matchers.rb
  23. +51 −0 spec/mspec/lib/mspec/matchers/raise_exception.rb
  24. +1 −0 spec/mspec/lib/mspec/runner.rb
  25. +0 −19 spec/mspec/lib/mspec/runner/actions/debug.rb
  26. +54 −0 spec/mspec/lib/mspec/runner/evaluate.rb
  27. +1 −1 spec/mspec/lib/mspec/runner/mspec.rb
  28. +1 −0 spec/mspec/lib/mspec/utils/options.rb
  29. +1 −1 spec/mspec/lib/mspec/version.rb
  30. +0 −15 spec/mspec/spec/helpers/fmode_spec.rb
  31. +16 −16 spec/mspec/spec/helpers/fs_spec.rb
  32. +5 −0 spec/mspec/spec/helpers/io_spec.rb
  33. +0 −40 spec/mspec/spec/helpers/language_version_spec.rb
  34. +8 −8 spec/mspec/spec/helpers/ruby_exe_spec.rb
  35. +0 −1 spec/mspec/spec/matchers/equal_spec.rb
  36. +82 −0 spec/mspec/spec/matchers/raise_exception_spec.rb
  37. +0 −62 spec/mspec/spec/runner/actions/debug_spec.rb
  38. +1 −1 spec/mspec/spec/runner/mspec_spec.rb
  39. +33 −0 spec/ruby/command_line/dash_upper_k_spec.rb
  40. +162 −0 spec/ruby/command_line/rubyopt_spec.rb
  41. +65 −0 spec/ruby/core/array/bsearch_spec.rb
  42. +7 −0 spec/ruby/core/array/eql_spec.rb
  43. +4 −0 spec/ruby/core/array/first_spec.rb
  44. +37 −0 spec/ruby/core/array/to_h_spec.rb
  45. +31 −0 spec/ruby/core/dir/fileno_spec.rb
  46. +13 −0 spec/ruby/core/dir/glob_spec.rb
  47. +9 −1 spec/ruby/core/encoding/converter/inspect_spec.rb
  48. +0 −4 spec/ruby/core/encoding/default_external_spec.rb
  49. +5 −0 spec/ruby/core/enumerable/first_spec.rb
  50. +13 −0 spec/ruby/core/enumerable/fixtures/classes.rb
  51. +3 −0 spec/ruby/core/enumerable/sort_spec.rb
  52. +46 −0 spec/ruby/core/enumerable/to_h_spec.rb
  53. +2 −2 spec/ruby/core/hash/shared/replace.rb
  54. +99 −11 spec/ruby/core/io/popen_spec.rb
  55. +30 −0 spec/ruby/core/io/shared/new.rb
  56. +9 −0 spec/ruby/core/kernel/Float_spec.rb
  57. +9 −5 spec/ruby/core/kernel/backtick_spec.rb
  58. +12 −0 spec/ruby/core/kernel/itself_spec.rb
  59. +1 −1 spec/ruby/core/kernel/require_relative_spec.rb
  60. +26 −0 spec/ruby/core/kernel/singleton_class_spec.rb
  61. +17 −20 spec/ruby/core/kernel/sleep_spec.rb
  62. +191 −47 spec/ruby/core/method/arity_spec.rb
  63. +1 −1 spec/ruby/core/module/autoload_spec.rb
  64. +50 −0 spec/ruby/core/module/define_method_spec.rb
  65. +6 −0 spec/ruby/core/objectspace/define_finalizer_spec.rb
  66. +391 −91 spec/ruby/core/proc/arity_spec.rb
  67. +8 −4 spec/ruby/core/regexp/compile_spec.rb
  68. +8 −4 spec/ruby/core/regexp/new_spec.rb
  69. +429 −0 spec/ruby/core/regexp/shared/new_ascii.rb
  70. +16 −15 spec/ruby/core/regexp/shared/{new.rb → new_ascii_8bit.rb}
  71. +37 −8 spec/ruby/core/string/modulo_spec.rb
  72. +22 −0 spec/ruby/core/string/scrub_spec.rb
  73. +78 −72 spec/ruby/core/string/shared/slice.rb
  74. +5 −7 spec/ruby/core/string/slice_spec.rb
  75. +4 −0 spec/ruby/core/string/start_with_spec.rb
  76. +11 −3 spec/ruby/core/string/sub_spec.rb
  77. +6 −0 spec/ruby/core/time/minus_spec.rb
  78. +1 −1 spec/ruby/core/time/round_spec.rb
  79. +195 −24 spec/ruby/core/unboundmethod/arity_spec.rb
  80. +143 −0 spec/ruby/language/block_spec.rb
  81. +1 −2 spec/ruby/language/def_spec.rb
  82. +0 −32 spec/ruby/language/encoding_spec.rb
  83. +0 −6 spec/ruby/language/fixtures/classes.rb
  84. +0 −7 spec/ruby/language/fixtures/literal_lambda.rb
  85. +42 −6 spec/ruby/language/hash_spec.rb
  86. +522 −106 spec/ruby/language/lambda_spec.rb
  87. +1,104 −0 spec/ruby/language/method_spec.rb
  88. +65 −11 spec/ruby/language/numbers_spec.rb
  89. +0 −162 spec/ruby/language/predefined_spec.rb
  90. +0 −137 spec/ruby/language/splat_spec.rb
  91. +8 −0 spec/ruby/language/symbol_spec.rb
  92. +541 −1,029 spec/ruby/language/variables_spec.rb
  93. +106 −0 spec/ruby/language/while_spec.rb
  94. +17 −0 spec/ruby/optional/capi/array_spec.rb
  95. +58 −0 spec/ruby/optional/capi/bignum_spec.rb
  96. +10 −0 spec/ruby/optional/capi/class_spec.rb
  97. +6 −0 spec/ruby/optional/capi/exception_spec.rb
  98. +10 −0 spec/ruby/optional/capi/ext/array_spec.c
  99. +36 −0 spec/ruby/optional/capi/ext/bignum_spec.c
  100. +14 −4 spec/ruby/optional/capi/ext/class_spec.c
  101. +40 −0 spec/ruby/optional/capi/ext/globals_spec.c
  102. +13 −0 spec/ruby/optional/capi/ext/io_spec.c
  103. +20 −0 spec/ruby/optional/capi/ext/kernel_spec.c
  104. +10 −0 spec/ruby/optional/capi/ext/numeric_spec.c
  105. +20 −0 spec/ruby/optional/capi/ext/rational_spec.c
  106. +15 −0 spec/ruby/optional/capi/ext/rubyspec.h
  107. +1 −1 spec/ruby/optional/capi/ext/string_spec.c
  108. +5 −0 spec/ruby/optional/capi/ext/symbol_spec.c
  109. +56 −0 spec/ruby/optional/capi/globals_spec.rb
  110. +14 −0 spec/ruby/optional/capi/io_spec.rb
  111. +37 −0 spec/ruby/optional/capi/kernel_spec.rb
  112. +24 −0 spec/ruby/optional/capi/numeric_spec.rb
  113. +12 −0 spec/ruby/optional/capi/rational_spec.rb
  114. +14 −1 spec/ruby/optional/capi/string_spec.rb
  115. +6 −0 spec/ruby/optional/capi/symbol_spec.rb
  116. +28 −0 spec/ruby/shared/process/exec.rb
  117. +6 −0 spec/ruby/shared/process/fixtures/map_fd.rb
  118. +30 −0 spec/ruby/shared/process/fork.rb
  119. +23 −0 spec/ruby/shared/process/spawn.rb
  120. +11 −0 spec/truffle/tags/language/block_tags.txt
  121. +1 −0 spec/truffle/tags/language/class_tags.txt
  122. +6 −0 spec/truffle/tags/language/def_tags.txt
  123. +6 −0 spec/truffle/tags/language/hash_tags.txt
  124. +33 −0 spec/truffle/tags/language/lambda_tags.txt
  125. +77 −0 spec/truffle/tags/language/method_tags.txt
  126. +10 −0 spec/truffle/tags/language/numbers_tags.txt
  127. +13 −0 spec/truffle/tags/language/predefined_tags.txt
  128. +56 −0 spec/truffle/tags/language/variables_tags.txt
  129. +6 −0 spec/truffle/tags/language/versions/def_2.0.rb
  130. +2 −0 spec/truffle/tags/language/while_tags.txt
4 changes: 4 additions & 0 deletions core/src/main/java/org/jruby/ast/ComplexNode.java
Original file line number Diff line number Diff line change
@@ -41,4 +41,8 @@ public NodeType getNodeType() {
public Node getNumber() {
return y;
}

public void setNumber(Node y) {
this.y = y;
}
}
18 changes: 16 additions & 2 deletions core/src/main/java/org/jruby/parser/ParserSupport.java
Original file line number Diff line number Diff line change
@@ -1037,6 +1037,18 @@ public FloatNode negateFloat(FloatNode floatNode) {

return floatNode;
}

public ComplexNode negateComplexNode(ComplexNode complexNode) {
complexNode.setNumber(negateNumeric(complexNode.getPosition(), complexNode.getNumber()));

return complexNode;
}

public RationalNode negateRational(RationalNode rationalNode) {
return new RationalNode(rationalNode.getPosition(),
-rationalNode.getNumerator(),
rationalNode.getDenominator());
}

public Node unwrapNewlineNode(Node node) {
if(node instanceof NewlineNode) {
@@ -1414,10 +1426,12 @@ public Node negateNumeric(ISourcePosition position, Node node) {
case FIXNUMNODE:
case BIGNUMNODE:
return negateInteger(node);
case COMPLEXNODE: // FIXME: impl
// COMPLEX
case COMPLEXNODE:
return negateComplexNode((ComplexNode) node);
case FLOATNODE:
return negateFloat((FloatNode) node);
case RATIONALNODE:
return negateRational((RationalNode) node);
}

yyerror("Invalid or unimplemented numeric to negate: " + node.toString());
24 changes: 20 additions & 4 deletions core/src/main/java/org/jruby/truffle/nodes/core/ArrayNodes.java
Original file line number Diff line number Diff line change
@@ -635,13 +635,15 @@ public Object getObject(RubyArray array, int index, int length) {
public Object getObject(RubyArray array, RubyRange.IntegerFixnumRange range, UndefinedPlaceholder undefined) {
notDesignedForCompilation();

int normalisedIndex = array.normaliseIndex(range.getBegin());
int length = array.normaliseExclusiveIndex(range.getExclusiveEnd()) - normalisedIndex;
final int normalisedIndex = array.normaliseIndex(range.getBegin());

if (normalisedIndex < 0 || normalisedIndex >= array.getSize()) {
return getContext().getCoreLibrary().getNilObject();
} else {
return new RubyArray(getContext().getCoreLibrary().getArrayClass(), Arrays.copyOfRange((Object[]) array.getStore(), normalisedIndex, normalisedIndex + length), length);
final int end = array.normaliseIndex(range.getEnd());
final int excludingEnd = array.clampExclusiveIndex(range.doesExcludeEnd() ? end : end+1);

return new RubyArray(getContext().getCoreLibrary().getArrayClass(), Arrays.copyOfRange((Object[]) array.getStore(), normalisedIndex, excludingEnd), excludingEnd - normalisedIndex);
}
}

@@ -2069,7 +2071,7 @@ public RubyString inspect(VirtualFrame frame, RubyArray array) {

}

@CoreMethod(names = "join", required = 1)
@CoreMethod(names = "join", optional = 1)
public abstract static class JoinNode extends ArrayCoreMethodNode {

public JoinNode(RubyContext context, SourceSection sourceSection) {
@@ -2080,6 +2082,20 @@ public JoinNode(JoinNode prev) {
super(prev);
}

@Specialization
public RubyString join(RubyArray array, UndefinedPlaceholder unused) {
Object separator = getContext().getCoreLibrary().getGlobalVariablesObject().getInstanceVariable("$,");
if (separator == getContext().getCoreLibrary().getNilObject()) {
separator = getContext().makeString("");
}

if (separator instanceof RubyString) {
return join(array, (RubyString) separator);
} else {
throw new UnsupportedOperationException();
}
}

@Specialization
public RubyString join(RubyArray array, RubyString separator) {
notDesignedForCompilation();
27 changes: 26 additions & 1 deletion core/src/main/java/org/jruby/truffle/nodes/core/RegexpNodes.java
Original file line number Diff line number Diff line change
@@ -9,10 +9,12 @@
*/
package org.jruby.truffle.nodes.core;

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.source.*;
import com.oracle.truffle.api.dsl.*;
import com.oracle.truffle.api.frame.VirtualFrame;
import org.jruby.runtime.Visibility;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.dispatch.DispatchHeadNode;
import org.jruby.truffle.runtime.*;
import org.jruby.truffle.runtime.core.*;
@@ -21,6 +23,27 @@
@CoreClass(name = "Regexp")
public abstract class RegexpNodes {

public abstract static class EscapingNode extends CoreMethodNode {

@Child protected EscapeNode escapeNode;

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

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

protected RubyString escape(VirtualFrame frame, RubyString string) {
if (escapeNode == null) {
CompilerDirectives.transferToInterpreterAndInvalidate();
escapeNode = insert(RegexpNodesFactory.EscapeNodeFactory.create(getContext(), getSourceSection(), new RubyNode[]{null}));
}
return escapeNode.executeEscape(frame, string);
}
}

@CoreMethod(names = "==", required = 1)
public abstract static class EqualNode extends CoreMethodNode {

@@ -103,8 +126,10 @@ public EscapeNode(EscapeNode prev) {
super(prev);
}

public abstract RubyString executeEscape(VirtualFrame frame, RubyString pattern);

@Specialization
public RubyString sqrt(RubyString pattern) {
public RubyString escape(RubyString pattern) {
notDesignedForCompilation();

return getContext().makeString(org.jruby.RubyRegexp.quote19(new ByteList(pattern.getBytes()), true).toString());
129 changes: 112 additions & 17 deletions core/src/main/java/org/jruby/truffle/nodes/core/StringNodes.java
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@
package org.jruby.truffle.nodes.core;

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.UnexpectedResultException;
import com.oracle.truffle.api.source.SourceSection;
import com.oracle.truffle.api.dsl.Specialization;
@@ -26,7 +27,9 @@
import org.jruby.util.ByteList;
import org.jruby.util.Pack;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.regex.Pattern;

@CoreClass(name = "String")
@@ -185,15 +188,15 @@ public GetIndexNode(GetIndexNode prev) {
super(prev);
}

@Specialization(rewriteOn=UnexpectedResultException.class)
@Specialization(rewriteOn = UnexpectedResultException.class)
public RubyString getIndexInBounds(RubyString string, int index, UndefinedPlaceholder undefined) throws UnexpectedResultException {
final int normalisedIndex = string.normaliseIndex(index);
final ByteList bytes = string.getBytes();

if (normalisedIndex < 0 || normalisedIndex + 1 >= bytes.length()) {
if (normalisedIndex < 0 || normalisedIndex >= bytes.length()) {
throw new UnexpectedResultException(getContext().getCoreLibrary().getNilObject());
} else {
return new RubyString(getContext().getCoreLibrary().getStringClass(), (ByteList) bytes.subSequence(index, index + 1));
return getContext().makeString(bytes.charAt(normalisedIndex));
}
}

@@ -202,27 +205,27 @@ public Object getIndex(RubyString string, int index, UndefinedPlaceholder undefi
int normalisedIndex = string.normaliseIndex(index);
final ByteList bytes = string.getBytes();

if (normalisedIndex < 0 || normalisedIndex + 1 >= bytes.length()) {
if (normalisedIndex < 0 || normalisedIndex >= bytes.length()) {
return getContext().getCoreLibrary().getNilObject();
} else {
return new RubyString(getContext().getCoreLibrary().getStringClass(), (ByteList) bytes.subSequence(index, index + 1));
return getContext().makeString(bytes.charAt(normalisedIndex));
}
}

@Specialization
public RubyString getIndex(RubyString string, RubyRange.IntegerFixnumRange range, UndefinedPlaceholder undefined) {
public Object getIndex(RubyString string, RubyRange.IntegerFixnumRange range, UndefinedPlaceholder undefined) {
notDesignedForCompilation();

final String javaString = string.toString();
final int begin = string.normaliseIndex(range.getBegin());

if (range.doesExcludeEnd()) {
final int begin = string.normaliseIndex(range.getBegin());
final int exclusiveEnd = string.normaliseExclusiveIndex(range.getExclusiveEnd());
return getContext().makeString(javaString.substring(begin, exclusiveEnd));
if (begin < 0 || begin >= javaString.length()) {
return getContext().getCoreLibrary().getNilObject();
} else {
final int begin = string.normaliseIndex(range.getBegin());
final int inclusiveEnd = string.normaliseIndex(range.getInclusiveEnd());
return getContext().makeString(javaString.substring(begin, inclusiveEnd + 1));
final int end = string.normaliseIndex(range.getEnd());
final int excludingEnd = string.clampExclusiveIndex(range.doesExcludeEnd() ? end : end+1);

return getContext().makeString(javaString.substring(begin, excludingEnd));
}
}

@@ -231,7 +234,7 @@ public RubyString getIndex(RubyString string, int start, int length) {
// TODO(CS): not sure if this is right - encoding
// TODO(CS): why does subSequence return CharSequence?
final int begin = string.normaliseIndex(start);
final int exclusiveEnd = string.normaliseExclusiveIndex(start + length);
final int exclusiveEnd = string.normaliseIndex(start + length);
return new RubyString(getContext().getCoreLibrary().getStringClass(), (ByteList) string.getBytes().subSequence(begin, exclusiveEnd - begin));
}

@@ -359,6 +362,45 @@ public RubyString downcase(RubyString string) {
}
}

@CoreMethod(names = "each_line")
public abstract static class EachLineNode extends YieldingCoreMethodNode {

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

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

@Specialization
public RubyArray eachLine(RubyString string) {
notDesignedForCompilation();

final List<Object> lines = new ArrayList<>();

String str = string.toString();
int start = 0;

while (start < str.length()) {
int end = str.indexOf('\n', start);

if (end == -1) {
lines.add(getContext().makeString(str.substring(start)));
break;
}

String line = str.substring(start, end+1);
start = end+1;

lines.add(getContext().makeString(line));
}

return RubyArray.fromObjects(getContext().getCoreLibrary().getArrayClass(), lines.toArray(new Object[lines.size()]));
}

}

@CoreMethod(names = "empty?")
public abstract static class EmptyNode extends CoreMethodNode {

@@ -440,7 +482,7 @@ public RubyString forceEncoding(RubyString string, RubyString encodingName) {
}

@CoreMethod(names = "gsub", required = 2)
public abstract static class GsubNode extends CoreMethodNode {
public abstract static class GsubNode extends RegexpNodes.EscapingNode {

public GsubNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
@@ -451,10 +493,10 @@ public GsubNode(GsubNode prev) {
}

@Specialization
public RubyString gsub(RubyString string, RubyString regexpString, RubyString replacement) {
public RubyString gsub(VirtualFrame frame, RubyString string, RubyString regexpString, RubyString replacement) {
notDesignedForCompilation();

final RubyRegexp regexp = new RubyRegexp(this, getContext().getCoreLibrary().getRegexpClass(), regexpString.toString(), Option.DEFAULT);
final RubyRegexp regexp = new RubyRegexp(this, getContext().getCoreLibrary().getRegexpClass(), escape(frame, regexpString).toString(), Option.DEFAULT);
return gsub(string, regexp, replacement);
}

@@ -634,6 +676,32 @@ public RubyString rjust(RubyString string, int length, RubyString padding) {

}

@CoreMethod(names = "rstrip")
public abstract static class RStripNode extends CoreMethodNode {

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

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

@Specialization
public RubyString rstrip(RubyString string) {
notDesignedForCompilation();

String str = string.toString();
int last = str.length()-1;
while (last >= 0 && " \r\n\t".indexOf(str.charAt(last)) != -1) {
last--;
}

return getContext().makeString(str.substring(0, last+1));
}

}

@CoreMethod(names = "scan", required = 1)
public abstract static class ScanNode extends CoreMethodNode {

@@ -751,6 +819,33 @@ public boolean endWith(RubyString string, RubyString b) {
}
}

@CoreMethod(names = "sub", required = 2)
public abstract static class SubNode extends RegexpNodes.EscapingNode {

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

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

@Specialization
public RubyString sub(VirtualFrame frame, RubyString string, RubyString regexpString, RubyString replacement) {
notDesignedForCompilation();

final RubyRegexp regexp = new RubyRegexp(this, getContext().getCoreLibrary().getRegexpClass(), escape(frame, regexpString).toString(), Option.DEFAULT);
return sub(string, regexp, replacement);
}

@Specialization
public RubyString sub(RubyString string, RubyRegexp regexp, RubyString replacement) {
notDesignedForCompilation();

return regexp.sub(string.toString(), replacement.toString());
}
}

@CoreMethod(names = "sum")
public abstract static class SumNode extends CoreMethodNode {

Original file line number Diff line number Diff line change
@@ -247,6 +247,7 @@ public void initialize() {
globalVariablesObject.setInstanceVariable("$LOADED_FEATURES", new RubyArray(arrayClass));
globalVariablesObject.setInstanceVariable("$:", globalVariablesObject.getInstanceVariable("$LOAD_PATH"));
globalVariablesObject.setInstanceVariable("$\"", globalVariablesObject.getInstanceVariable("$LOADED_FEATURES"));
globalVariablesObject.setInstanceVariable("$,", nilObject);

initializeEncodingConstants();

Loading