-
-
Notifications
You must be signed in to change notification settings - Fork 925
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into truffle-head
- 9.4.12.0
- 9.4.11.0
- 9.4.10.0
- 9.4.9.0
- 9.4.8.0
- 9.4.7.0
- 9.4.6.0
- 9.4.5.0
- 9.4.4.0
- 9.4.3.0
- 9.4.2.0
- 9.4.1.0
- 9.4.0.0
- 9.3.15.0
- 9.3.14.0
- 9.3.13.0
- 9.3.12.0
- 9.3.11.0
- 9.3.10.0
- 9.3.9.0
- 9.3.8.0
- 9.3.7.0
- 9.3.6.0
- 9.3.5.0
- 9.3.4.0
- 9.3.3.0
- 9.3.2.0
- 9.3.1.0
- 9.3.0.0
- 9.2.21.0
- 9.2.20.1
- 9.2.20.0
- 9.2.19.0
- 9.2.18.0
- 9.2.17.0
- 9.2.16.0
- 9.2.15.0
- 9.2.14.0
- 9.2.13.0
- 9.2.12.0
- 9.2.11.1
- 9.2.11.0
- 9.2.10.0
- 9.2.9.0
- 9.2.8.0
- 9.2.7.0
- 9.2.6.0
- 9.2.5.0
- 9.2.4.1
- 9.2.4.0
- 9.2.3.0
- 9.2.2.0
- 9.2.1.0
- 9.2.0.0
- 9.1.17.0
- 9.1.16.0
- 9.1.15.0
- 9.1.14.0
- 9.1.13.0
- 9.1.12.0
- 9.1.11.0
- 9.1.10.0
- 9.1.9.0
- 9.1.8.0
- 9.1.7.0
- 9.1.6.0
- 9.1.5.0
- 9.1.4.0
- 9.1.3.0
- 9.1.2.0
- 9.1.1.0
- 9.1.0.0
- 9.0.5.0
Showing
45 changed files
with
934 additions
and
403 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
fails:File.link link a file with another | ||
fails:File.link raises an Errno::EEXIST if the target already exists |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
fails:File::Stat#grpowned? takes non primary groups into account | ||
fails(windows):File::Stat#grpowned? returns false if the file exist | ||
fails:File::Stat#grpowned? returns true if the file exist | ||
fails:File::Stat#grpowned? accepts an object that has a #to_path method |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
fails:File.symlink creates a symlink between a source and target file | ||
fails:File.symlink raises an Errno::EEXIST if the target already exists |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
fails:FileTest.grpowned? takes non primary groups into account | ||
fails:FileTest.grpowned? returns true if the file exist | ||
fails:FileTest.grpowned? accepts an object that has a #to_path method |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,10 @@ | ||
fails:Thread#alive? describes a dying sleeping thread | ||
fails(flaky):Thread#alive? can check it's own status | ||
fails(flaky):Thread#alive? describes a running thread | ||
fails(flaky):Thread#alive? describes a sleeping thread | ||
fails(flaky):Thread#alive? describes a blocked thread | ||
fails(flaky):Thread#alive? describes a completed thread | ||
fails(flaky):Thread#alive? describes a killed thread | ||
fails(flaky):Thread#alive? describes a thread with an uncaught exception | ||
fails(flaky):Thread#alive? describes a dying running thread | ||
fails(flaky):Thread#alive? returns true for a killed but still running thread |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
truffle/src/main/java/org/jruby/truffle/pack/nodes/format/FormatFloatNode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* 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.pack.nodes.format; | ||
|
||
import com.oracle.truffle.api.dsl.NodeChild; | ||
import com.oracle.truffle.api.dsl.NodeChildren; | ||
import com.oracle.truffle.api.dsl.Specialization; | ||
import org.jruby.truffle.pack.nodes.PackNode; | ||
import org.jruby.truffle.pack.parser.FormatDirective; | ||
import org.jruby.util.ByteList; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
|
||
@NodeChildren({ | ||
@NodeChild(value = "value", type = PackNode.class), | ||
}) | ||
public abstract class FormatFloatNode extends PackNode { | ||
|
||
private final int spacePadding; | ||
private final int zeroPadding; | ||
private final int precision; | ||
private final char format; | ||
|
||
public FormatFloatNode(int spacePadding, int zeroPadding, int precision, char format) { | ||
this.spacePadding = spacePadding; | ||
this.zeroPadding = zeroPadding; | ||
this.precision = precision; | ||
this.format = format; | ||
} | ||
|
||
@Specialization | ||
public ByteList format(double value) { | ||
// TODO CS 3-May-15 write this without building a string and formatting | ||
|
||
if (format == 'G' || format == 'g') { | ||
/** | ||
* General approach taken from StackOverflow: http://stackoverflow.com/questions/703396/how-to-nicely-format-floating-numbers-to-string-without-unnecessary-decimal-0 | ||
* Answers provided by JasonD (http://stackoverflow.com/users/1288598/jasond) and Darthenius (http://stackoverflow.com/users/974531/darthenius) | ||
* Licensed by cc-wiki license: http://creativecommons.org/licenses/by-sa/3.0/ | ||
*/ | ||
|
||
// TODO (nirvdrum 09-Mar-15) Make this adhere to the MRI invariant: "single-precision, network (big-endian) byte order" | ||
|
||
// TODO CS 4-May-15 G/g? Space padding? Zero padding? Precision? | ||
|
||
// If the value is a long value stuffed in a double, cast it so we don't print a trailing ".0". | ||
if ((value - Math.rint(value)) == 0) { | ||
return ByteList.create(String.valueOf((long) value)); | ||
} else { | ||
return ByteList.create(String.valueOf(value)); | ||
} | ||
} else { | ||
final StringBuilder builder = new StringBuilder(); | ||
|
||
builder.append("%"); | ||
|
||
if (spacePadding != FormatDirective.DEFAULT) { | ||
builder.append(" "); | ||
builder.append(spacePadding); | ||
|
||
if (zeroPadding != FormatDirective.DEFAULT) { | ||
builder.append("."); | ||
builder.append(zeroPadding); | ||
} | ||
} else if (zeroPadding != FormatDirective.DEFAULT) { | ||
builder.append("0"); | ||
builder.append(zeroPadding); | ||
} | ||
|
||
if (precision != FormatDirective.DEFAULT) { | ||
builder.append("."); | ||
builder.append(precision); | ||
} | ||
|
||
builder.append(format); | ||
|
||
return new ByteList(String.format(builder.toString(), value).getBytes(StandardCharsets.US_ASCII)); | ||
} | ||
} | ||
|
||
} |
73 changes: 73 additions & 0 deletions
73
truffle/src/main/java/org/jruby/truffle/pack/nodes/format/FormatIntegerNode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* 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.pack.nodes.format; | ||
|
||
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 org.jruby.truffle.pack.nodes.PackNode; | ||
import org.jruby.truffle.pack.parser.FormatDirective; | ||
import org.jruby.util.ByteList; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
|
||
@NodeChildren({ | ||
@NodeChild(value = "value", type = PackNode.class), | ||
}) | ||
public abstract class FormatIntegerNode extends PackNode { | ||
|
||
private final int spacePadding; | ||
private final int zeroPadding; | ||
private final char format; | ||
|
||
public FormatIntegerNode(int spacePadding, int zeroPadding, char format) { | ||
this.spacePadding = spacePadding; | ||
this.zeroPadding = zeroPadding; | ||
this.format = format; | ||
} | ||
|
||
@Specialization | ||
public ByteList format(int value) { | ||
return doFormat(value); | ||
} | ||
|
||
@Specialization | ||
public ByteList format(long value) { | ||
return doFormat(value); | ||
} | ||
|
||
@CompilerDirectives.TruffleBoundary | ||
protected ByteList doFormat(Object value) { | ||
// TODO CS 3-May-15 write this without building a string and formatting | ||
|
||
final StringBuilder builder = new StringBuilder(); | ||
|
||
builder.append("%"); | ||
|
||
if (spacePadding != FormatDirective.DEFAULT) { | ||
builder.append(" "); | ||
builder.append(spacePadding); | ||
|
||
if (zeroPadding != FormatDirective.DEFAULT) { | ||
builder.append("."); | ||
builder.append(zeroPadding); | ||
} | ||
} else if (zeroPadding != FormatDirective.DEFAULT) { | ||
builder.append("0"); | ||
builder.append(zeroPadding); | ||
} | ||
|
||
builder.append(format); | ||
|
||
return new ByteList(String.format(builder.toString(), value).getBytes(StandardCharsets.US_ASCII)); | ||
} | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
truffle/src/main/java/org/jruby/truffle/pack/nodes/read/LiteralBytesNode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* 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.pack.nodes.read; | ||
|
||
import com.oracle.truffle.api.frame.VirtualFrame; | ||
import org.jruby.truffle.pack.nodes.PackNode; | ||
import org.jruby.util.ByteList; | ||
|
||
public class LiteralBytesNode extends PackNode { | ||
|
||
private final ByteList bytes; | ||
|
||
public LiteralBytesNode(ByteList bytes) { | ||
this.bytes = bytes; | ||
} | ||
|
||
@Override | ||
public Object execute(VirtualFrame frame) { | ||
return bytes; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
truffle/src/main/java/org/jruby/truffle/pack/nodes/read/ReadValueNode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* 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.pack.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.pack.nodes.PackNode; | ||
import org.jruby.truffle.pack.nodes.SourceNode; | ||
|
||
@NodeChildren({ | ||
@NodeChild(value = "source", type = SourceNode.class), | ||
}) | ||
public abstract class ReadValueNode extends PackNode { | ||
|
||
@Specialization(guards = "isNull(source)") | ||
public void read(VirtualFrame frame, Object source) { | ||
CompilerDirectives.transferToInterpreter(); | ||
|
||
// Advance will handle the error | ||
advanceSourcePosition(frame); | ||
|
||
throw new IllegalStateException(); | ||
} | ||
|
||
@Specialization | ||
public long read(VirtualFrame frame, int[] source) { | ||
return source[advanceSourcePosition(frame)]; | ||
} | ||
|
||
@Specialization | ||
public long read(VirtualFrame frame, long[] source) { | ||
return source[advanceSourcePosition(frame)]; | ||
} | ||
|
||
@Specialization | ||
public long read(VirtualFrame frame, double[] source) { | ||
return (long) source[advanceSourcePosition(frame)]; | ||
} | ||
|
||
@Specialization | ||
public Object read(VirtualFrame frame, Object[] source) { | ||
return source[advanceSourcePosition(frame)]; | ||
} | ||
|
||
} |
40 changes: 40 additions & 0 deletions
40
truffle/src/main/java/org/jruby/truffle/pack/nodes/type/ToIntegerNode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* 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.pack.nodes.type; | ||
|
||
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.pack.nodes.PackNode; | ||
|
||
@NodeChildren({ | ||
@NodeChild(value = "value", type = PackNode.class), | ||
}) | ||
public abstract class ToIntegerNode extends PackNode { | ||
|
||
public abstract Object executeToInteger(VirtualFrame frame, Object object); | ||
|
||
@Specialization | ||
public int toInteger(VirtualFrame frame, int value) { | ||
return value; | ||
} | ||
|
||
@Specialization | ||
public long toInteger(VirtualFrame frame, long value) { | ||
return value; | ||
} | ||
|
||
@Specialization | ||
public long toInteger(VirtualFrame frame, double value) { | ||
return (long) value; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
truffle/src/main/java/org/jruby/truffle/pack/nodes/write/WriteBytesNode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* 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.pack.nodes.write; | ||
|
||
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.pack.nodes.PackNode; | ||
import org.jruby.util.ByteList; | ||
|
||
/** | ||
* Simply write bytes. | ||
*/ | ||
@NodeChildren({ | ||
@NodeChild(value = "value", type = PackNode.class), | ||
}) | ||
public abstract class WriteBytesNode extends PackNode { | ||
|
||
@Specialization | ||
public Object write(VirtualFrame frame, ByteList bytes) { | ||
writeBytes(frame, bytes); | ||
return null; | ||
} | ||
|
||
} |
49 changes: 49 additions & 0 deletions
49
truffle/src/main/java/org/jruby/truffle/pack/parser/FormatDirective.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* 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.pack.parser; | ||
|
||
/* | ||
* A single format directive from a printf-style format string. | ||
* | ||
* %[space padding][zero padding][.precision]type | ||
*/ | ||
public class FormatDirective { | ||
|
||
public static final int DEFAULT = -1; | ||
|
||
private final int spacePadding; | ||
private final int zeroPadding; | ||
private final int precision; | ||
private final char type; | ||
|
||
public FormatDirective(int spacePadding, int zeroPadding, int precision, char type) { | ||
this.spacePadding = spacePadding; | ||
this.zeroPadding = zeroPadding; | ||
this.precision = precision; | ||
this.type = type; | ||
} | ||
|
||
public int getSpacePadding() { | ||
return spacePadding; | ||
} | ||
|
||
public int getZeroPadding() { | ||
return zeroPadding; | ||
} | ||
|
||
public int getPrecision() { | ||
return precision; | ||
} | ||
|
||
public char getType() { | ||
return type; | ||
} | ||
|
||
} |
143 changes: 143 additions & 0 deletions
143
truffle/src/main/java/org/jruby/truffle/pack/parser/FormatParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
/* | ||
* 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.pack.parser; | ||
|
||
import com.oracle.truffle.api.CallTarget; | ||
import com.oracle.truffle.api.Truffle; | ||
import org.jruby.truffle.pack.nodes.PackNode; | ||
import org.jruby.truffle.pack.nodes.PackRootNode; | ||
import org.jruby.truffle.pack.nodes.SourceNode; | ||
import org.jruby.truffle.pack.nodes.control.SequenceNode; | ||
import org.jruby.truffle.pack.nodes.format.FormatFloatNodeGen; | ||
import org.jruby.truffle.pack.nodes.format.FormatIntegerNodeGen; | ||
import org.jruby.truffle.pack.nodes.read.LiteralBytesNode; | ||
import org.jruby.truffle.pack.nodes.read.ReadStringNodeGen; | ||
import org.jruby.truffle.pack.nodes.read.ReadValueNodeGen; | ||
import org.jruby.truffle.pack.nodes.type.ToDoubleNodeGen; | ||
import org.jruby.truffle.pack.nodes.type.ToIntegerNodeGen; | ||
import org.jruby.truffle.pack.nodes.write.WriteByteNode; | ||
import org.jruby.truffle.pack.nodes.write.WriteBytesNodeGen; | ||
import org.jruby.truffle.pack.runtime.PackEncoding; | ||
import org.jruby.truffle.runtime.RubyContext; | ||
import org.jruby.util.ByteList; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* Parses a format expression into a tree of Truffle nodes. | ||
*/ | ||
public class FormatParser { | ||
|
||
private final RubyContext context; | ||
|
||
private PackEncoding encoding = PackEncoding.DEFAULT; | ||
|
||
public FormatParser(RubyContext context) { | ||
this.context = context; | ||
} | ||
|
||
public CallTarget parse(ByteList format) { | ||
final FormatTokenizer tokenizer = new FormatTokenizer(format); | ||
final PackNode body = parse(tokenizer); | ||
return Truffle.getRuntime().createCallTarget(new PackRootNode(PackParser.describe(format.toString()), encoding, body)); | ||
} | ||
|
||
public PackNode parse(FormatTokenizer tokenizer) { | ||
final List<PackNode> sequenceChildren = new ArrayList<>(); | ||
|
||
while (true) { | ||
Object token = tokenizer.next(); | ||
|
||
if (token == null) { | ||
break; | ||
} | ||
|
||
final PackNode node; | ||
|
||
if (token instanceof ByteList) { | ||
node = WriteBytesNodeGen.create(new LiteralBytesNode((ByteList) token)); | ||
} else if (token instanceof FormatDirective) { | ||
final FormatDirective directive = (FormatDirective) token; | ||
|
||
switch (directive.getType()) { | ||
case '%': | ||
node = new WriteByteNode((byte) '%'); | ||
break; | ||
case 's': | ||
node = WriteBytesNodeGen.create(ReadStringNodeGen.create( | ||
context, true, "to_s", false, new ByteList(), new SourceNode())); | ||
break; | ||
case 'd': | ||
case 'i': | ||
case 'u': | ||
case 'x': | ||
case 'X': | ||
final int spacePadding = directive.getSpacePadding(); | ||
|
||
final int zeroPadding; | ||
|
||
/* | ||
* Precision and zero padding both set zero padding - | ||
* but precision has priority and explicit zero padding | ||
* is actually ignored if it's set. | ||
*/ | ||
|
||
if (directive.getPrecision() != FormatDirective.DEFAULT) { | ||
zeroPadding = directive.getPrecision(); | ||
} else { | ||
zeroPadding = directive.getZeroPadding(); | ||
} | ||
|
||
final char format; | ||
|
||
switch (directive.getType()) { | ||
case 'd': | ||
case 'i': | ||
case 'u': | ||
format = 'd'; | ||
break; | ||
case 'x': | ||
case 'X': | ||
format = directive.getType(); | ||
break; | ||
default: | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
node = WriteBytesNodeGen.create( | ||
FormatIntegerNodeGen.create(spacePadding, zeroPadding, format, | ||
ToIntegerNodeGen.create( | ||
ReadValueNodeGen.create(new SourceNode())))); | ||
break; | ||
case 'f': | ||
case 'g': | ||
case 'G': | ||
node = WriteBytesNodeGen.create( | ||
FormatFloatNodeGen.create(directive.getSpacePadding(), | ||
directive.getZeroPadding(), directive.getPrecision(), | ||
directive.getType(), | ||
ToDoubleNodeGen.create( | ||
ReadValueNodeGen.create(new SourceNode())))); | ||
break; | ||
default: | ||
throw new UnsupportedOperationException(); | ||
} | ||
} else { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
sequenceChildren.add(node); | ||
} | ||
|
||
return new SequenceNode(sequenceChildren.toArray(new PackNode[sequenceChildren.size()])); | ||
} | ||
|
||
} |
121 changes: 121 additions & 0 deletions
121
truffle/src/main/java/org/jruby/truffle/pack/parser/FormatTokenizer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
/* | ||
* 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.pack.parser; | ||
|
||
import org.jruby.util.ByteList; | ||
|
||
/** | ||
* Tokenizes a format expression into a stream of {@link String} and | ||
* {@link FormatDirective} objects. | ||
*/ | ||
public class FormatTokenizer { | ||
|
||
private static final String TYPE_CHARS = "%sdiuxXfg"; | ||
|
||
private final ByteList format; | ||
private int position; | ||
private Object peek; | ||
|
||
/** | ||
* Construct a tokenizer. | ||
* @param format the pack expression | ||
*/ | ||
public FormatTokenizer(ByteList format) { | ||
this.format = format; | ||
} | ||
|
||
public Object peek() { | ||
if (peek == null) { | ||
peek = next(); | ||
} | ||
|
||
return peek; | ||
} | ||
|
||
public Object next() { | ||
if (peek != null) { | ||
final Object token = peek; | ||
peek = null; | ||
return token; | ||
} | ||
|
||
if (position >= format.length()) { | ||
return null; | ||
} | ||
|
||
final char c = format.charAt(position); | ||
|
||
if (c != '%') { | ||
final int stringStart = position; | ||
|
||
position++; | ||
|
||
while (position < format.length() && format.charAt(position) != '%') { | ||
position++; | ||
} | ||
|
||
return format.subSequence(stringStart, position); | ||
} | ||
|
||
position++; | ||
|
||
int spacePadding; | ||
int zeroPadding; | ||
|
||
if (format.charAt(position) == ' ') { | ||
position++; | ||
spacePadding = readInt(); | ||
zeroPadding = FormatDirective.DEFAULT; | ||
} else { | ||
spacePadding = FormatDirective.DEFAULT; | ||
|
||
if (format.charAt(position) == '0') { | ||
position++; | ||
zeroPadding = readInt(); | ||
} else { | ||
zeroPadding = FormatDirective.DEFAULT; | ||
} | ||
} | ||
|
||
final int precision; | ||
|
||
if (format.charAt(position) == '.') { | ||
position++; | ||
precision = readInt(); | ||
} else { | ||
precision = FormatDirective.DEFAULT; | ||
} | ||
|
||
if (Character.isDigit(format.charAt(position))) { | ||
spacePadding = readInt(); | ||
} | ||
|
||
final char type = format.charAt(position); | ||
|
||
if (TYPE_CHARS.indexOf(type) == -1) { | ||
throw new UnsupportedOperationException("Unknown format type '" + format.charAt(position) + "'"); | ||
} | ||
|
||
position++; | ||
|
||
return new FormatDirective(spacePadding, zeroPadding, precision, type); | ||
} | ||
|
||
private int readInt() { | ||
final int start = position; | ||
|
||
while (Character.isDigit(format.charAt(position))) { | ||
position++; | ||
} | ||
|
||
return Integer.parseInt(format.subSequence(start, position).toString()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
221 changes: 0 additions & 221 deletions
221
truffle/src/main/java/org/jruby/truffle/runtime/core/StringFormatter.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,15 @@ | ||
# Copyright (c) 2014, 2015 Oracle and/or its affiliates. All rights reserved. This | ||
# 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 | ||
|
||
# These are implemented just to get other stuff working - we'll go back and | ||
# implement these properly later. | ||
|
||
class String | ||
|
||
def %(args) | ||
sprintf(self, *args) | ||
end | ||
|
||
end |