Skip to content

Commit

Permalink
Showing 3 changed files with 43 additions and 4 deletions.
1 change: 0 additions & 1 deletion spec/truffle/tags/core/string/modulo_tags.txt
Original file line number Diff line number Diff line change
@@ -7,7 +7,6 @@ fails:String#% replaces trailing absolute argument specifier without type with p
fails:String#% raises an ArgumentError when given invalid argument specifiers
fails:String#% raises an ArgumentError when multiple positional argument tokens are given for one format specifier
fails:String#% respects positional arguments and precision tokens given for one format specifier
fails:String#% allows more than one digit of position
fails:String#% raises an ArgumentError when multiple width star tokens are given for one format specifier
fails:String#% raises an ArgumentError when a width star token is seen after a width token
fails:String#% raises an ArgumentError when multiple precision tokens are given
Original file line number Diff line number Diff line change
@@ -24,6 +24,7 @@
import org.jruby.truffle.core.format.format.FormatFloatNodeGen;
import org.jruby.truffle.core.format.format.FormatIntegerNodeGen;
import org.jruby.truffle.core.format.read.SourceNode;
import org.jruby.truffle.core.format.read.array.ReadArgumentIndexValueNodeGen;
import org.jruby.truffle.core.format.read.array.ReadHashValueNodeGen;
import org.jruby.truffle.core.format.read.array.ReadIntegerNodeGen;
import org.jruby.truffle.core.format.read.array.ReadStringNodeGen;
@@ -129,12 +130,14 @@ public void exitFormat(PrintfParser.FormatContext ctx) {

final FormatNode valueNode;

if (ctx.ANGLE_KEY() == null) {
valueNode = ReadValueNodeGen.create(context, new SourceNode());
} else {
if (ctx.ANGLE_KEY() != null) {
final byte[] keyBytes = tokenAsBytes(ctx.ANGLE_KEY().getSymbol(), 1);
final DynamicObject key = context.getSymbolTable().getSymbol(context.getRopeTable().getRope(keyBytes, USASCIIEncoding.INSTANCE, CodeRange.CR_7BIT));
valueNode = ReadHashValueNodeGen.create(context, key, new SourceNode());
} else if (absoluteArgumentIndex != DEFAULT){
valueNode = ReadArgumentIndexValueNodeGen.create(context, absoluteArgumentIndex, new SourceNode());
} else {
valueNode = ReadValueNodeGen.create(context, new SourceNode());
}

final int precision;
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright (c) 2015, 2016 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.core.format.read.array;

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.RubyContext;
import org.jruby.truffle.core.format.FormatNode;
import org.jruby.truffle.core.format.read.SourceNode;

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

private final int index;

public ReadArgumentIndexValueNode(RubyContext context, int index) {
super(context);
this.index = index - 1;
}

@Specialization
public Object read(VirtualFrame frame, Object[] source) {
return source[this.index];
}

}

0 comments on commit f24a6db

Please sign in to comment.