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

Commits on Dec 8, 2014

  1. Copy the full SHA
    eb66623 View commit details
  2. Copy the full SHA
    6c2956a View commit details
  3. Copy the full SHA
    6f2cb65 View commit details
  4. Copy the full SHA
    800484a View commit details
  5. Copy the full SHA
    8e102f7 View commit details
  6. Copy the full SHA
    b1b3ece View commit details
44 changes: 44 additions & 0 deletions core/src/main/java/org/jruby/truffle/nodes/control/OnceNode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright (c) 2013, 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.control;

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.source.SourceSection;
import com.oracle.truffle.api.utilities.AssumedValue;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.runtime.RubyContext;

public class OnceNode extends RubyNode {

@Child protected RubyNode child;

// TODO(CS): need to always copy this with cloned nodes
private final AssumedValue<Object> valueMemo = new AssumedValue<>(null);

public OnceNode(RubyContext context, SourceSection sourceSection, RubyNode child) {
super(context, sourceSection);
this.child = child;
}

@Override
public Object execute(VirtualFrame frame) {
notDesignedForCompilation();

Object value = valueMemo.get();

if (value == null) {
value = child.execute(frame);
valueMemo.set(value);
}

return value;
}
}
28 changes: 28 additions & 0 deletions core/src/main/java/org/jruby/truffle/nodes/core/KernelNodes.java
Original file line number Diff line number Diff line change
@@ -1143,6 +1143,34 @@ public boolean load(RubyString file) {
}
}

@CoreMethod(names = "local_variables", needsSelf = false)
public abstract static class LocalVariablesNode extends CoreMethodNode {

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

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

@Specialization
public RubyArray localVariables() {
notDesignedForCompilation();

final RubyArray array = new RubyArray(getContext().getCoreLibrary().getArrayClass());

for (Object name : Truffle.getRuntime().getCallerFrame().getFrame(FrameInstance.FrameAccess.READ_ONLY, false).getFrameDescriptor().getIdentifiers()) {
if (name instanceof String) {
array.slowPush(getContext().newSymbol((String) name));
}
}

return array;
}

}

