Skip to content

Commit

Permalink
Showing 3 changed files with 21 additions and 5 deletions.
9 changes: 9 additions & 0 deletions test/truffle/pe/core/string_pe.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# 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

example "'abc'.length", 3
1 change: 1 addition & 0 deletions test/truffle/pe/pe.rb
Original file line number Diff line number Diff line change
@@ -73,6 +73,7 @@ def tagged_counter_example(code)
require_relative 'core/binding_pe.rb'
require_relative 'core/frozen_pe.rb'
require_relative 'core/block_given_pe.rb'
require_relative 'core/string_pe.rb'
require_relative 'macro/pushing_pixels_pe.rb'
end

Original file line number Diff line number Diff line change
@@ -9,9 +9,12 @@
*/
package org.jruby.truffle.nodes.literal;

import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.source.SourceSection;

import org.jcodings.Encoding;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.objects.AllocateObjectNode;
import org.jruby.truffle.nodes.objects.AllocateObjectNodeGen;
@@ -20,22 +23,25 @@

public class StringLiteralNode extends RubyNode {

private final ByteList bytes;
private @CompilationFinal byte[] bytes; // deeply immutable
private final Encoding encoding;
private final int codeRange;

@Child private AllocateObjectNode allocateObjectNode;

public StringLiteralNode(RubyContext context, SourceSection sourceSection, ByteList bytes, int codeRange) {
public StringLiteralNode(RubyContext context, SourceSection sourceSection, ByteList byteList, int codeRange) {
super(context, sourceSection);
assert bytes != null;
this.bytes = bytes;
assert byteList != null;
this.bytes = byteList.bytes();
this.encoding = byteList.getEncoding();
this.codeRange = codeRange;
allocateObjectNode = AllocateObjectNodeGen.create(context, sourceSection, false, null, null);
}

@Override
public DynamicObject execute(VirtualFrame frame) {
return allocateObjectNode.allocate(getContext().getCoreLibrary().getStringClass(), bytes.dup(), codeRange, null);
final ByteList byteList = new ByteList(bytes, encoding, true /* do copy */);
return allocateObjectNode.allocate(getContext().getCoreLibrary().getStringClass(), byteList, codeRange, null);
}

}

0 comments on commit b5a4f37

Please sign in to comment.