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: ab853cd09b3d
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: f73877b6a122
Choose a head ref
  • 2 commits
  • 3 files changed
  • 1 contributor

Commits on Jun 4, 2015

  1. Copy the full SHA
    4504477 View commit details
  2. Copy the full SHA
    f73877b View commit details
1 change: 0 additions & 1 deletion spec/truffle/tags/core/regexp/initialize_tags.txt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright (c) 2015 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 org.jruby.truffle.runtime.core.RubyRegexp;

public class RegexpGuards {

public static boolean isInitialized(RubyRegexp regexp) {
return regexp.getRegex() != null;
}

public static boolean isRegexpLiteral(RubyRegexp regexp) {
return regexp.getOptions().isLiteral();
}

}
Original file line number Diff line number Diff line change
@@ -11,10 +11,12 @@

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.dsl.ImportStatic;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.source.SourceSection;
import org.joni.Matcher;
import org.joni.Regex;
import org.jruby.truffle.nodes.core.RegexpGuards;
import org.jruby.truffle.nodes.core.StringNodes;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.control.RaiseException;
@@ -48,6 +50,7 @@ public boolean fixedEncoding(RubyRegexp regexp) {
}

@RubiniusPrimitive(name = "regexp_initialize")
@ImportStatic(RegexpGuards.class)
public static abstract class RegexpInitializePrimitiveNode extends RubiniusPrimitiveNode {

public RegexpInitializePrimitiveNode(RubyContext context, SourceSection sourceSection) {
@@ -60,18 +63,22 @@ public RubyRegexp initializeRegexpLiteral(RubyRegexp regexp, RubyString pattern,
throw new RaiseException(getContext().getCoreLibrary().securityError("can't modify literal regexp", this));
}

@Specialization(guards = "!isRegexpLiteral(regexp)")
@Specialization(guards = { "!isRegexpLiteral(regexp)", "isInitialized(regexp)" })
public RubyRegexp initializeAlreadyInitialized(RubyRegexp regexp, RubyString pattern, int options) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().typeError("already initialized regexp", this));
}

@Specialization(guards = { "!isRegexpLiteral(regexp)", "!isInitialized(regexp)" })
public RubyRegexp initialize(RubyRegexp regexp, RubyString pattern, int options) {
regexp.initialize(this, StringNodes.getByteList(pattern), options);
return regexp;
}

public static boolean isRegexpLiteral(RubyRegexp regexp) {
return regexp.getOptions().isLiteral();
}
}

@RubiniusPrimitive(name = "regexp_options")
@ImportStatic(RegexpGuards.class)
public static abstract class RegexpOptionsPrimitiveNode extends RubiniusPrimitiveNode {

public RegexpOptionsPrimitiveNode(RubyContext context, SourceSection sourceSection) {
@@ -89,9 +96,6 @@ public int optionsNotInitialized(RubyRegexp regexp) {
throw new RaiseException(getContext().getCoreLibrary().typeError("uninitialized Regexp", this));
}

public static boolean isInitialized(RubyRegexp regexp) {
return regexp.getRegex() != null;
}
}

@RubiniusPrimitive(name = "regexp_search_region", lowerFixnumParameters = {1, 2})