@CoreMethod(names = "loop", isModuleFunction = true)
public abstract static class LoopNode extends CoreMethodNode {

18 changes: 18 additions & 0 deletions core/src/main/java/org/jruby/truffle/nodes/core/RegexpNodes.java
Original file line number Diff line number Diff line change
@@ -112,6 +112,24 @@ public Object match(RubyRegexp regexp, RubyBasicObject other) {

}

@CoreMethod(names = "encoding")
public abstract static class EncodingNode extends CoreMethodNode {

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

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

@Specialization
public RubyEncoding encoding(RubyRegexp regexp) {
notDesignedForCompilation();
return regexp.getEncoding();
}
}

@CoreMethod(names = "escape", onSingleton = true, required = 1)
public abstract static class EscapeNode extends CoreMethodNode {

Original file line number Diff line number Diff line change
@@ -475,10 +475,14 @@ public ForceEncodingNode(ForceEncodingNode prev) {
@Specialization
public RubyString forceEncoding(RubyString string, RubyString encodingName) {
notDesignedForCompilation();
final RubyEncoding encoding = RubyEncoding.getEncoding(getContext(), encodingName.toString());
return forceEncoding(string, encoding);
}

RubyEncoding encoding = RubyEncoding.getEncoding(getContext(), encodingName.toString());
@Specialization
public RubyString forceEncoding(RubyString string, RubyEncoding encoding) {
notDesignedForCompilation();
string.forceEncoding(encoding.getEncoding());

return string;
}

14 changes: 14 additions & 0 deletions core/src/main/java/org/jruby/truffle/runtime/core/RubyRegexp.java
Original file line number Diff line number Diff line change
@@ -54,6 +54,8 @@ public RubyBasicObject newInstance(RubyNode currentNode) {
@CompilationFinal private Regex regex;
@CompilationFinal private ByteList source;

private RubyEncoding encoding;

public RubyRegexp(RubyClass regexpClass) {
super(regexpClass);
}
@@ -342,4 +344,16 @@ public static Regex compile(RubyNode currentNode, RubyContext context, byte[] by
//}
}

public void forceEncoding(RubyEncoding encoding) {
this.encoding = encoding;
}

public RubyEncoding getEncoding() {
if (encoding == null) {
encoding = RubyEncoding.getEncoding(getContext(), regex.getEncoding());
}

return encoding;
}

}
Original file line number Diff line number Diff line change
@@ -13,6 +13,8 @@
import com.oracle.truffle.api.source.SourceSection;
import com.oracle.truffle.api.frame.FrameSlot;
import com.oracle.truffle.api.nodes.NodeUtil;
import org.jcodings.Encoding;
import org.jcodings.specific.USASCIIEncoding;
import org.joni.Regex;
import org.jruby.ast.*;
import org.jruby.common.IRubyWarnings;
@@ -674,7 +676,13 @@ public RubyNode visitDRegxNode(org.jruby.ast.DRegexpNode node) {
children.add(child.accept(this));
}

return new InteroplatedRegexpNode(context, sourceSection, children.toArray(new RubyNode[children.size()]), node.getOptions());
final InteroplatedRegexpNode i = new InteroplatedRegexpNode(context, sourceSection, children.toArray(new RubyNode[children.size()]), node.getOptions());

if (node.getOptions().isOnce()) {
return new OnceNode(context, i.getEncapsulatingSourceSection(), i);
}

return i;
}

@Override
@@ -1887,10 +1895,42 @@ public RubyNode visitRegexpNode(org.jruby.ast.RegexpNode node) {
Regex regex = RubyRegexp.compile(currentNode, context, node.getValue().bytes(), node.getEncoding(), node.getOptions().toOptions());

final RubyRegexp regexp = new RubyRegexp(context.getCoreLibrary().getRegexpClass(), regex, node.getValue());

if (node.getOptions().isEncodingNone()) {
// This isn't quite right - we shouldn't be looking up by name, we need a real reference to this constants

if (all7Bit(node.getValue().bytes())) {
regexp.forceEncoding((RubyEncoding) context.getCoreLibrary().getEncodingClass().getConstants().get("US_ASCII").getValue());
} else {
regexp.forceEncoding((RubyEncoding) context.getCoreLibrary().getEncodingClass().getConstants().get("ASCII-8BIT").getValue());
}
} else if (node.getOptions().getKCode().getKCode().equals("SJIS")) {
regexp.forceEncoding((RubyEncoding) context.getCoreLibrary().getEncodingClass().getConstants().get("Windows_31J").getValue());
} else if (node.getOptions().getKCode().getKCode().equals("UTF8")) {
regexp.forceEncoding((RubyEncoding) context.getCoreLibrary().getEncodingClass().getConstants().get("UTF_8").getValue());
} else {
regexp.forceEncoding(RubyEncoding.getEncoding(context, node.getEncoding()));
}

final ObjectLiteralNode literalNode = new ObjectLiteralNode(context, translate(node.getPosition()), regexp);

if (node.getOptions().isOnce()) {
return new OnceNode(context, literalNode.getEncapsulatingSourceSection(), literalNode);
}

return literalNode;
}

private static boolean all7Bit(byte[] bytes) {
for (int n = 0; n < bytes.length; n++) {
if (bytes[n] < 0 || bytes[n] > 0x7F) {
return false;
}
}

return true;
}

@Override
public RubyNode visitRescueNode(org.jruby.ast.RescueNode node) {
final SourceSection sourceSection = translate(node.getPosition());
1 change: 1 addition & 0 deletions core/src/main/java/org/jruby/util/Memo.java
Original file line number Diff line number Diff line change
@@ -28,4 +28,5 @@ public T get() {
return value;
}


}
3 changes: 0 additions & 3 deletions spec/truffle/tags/language/match_tags.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
fails:The =~ operator with named captures on syntax of /regexp/ =~ string_variable sets local variables by the captured pairs
fails:The =~ operator with named captures on syntax of string_variable =~ /regexp/ does not set local variables
fails:The =~ operator with named captures on syntax of regexp_variable =~ string_variable does not set local variables
fails:The =~ operator with named captures on the method calling does not set local variables
11 changes: 0 additions & 11 deletions spec/truffle/tags/language/predefined_tags.txt
Original file line number Diff line number Diff line change
@@ -2,15 +2,10 @@ fails:Predefined global $~ changes the value of derived capture globals when ass
fails:Predefined global $~ changes the value of the derived preceding match global
fails:Predefined global $~ changes the value of the derived following match global
fails:Predefined global $~ changes the value of the derived full match global
fails(inherited):Predefined global $& sets the encoding to the encoding of the source String
fails:Predefined global $` is equivalent to MatchData#pre_match on the last match $~
fails(inherited):Predefined global $` sets the encoding to the encoding of the source String
fails(inherited):Predefined global $` sets an empty result to the encoding of the source String
fails:Predefined global $' is equivalent to MatchData#post_match on the last match $~
fails(inherited):Predefined global $' sets the encoding to the encoding of the source String
fails(inherited):Predefined global $' sets an empty result to the encoding of the source String
fails(inherited):Predefined global $+ sets the encoding to the encoding of the source String
fails(inherited):Predefined globals $1..N sets the encoding to the encoding of the source String
fails:Predefined global $stdout is the same as $DEFAULT_OUTPUT from 'English' library
fails:Predefined global $stdout raises TypeError error if assigned to nil
fails:Predefined global $stdout raises TypeError error if assigned to object that doesn't respond to #write
@@ -47,18 +42,12 @@ fails:The predefined global constant STDIN has the encodings set by #set_encodin
fails:The predefined global constant STDIN has the same external encoding as Encoding.default_external when that encoding is changed
fails:The predefined global constant STDIN has the same external encoding as Encoding.default_external
fails:Processing RUBYOPT adds the -I path to $LOAD_PATH
fails:Predefined global $& sets the encoding to the encoding of the source String
fails:Predefined global $` sets the encoding to the encoding of the source String
fails:Predefined global $` sets an empty result to the encoding of the source String
fails:Predefined global $' sets the encoding to the encoding of the source String
fails:Predefined global $' sets an empty result to the encoding of the source String
fails:Predefined global $+ sets the encoding to the encoding of the source String
fails:Predefined globals $1..N sets the encoding to the encoding of the source String
fails:Predefined global $/ changes $-0
fails:Predefined global $-0 changes $/
fails:Predefined global $-0 does not call #to_str to convert the object to a String
fails:Predefined global $-0 raises a TypeError if assigned a Fixnum
fails:Predefined global $-0 raises a TypeError if assigned a boolean
fails:Global variable $0 raises a TypeError when not given an object that can be coerced to a String
fails:Predefined global $~ raises an error if assigned an object not nil or instanceof MatchData
fails:Predefined global $~ is set at the method-scoped level rather than block-scoped
15 changes: 2 additions & 13 deletions spec/truffle/tags/language/regexp/encoding_tags.txt
Original file line number Diff line number Diff line change
@@ -1,20 +1,9 @@
fails:Regexps with encoding modifiers supports /e (EUC encoding)
fails:Regexps with encoding modifiers supports /e (EUC encoding) with interpolation
fails:Regexps with encoding modifiers supports /e (EUC encoding) with interpolation /o
fails:Regexps with encoding modifiers uses EUC-JP as /e encoding
fails:Regexps with encoding modifiers preserves EUC-JP as /e encoding through interpolation
fails:Regexps with encoding modifiers uses US-ASCII as /n encoding if all chars are 7-bit
fails:Regexps with encoding modifiers uses ASCII-8BIT as /n encoding if not all chars are 7-bit
fails:Regexps with encoding modifiers preserves US-ASCII as /n encoding through interpolation if all chars are 7-bit
fails:Regexps with encoding modifiers preserves ASCII-8BIT as /n encoding through interpolation if all chars are 7-bit
fails:Regexps with encoding modifiers supports /s (Windows_31J encoding)
fails:Regexps with encoding modifiers supports /s (Windows_31J encoding) with interpolation
fails:Regexps with encoding modifiers supports /s (Windows_31J encoding) with interpolation and /o
fails:Regexps with encoding modifiers uses Windows-31J as /s encoding
fails:Regexps with encoding modifiers preserves Windows-31J as /s encoding through interpolation
fails:Regexps with encoding modifiers uses UTF-8 as /u encoding
fails:Regexps with encoding modifiers preserves UTF-8 as /u encoding through interpolation
fails:Regexps with encoding modifiers supports /n (No encoding) with interpolation
fails:Regexps with encoding modifiers supports /n (No encoding) with interpolation /o
fails:Regexps with encoding modifiers supports /u (UTF8 encoding) with interpolation
fails:Regexps with encoding modifiers supports /u (UTF8 encoding) with interpolation and /o
fails:Regexps with encoding modifiers supports /s (Windows_31J encoding) with interpolation
fails:Regexps with encoding modifiers supports /s (Windows_31J encoding) with interpolation and /o
3 changes: 0 additions & 3 deletions spec/truffle/tags/language/regexp/modifiers_tags.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
fails:Regexps with modifers supports /o (once)
fails:Regexps with modifers invokes substitutions for /o only once
fails(inherited):Regexps with modifers supports ASII/Unicode modifiers
fails:Regexps with modifers raises SyntaxError for ASII/Unicode modifiers