Navigation Menu

Skip to content

Commit

Permalink
[Truffle] Pass encoding into eval.
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisseaton committed Dec 24, 2014
1 parent a55543b commit 53610d2
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 28 deletions.
3 changes: 2 additions & 1 deletion core/src/main/java/org/jruby/truffle/TruffleBridgeImpl.java
Expand Up @@ -14,6 +14,7 @@
import com.oracle.truffle.api.Truffle;
import com.oracle.truffle.api.frame.MaterializedFrame;
import com.oracle.truffle.api.source.SourceSection;
import org.jcodings.specific.UTF8Encoding;
import org.jruby.TruffleBridge;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.truffle.nodes.RubyNode;
Expand Down Expand Up @@ -161,7 +162,7 @@ public Object execute(final TranslatorDriver.ParserContext parserContext, final
source = Source.fromBytes(bytes, inputFile, new BytesDecoder.UTF8BytesDecoder());
}

return truffleContext.execute(truffleContext, source, parserContext, self, parentFrame, null, new NodeWrapper() {
return truffleContext.execute(truffleContext, source, UTF8Encoding.INSTANCE, parserContext, self, parentFrame, null, new NodeWrapper() {
@Override
public RubyNode wrap(RubyNode node) {
RubyContext context = node.getContext();
Expand Down
Expand Up @@ -234,7 +234,7 @@ public InstanceEvalNode(InstanceEvalNode prev) {
public Object instanceEval(VirtualFrame frame, Object receiver, RubyString string, UndefinedPlaceholder block) {
notDesignedForCompilation();

return getContext().eval(string.toString(), receiver, this);
return getContext().eval(string.getBytes(), receiver, this);
}

@Specialization
Expand Down
Expand Up @@ -513,7 +513,7 @@ public Object eval(VirtualFrame frame, RubyString source, UndefinedPlaceholder b
public Object eval(RubyString source, RubyBinding binding) {
notDesignedForCompilation();

return getContext().eval(source.toString(), binding, this);
return getContext().eval(source.getBytes(), binding, this);
}

@Specialization(guards = "!isRubyString(arguments[0])")
Expand Down Expand Up @@ -543,7 +543,7 @@ public Object eval(VirtualFrame frame, RubyBasicObject object, RubyBinding bindi
}

if (coerced instanceof RubyString) {
return getContext().eval(coerced.toString(), binding, this);
return getContext().eval(((RubyString) coerced).getBytes(), binding, this);
} else {
throw new RaiseException(
getContext().getCoreLibrary().typeError(
Expand Down
12 changes: 6 additions & 6 deletions core/src/main/java/org/jruby/truffle/nodes/core/ModuleNodes.java
Expand Up @@ -391,24 +391,24 @@ public ClassEvalNode(ClassEvalNode prev) {
public Object classEval(VirtualFrame frame, RubyModule module, RubyString code, @SuppressWarnings("unused") UndefinedPlaceholder file, @SuppressWarnings("unused") UndefinedPlaceholder line, @SuppressWarnings("unused") UndefinedPlaceholder block) {
notDesignedForCompilation();

final Source source = Source.fromText(code.toString(), "(eval)");
return getContext().execute(getContext(), source, TranslatorDriver.ParserContext.MODULE, module, frame.materialize(), this);
final Source source = Source.fromText(code.getBytes(), "(eval)");
return getContext().execute(getContext(), source, code.getBytes().getEncoding(), TranslatorDriver.ParserContext.MODULE, module, frame.materialize(), this);
}

@Specialization
public Object classEval(VirtualFrame frame, RubyModule module, RubyString code, RubyString file, @SuppressWarnings("unused") UndefinedPlaceholder line, @SuppressWarnings("unused") UndefinedPlaceholder block) {
notDesignedForCompilation();

final Source source = Source.asPseudoFile(code.toString(), file.toString());
return getContext().execute(getContext(), source, TranslatorDriver.ParserContext.MODULE, module, frame.materialize(), this);
final Source source = Source.asPseudoFile(code.getBytes(), file.toString());
return getContext().execute(getContext(), source, code.getBytes().getEncoding(), TranslatorDriver.ParserContext.MODULE, module, frame.materialize(), this);
}

@Specialization
public Object classEval(VirtualFrame frame, RubyModule module, RubyString code, RubyString file, @SuppressWarnings("unused") int line, @SuppressWarnings("unused") UndefinedPlaceholder block) {
notDesignedForCompilation();

final Source source = Source.asPseudoFile(code.toString(), file.toString());
return getContext().execute(getContext(), source, TranslatorDriver.ParserContext.MODULE, module, frame.materialize(), this);
final Source source = Source.asPseudoFile(code.getBytes(), file.toString());
return getContext().execute(getContext(), source, code.getBytes().getEncoding(), TranslatorDriver.ParserContext.MODULE, module, frame.materialize(), this);
}

@Specialization
Expand Down
26 changes: 14 additions & 12 deletions core/src/main/java/org/jruby/truffle/runtime/RubyContext.java
Expand Up @@ -18,6 +18,8 @@
import java.util.concurrent.atomic.*;

import com.oracle.truffle.api.object.Shape;
import org.jcodings.Encoding;
import org.jcodings.specific.UTF8Encoding;
import org.jruby.Ruby;
import org.jruby.*;
import com.oracle.truffle.api.*;
Expand Down Expand Up @@ -138,7 +140,7 @@ public static String checkClassVariableName(RubyContext context, String name, Ru
}

public void load(Source source, RubyNode currentNode) {
execute(this, source, TranslatorDriver.ParserContext.TOP_LEVEL, coreLibrary.getMainObject(), null, currentNode);
execute(this, source, UTF8Encoding.INSTANCE, TranslatorDriver.ParserContext.TOP_LEVEL, coreLibrary.getMainObject(), null, currentNode);
}

public void loadFile(String fileName, RubyNode currentNode) {
Expand All @@ -163,7 +165,7 @@ private void loadFileAbsolute(String fileName, RubyNode currentNode) {
final Source source = Source.fromBytes(bytes, fileName, new BytesDecoder.UTF8BytesDecoder());

coreLibrary.getLoadedFeatures().slowPush(makeString(fileName));
execute(this, source, TranslatorDriver.ParserContext.TOP_LEVEL, coreLibrary.getMainObject(), null, currentNode);
execute(this, source, UTF8Encoding.INSTANCE, TranslatorDriver.ParserContext.TOP_LEVEL, coreLibrary.getMainObject(), null, currentNode);
}

public RubySymbol.SymbolTable getSymbolTable() {
Expand All @@ -180,27 +182,27 @@ public RubySymbol newSymbol(ByteList name) {
return symbolTable.getSymbol(name);
}

public Object eval(String code, RubyNode currentNode) {
public Object eval(ByteList code, RubyNode currentNode) {
final Source source = Source.fromText(code, "(eval)");
return execute(this, source, TranslatorDriver.ParserContext.TOP_LEVEL, coreLibrary.getMainObject(), null, currentNode);
return execute(this, source, code.getEncoding(), TranslatorDriver.ParserContext.TOP_LEVEL, coreLibrary.getMainObject(), null, currentNode);
}

public Object eval(String code, Object self, RubyNode currentNode) {
public Object eval(ByteList code, Object self, RubyNode currentNode) {
final Source source = Source.fromText(code, "(eval)");
return execute(this, source, TranslatorDriver.ParserContext.TOP_LEVEL, self, null, currentNode);
return execute(this, source, code.getEncoding(), TranslatorDriver.ParserContext.TOP_LEVEL, self, null, currentNode);
}

public Object eval(String code, RubyBinding binding, RubyNode currentNode) {
public Object eval(ByteList code, RubyBinding binding, RubyNode currentNode) {
final Source source = Source.fromText(code, "(eval)");
return execute(this, source, TranslatorDriver.ParserContext.TOP_LEVEL, binding.getSelf(), binding.getFrame(), currentNode);
return execute(this, source, code.getEncoding(), TranslatorDriver.ParserContext.TOP_LEVEL, binding.getSelf(), binding.getFrame(), currentNode);
}

public Object execute(RubyContext context, Source source, TranslatorDriver.ParserContext parserContext, Object self, MaterializedFrame parentFrame, RubyNode currentNode) {
return execute(context, source, parserContext, self, parentFrame, currentNode, NodeWrapper.IDENTITY);
public Object execute(RubyContext context, Source source, Encoding defaultEncoding, TranslatorDriver.ParserContext parserContext, Object self, MaterializedFrame parentFrame, RubyNode currentNode) {
return execute(context, source, defaultEncoding, parserContext, self, parentFrame, currentNode, NodeWrapper.IDENTITY);
}

public Object execute(RubyContext context, Source source, TranslatorDriver.ParserContext parserContext, Object self, MaterializedFrame parentFrame, RubyNode currentNode, NodeWrapper wrapper) {
final RubyRootNode rootNode = translator.parse(context, source, parserContext, parentFrame, currentNode, wrapper);
public Object execute(RubyContext context, Source source, Encoding defaultEncoding, TranslatorDriver.ParserContext parserContext, Object self, MaterializedFrame parentFrame, RubyNode currentNode, NodeWrapper wrapper) {
final RubyRootNode rootNode = translator.parse(context, source, defaultEncoding, parserContext, parentFrame, currentNode, wrapper);
final CallTarget callTarget = Truffle.getRuntime().createCallTarget(rootNode);

// TODO(CS): we really need a method here - it's causing problems elsewhere
Expand Down
Expand Up @@ -15,6 +15,7 @@
import com.oracle.truffle.api.source.Source;
import org.jcodings.Encoding;
import org.jcodings.EncodingDB;
import org.jcodings.specific.UTF8Encoding;
import org.jruby.runtime.Constants;
import org.jruby.runtime.encoding.EncodingService;
import org.jruby.truffle.nodes.RubyNode;
Expand Down Expand Up @@ -313,7 +314,7 @@ public void loadRubyCore(String fileName) {
throw new RuntimeException(e);
}

context.execute(context, source, TranslatorDriver.ParserContext.TOP_LEVEL, mainObject, null, null);
context.execute(context, source, UTF8Encoding.INSTANCE, TranslatorDriver.ParserContext.TOP_LEVEL, mainObject, null, null);
}

public void initializeEncodingConstants() {
Expand Down
Expand Up @@ -11,6 +11,7 @@

import com.oracle.truffle.api.source.*;
import com.oracle.truffle.api.frame.*;
import org.jcodings.Encoding;
import org.jruby.parser.StaticScope;
import org.jruby.runtime.Visibility;
import org.jruby.runtime.builtin.IRubyObject;
Expand Down Expand Up @@ -68,7 +69,7 @@ public MethodDefinitionNode parse(RubyContext context, org.jruby.ast.Node parseT
return translator.compileFunctionNode(sourceSection, "(unknown)", argsNode, bodyNode, false, sharedMethod);
}

public RubyRootNode parse(RubyContext context, Source source, ParserContext parserContext, MaterializedFrame parentFrame, RubyNode currentNode, NodeWrapper wrapper) {
public RubyRootNode parse(RubyContext context, Source source, Encoding defaultEncoding, ParserContext parserContext, MaterializedFrame parentFrame, RubyNode currentNode, NodeWrapper wrapper) {
// Set up the JRuby parser

final org.jruby.parser.Parser parser = new org.jruby.parser.Parser(context.getRuntime());
Expand Down Expand Up @@ -97,6 +98,7 @@ public RubyRootNode parse(RubyContext context, Source source, ParserContext pars
}

final org.jruby.parser.ParserConfiguration parserConfiguration = new org.jruby.parser.ParserConfiguration(context.getRuntime(), 0, false, parserContext == ParserContext.TOP_LEVEL, true);
parserConfiguration.setDefaultEncoding(defaultEncoding);

// Parse to the JRuby AST

Expand Down
2 changes: 0 additions & 2 deletions spec/truffle/tags/language/encoding_tags.txt

This file was deleted.

2 changes: 0 additions & 2 deletions spec/truffle/tags/language/magic_comment_tags.txt

This file was deleted.

0 comments on commit 53610d2

Please sign in to comment.