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

Commits on Dec 28, 2015

  1. [Truffle] U in unpack.

    chrisseaton committed Dec 28, 2015
    Copy the full SHA
    246209a View commit details
  2. [Truffle] u in unpack.

    chrisseaton committed Dec 28, 2015
    Copy the full SHA
    8d5a4f6 View commit details
  3. [Truffle] w in unpack.

    chrisseaton committed Dec 28, 2015
    Copy the full SHA
    b8da9a2 View commit details
  4. [Truffle] Unpack floats.

    chrisseaton committed Dec 28, 2015
    Copy the full SHA
    c882789 View commit details

Commits on Dec 29, 2015

  1. Copy the full SHA
    b9328c9 View commit details
  2. [Truffle] Z in unpack.

    chrisseaton committed Dec 29, 2015
    Copy the full SHA
    79cc499 View commit details
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/util/Pack.java
Original file line number Diff line number Diff line change
@@ -1390,7 +1390,7 @@ public static int utf8Decode(Ruby runtime, byte[]to, int p, int code) {

/** utf8_to_uv
*/
private static int utf8Decode(ByteBuffer buffer) {
private static int utf8Decode(ByteBuffer buffer) {
int c = buffer.get() & 0xFF;
int uv = c;
int n;
2 changes: 2 additions & 0 deletions spec/truffle/tags/core/string/unpack/z_tags.txt
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
fails:String#unpack with format 'Z' calls #to_str to coerce the directives string
fails:String#unpack with format 'Z' stops decoding at NULL bytes when passed the '*' modifier
fails:String#unpack with format 'Z' decodes the number of bytes specified by the count modifier and truncates the decoded string at the first NULL byte
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* 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.format.nodes.decode;

import com.oracle.truffle.api.dsl.NodeChild;
import com.oracle.truffle.api.dsl.NodeChildren;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.object.DynamicObject;
import org.jruby.truffle.format.nodes.PackNode;
import org.jruby.truffle.format.runtime.MissingValue;
import org.jruby.truffle.runtime.RubyContext;

@NodeChildren({
@NodeChild(value = "value", type = PackNode.class),
})
public abstract class DecodeFloat32Node extends PackNode {

public DecodeFloat32Node(RubyContext context) {
super(context);
}

@Specialization
public MissingValue decode(VirtualFrame frame, MissingValue missingValue) {
return missingValue;
}

@Specialization(guards = "isNil(nil)")
public DynamicObject decode(VirtualFrame frame, DynamicObject nil) {
return nil;
}

@Specialization
public float decode(VirtualFrame frame, int value) {
return Float.intBitsToFloat(value);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* 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.format.nodes.decode;

import com.oracle.truffle.api.dsl.NodeChild;
import com.oracle.truffle.api.dsl.NodeChildren;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.object.DynamicObject;
import org.jruby.truffle.format.nodes.PackNode;
import org.jruby.truffle.format.runtime.MissingValue;
import org.jruby.truffle.runtime.RubyContext;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;

@NodeChildren({
@NodeChild(value = "value", type = PackNode.class),
})
public abstract class DecodeFloat64Node extends PackNode {

public DecodeFloat64Node(RubyContext context) {
super(context);
}

@Specialization
public MissingValue decode(VirtualFrame frame, MissingValue missingValue) {
return missingValue;
}

@Specialization(guards = "isNil(nil)")
public DynamicObject decode(VirtualFrame frame, DynamicObject nil) {
return nil;
}

@Specialization
public double decode(VirtualFrame frame, long value) {
return Double.longBitsToDouble(value);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
/*
* 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.format.nodes.read;

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.dsl.NodeChild;
import com.oracle.truffle.api.dsl.NodeChildren;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
import org.jcodings.Encoding;
import org.jruby.RubyBignum;
import org.jruby.truffle.format.nodes.PackNode;
import org.jruby.truffle.format.nodes.SourceNode;
import org.jruby.truffle.nodes.core.FixnumOrBignumNode;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.layouts.Layouts;
import org.jruby.util.ByteList;
import org.jruby.util.StringSupport;

import java.math.BigInteger;
import java.nio.ByteBuffer;

/**
* Read a string that contains UU-encoded data and write as actual binary
* data.
*/
@NodeChildren({
@NodeChild(value = "source", type = SourceNode.class),
})
public abstract class ReadBERNode extends PackNode {

@Child private FixnumOrBignumNode fixnumOrBignumNode;

private final int length;
private final boolean ignoreStar;

public ReadBERNode(RubyContext context, int length, boolean ignoreStar) {
super(context);
fixnumOrBignumNode = FixnumOrBignumNode.create(context, null);
this.length = length;
this.ignoreStar = ignoreStar;
}

@Specialization
protected Object encode(VirtualFrame frame, byte[] source) {
CompilerDirectives.transferToInterpreter();

// TODO CS 28-Dec-15 should write our own optimizable version of BER

/*
* Copied from JRuby's Pack class.
*
* **** BEGIN LICENSE BLOCK *****
* Version: EPL 1.0/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Eclipse Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.eclipse.org/legal/epl-v10.html
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* Copyright (C) 2002-2004 Jan Arne Petersen <jpetersen@uni-bonn.de>
* Copyright (C) 2002-2004 Anders Bengtsson <ndrsbngtssn@yahoo.se>
* Copyright (C) 2003-2004 Thomas E Enebo <enebo@acm.org>
* Copyright (C) 2004 Charles O Nutter <headius@headius.com>
* Copyright (C) 2004 Stefan Matthias Aust <sma@3plus4.de>
* Copyright (C) 2005 Derek Berner <derek.berner@state.nm.us>
* Copyright (C) 2006 Evan Buswell <ebuswell@gmail.com>
* Copyright (C) 2007 Nick Sieger <nicksieger@gmail.com>
* Copyright (C) 2009 Joseph LaFata <joe@quibb.org>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the EPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the EPL, the GPL or the LGPL.
***** END LICENSE BLOCK *****/

final ByteBuffer encode = ByteBuffer.wrap(source, getSourcePosition(frame), getSourceLength(frame) - getSourcePosition(frame));

long ul = 0;
long ulmask = (0xfe << 56) & 0xffffffff;
BigInteger big128 = BigInteger.valueOf(128);
int pos = encode.position();

ul <<= 7;
ul |= encode.get(pos) & 0x7f;
if((encode.get(pos++) & 0x80) == 0) {
setSourcePosition(frame, getSourcePosition(frame) + pos);
return ul;
} else if((ul & ulmask) == 0) {
BigInteger big = BigInteger.valueOf(ul);
while(pos < encode.limit()) {
BigInteger mulResult = big.multiply(big128);
BigInteger v = mulResult.add(BigInteger.valueOf(encode.get(pos) & 0x7f));
big = v;
if((encode.get(pos++) & 0x80) == 0) {
setSourcePosition(frame, getSourcePosition(frame) + pos);
return fixnumOrBignumNode.fixnumOrBignum(big);
}
}
}

try {
encode.position(pos);
} catch (IllegalArgumentException e) {
//throw runtime.newArgumentError("in `unpack': poorly encoded input");
throw new UnsupportedOperationException();
}

throw new UnsupportedOperationException();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/*
* 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.format.nodes.read;

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.dsl.NodeChild;
import com.oracle.truffle.api.dsl.NodeChildren;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
import org.jruby.truffle.format.nodes.PackNode;
import org.jruby.truffle.format.nodes.SourceNode;
import org.jruby.truffle.format.runtime.MissingValue;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.layouts.Layouts;
import org.jruby.util.ByteList;
import org.jruby.util.StringSupport;

import java.util.Arrays;

@NodeChildren({
@NodeChild(value = "source", type = SourceNode.class),
})
public abstract class ReadBinaryStringNode extends PackNode {

final boolean readToEnd;
final boolean readToNull;
final int count;
final boolean trimTrailingSpaces;
final boolean trimTrailingNulls;

public ReadBinaryStringNode(RubyContext context, boolean readToEnd, boolean readToNull, int count, boolean trimTrailingSpaces, boolean trimTrailingNulls) {
super(context);
this.readToEnd = readToEnd;
this.readToNull = readToNull;
this.count = count;
this.trimTrailingSpaces = trimTrailingSpaces;
this.trimTrailingNulls = trimTrailingNulls;
}

@Specialization(guards = "isNull(source)")
public void read(VirtualFrame frame, Object source) {
CompilerDirectives.transferToInterpreter();

// Advance will handle the error
advanceSourcePosition(frame, count);

throw new IllegalStateException();
}

@Specialization
public Object read(VirtualFrame frame, byte[] source) {
final int start = getSourcePosition(frame);

int length;
ByteList result;

if (readToEnd) {
length = 0;

while (start + length < getSourceLength(frame) && (!readToNull || (start + length < getSourceLength(frame) && source[start + length] != 0))) {
length++;
}
} else if (readToNull) {
length = 0;

while (start + length < getSourceLength(frame) && length < count && (!readToNull || (start + length < getSourceLength(frame) && source[start + length] != 0))) {
length++;
}
} else {
length = count;

if (start + length >= getSourceLength(frame)) {
length = getSourceLength(frame) - start;
}
}

int usedLength = length;

while (usedLength > 0 && ((trimTrailingSpaces && source[start + usedLength - 1] == ' ') || (trimTrailingNulls && source[start + usedLength - 1] == 0))) {
usedLength--;
}

result = new ByteList(source, start, usedLength, true);

setSourcePosition(frame, start + length);

return Layouts.STRING.createString(getContext().getCoreLibrary().getStringFactory(), result, StringSupport.CR_UNKNOWN, null);
}

}
Loading