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: 87d78de28346
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 69acc9b5cd1b
Choose a head ref
  • 1 commit
  • 6 files changed
  • 1 contributor

Commits on Dec 8, 2014

  1. Copy the full SHA
    69acc9b View commit details

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright (c) 2014 Oracle and/or its affiliates. All rights reserved. This
* code is released under a tri EPL/GPL/LGPL license. You can use it,
* redistribute it and/or modify it under the terms of the:
*
* Eclipse Public License version 1.0
* GNU General Public License version 2
* GNU Lesser General Public License version 2.1
*/
package org.jruby.truffle.nodes.core;

import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.dispatch.DispatchHeadNode;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.core.RubyRegexp;
import org.jruby.truffle.runtime.core.RubyString;
import org.jruby.util.RegexpOptions;

public class InteroplatedRegexpNode extends RubyNode {

@Children protected final RubyNode[] children;
private final RegexpOptions options;
@Child protected DispatchHeadNode toS;

public InteroplatedRegexpNode(RubyContext context, SourceSection sourceSection, RubyNode[] children, RegexpOptions options) {
super(context, sourceSection);
this.children = children;
this.options = options;
toS = new DispatchHeadNode(context);
}

@Override
public RubyRegexp executeRubyRegexp(VirtualFrame frame) {
notDesignedForCompilation();

final org.jruby.RubyString[] strings = new org.jruby.RubyString[children.length];

for (int n = 0; n < children.length; n++) {
final Object child = children[n].execute(frame);
strings[n] = org.jruby.RubyString.newString(getContext().getRuntime(), ((RubyString) toS.call(frame, child, "to_s", null)).getBytes());
}

return new RubyRegexp(this, getContext().getCoreLibrary().getRegexpClass(), org.jruby.RubyRegexp.preprocessDRegexp(getContext().getRuntime(), strings, options).getByteList(), options.toOptions());
}

@Override
public Object execute(VirtualFrame frame) {
return executeRubyRegexp(frame);
}
}
22 changes: 20 additions & 2 deletions core/src/main/java/org/jruby/truffle/nodes/core/RegexpNodes.java
Original file line number Diff line number Diff line change
@@ -58,7 +58,7 @@ public EqualNode(EqualNode prev) {
public boolean equal(RubyRegexp a, RubyRegexp b) {
notDesignedForCompilation();

return a.equals(b);
return ((org.jruby.RubyString) org.jruby.RubyRegexp.newRegexp(getContext().getRuntime(), a.getSource(), a.getRegex().getOptions()).to_s()).getByteList().equals(((org.jruby.RubyString) org.jruby.RubyRegexp.newRegexp(getContext().getRuntime(), b.getSource(), b.getRegex().getOptions()).to_s()).getByteList());
}

}
@@ -189,6 +189,24 @@ public Object initializeCopy(RubyRegexp self, RubyRegexp from) {

}

@CoreMethod(names = "inspect")
public abstract static class InspectNode extends CoreMethodNode {

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

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

@Specialization
public RubyString match(RubyRegexp regexp) {
return new RubyString(getContext().getCoreLibrary().getStringClass(), ((org.jruby.RubyString) org.jruby.RubyRegexp.newRegexp(getContext().getRuntime(), regexp.getSource(), regexp.getRegex().getOptions()).inspect19()).getByteList());
}

}

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

@@ -238,7 +256,7 @@ public ToSNode(ToSNode prev) {

@Specialization
public RubyString to_s(RubyRegexp regexp) {
return getContext().makeString(org.jruby.RubyRegexp.newRegexp(getContext().getRuntime(), regexp.getSource()).to_s().toString());
return new RubyString(getContext().getCoreLibrary().getStringClass(), ((org.jruby.RubyString) org.jruby.RubyRegexp.newRegexp(getContext().getRuntime(), regexp.getSource(), regexp.getRegex().getOptions()).to_s()).getByteList());
}

}
Original file line number Diff line number Diff line change
@@ -335,11 +335,11 @@ public static Regex compile(RubyNode currentNode, RubyContext context, ByteList
public static Regex compile(RubyNode currentNode, RubyContext context, byte[] bytes, Encoding encoding, int options) {
RubyNode.notDesignedForCompilation();

try {
//try {
return new Regex(bytes, 0, bytes.length, options, encoding, Syntax.RUBY);
} catch (ValueException e) {
throw new org.jruby.truffle.runtime.control.RaiseException(context.getCoreLibrary().runtimeError("error compiling regex", currentNode));
}
//} catch (ValueException e) {
// throw new org.jruby.truffle.runtime.control.RaiseException(context.getCoreLibrary().runtimeError("error compiling regex", currentNode));
//}
}

}
Original file line number Diff line number Diff line change
@@ -668,9 +668,13 @@ public RubyNode visitDAsgnNode(org.jruby.ast.DAsgnNode node) {
public RubyNode visitDRegxNode(org.jruby.ast.DRegexpNode node) {
SourceSection sourceSection = translate(node.getPosition());

final RubyNode stringNode = translateInterpolatedString(sourceSection, node.childNodes());
final List<RubyNode> children = new ArrayList<>();

for (org.jruby.ast.Node child : node.childNodes()) {
children.add(child.accept(this));
}

return StringToRegexpNodeFactory.create(context, sourceSection, stringNode);
return new InteroplatedRegexpNode(context, sourceSection, children.toArray(new RubyNode[children.size()]), node.getOptions());
}

@Override
2 changes: 0 additions & 2 deletions spec/truffle/tags/language/regexp/interpolation_tags.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
fails:Regexps with interpolation allows interpolation which mixes modifiers
fails:Regexps with interpolation throws RegexpError for malformed interpolation
fails:Regexps with interpolation allows interpolation in extended mode
fails:Regexps with interpolation allows escape sequences in interpolated regexps