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: ba40fa2f0e55
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 758404f48992
Choose a head ref
  • 7 commits
  • 22 files changed
  • 1 contributor

Commits on Sep 24, 2015

  1. Copy the full SHA
    54933e0 View commit details
  2. Copy the full SHA
    ab8672c View commit details
  3. Copy the full SHA
    8f6737b View commit details
  4. Copy the full SHA
    067d7e3 View commit details
  5. Copy the full SHA
    6c25cea View commit details
  6. Copy the full SHA
    5cb0974 View commit details

Commits on Sep 25, 2015

  1. Copy the full SHA
    758404f View commit details
Showing with 692 additions and 94 deletions.
  1. +14 −4 lib/ruby/truffle/truffle/truffle/psych.rb
  2. +0 −1 spec/truffle/tags/library/yaml/dump_stream_tags.txt
  3. +0 −6 spec/truffle/tags/library/yaml/dump_tags.txt
  4. +0 −2 spec/truffle/tags/library/yaml/load_documents_tags.txt
  5. +0 −1 spec/truffle/tags/library/yaml/load_file_tags.txt
  6. +0 −11 spec/truffle/tags/library/yaml/load_tags.txt
  7. +0 −2 spec/truffle/tags/library/yaml/parse_tags.txt
  8. +0 −1 spec/truffle/tags/library/yaml/tagurize_tags.txt
  9. +0 −14 spec/truffle/tags/library/yaml/to_yaml_tags.txt
  10. +2 −1 truffle/src/main/java/org/jruby/truffle/nodes/RubyNode.java
  11. +461 −4 truffle/src/main/java/org/jruby/truffle/nodes/ext/psych/PsychEmitterNodes.java
  12. +50 −27 truffle/src/main/java/org/jruby/truffle/nodes/ext/psych/PsychParserNodes.java
  13. +8 −3 truffle/src/main/java/org/jruby/truffle/runtime/RubyContext.java
  14. +38 −0 truffle/src/main/java/org/jruby/truffle/runtime/adapaters/InputStreamAdapter.java
  15. +41 −0 truffle/src/main/java/org/jruby/truffle/runtime/adapaters/OutputStreamAdapter.java
  16. +9 −8 truffle/src/main/java/org/jruby/truffle/runtime/core/CoreLibrary.java
  17. +4 −1 truffle/src/main/java/org/jruby/truffle/runtime/layouts/Layouts.java
  18. +44 −0 truffle/src/main/java/org/jruby/truffle/runtime/layouts/ext/psych/EmitterLayout.java
  19. +0 −6 truffle/src/main/java/org/jruby/truffle/translator/BodyTranslator.java
  20. +2 −2 truffle/src/main/java/org/jruby/truffle/translator/TranslatorDriver.java
  21. +3 −0 truffle/src/main/ruby/core.rb
  22. +16 −0 truffle/src/main/ruby/core/post.rb
18 changes: 14 additions & 4 deletions lib/ruby/truffle/truffle/truffle/psych.rb
Original file line number Diff line number Diff line change
@@ -6,13 +6,23 @@
# GNU General Public License version 2
# GNU Lesser General Public License version 2.1

module Truffle::Psych

Psych = Truffle::Psych

module Psych

def self.libyaml_version
# TODO CS 23-Sep-15 hardcoded this for now - use resources to read
# TODO CS 23-Sep-15 hardcoded this for now - uses resources to read
[1, 14, 0]
end

class ClassLoader

def path2class(path)
eval("::#{path}")
end

end

end

Psych = Truffle::Psych
require 'psych/syntax_error.rb'
1 change: 0 additions & 1 deletion spec/truffle/tags/library/yaml/dump_stream_tags.txt

This file was deleted.

6 changes: 0 additions & 6 deletions spec/truffle/tags/library/yaml/dump_tags.txt

This file was deleted.

2 changes: 0 additions & 2 deletions spec/truffle/tags/library/yaml/load_documents_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/truffle/tags/library/yaml/load_file_tags.txt

This file was deleted.

11 changes: 0 additions & 11 deletions spec/truffle/tags/library/yaml/load_tags.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1 @@
fails:YAML.load returns a document from current io stream when io provided
fails:YAML.load loads strings
fails:YAML.load fails on invalid keys
fails:YAML.load accepts symbols
fails:YAML.load accepts numbers
fails:YAML.load accepts collections
fails:YAML.load parses start markers
fails:YAML.load works with block sequence shortcuts
fails:YAML.load works on complex keys
fails:YAML.load loads a symbol key that contains spaces
fails:YAML.load with iso8601 timestamp computes the microseconds
fails:YAML.load with iso8601 timestamp rounds values smaller than 1 usec to 0
2 changes: 0 additions & 2 deletions spec/truffle/tags/library/yaml/parse_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/truffle/tags/library/yaml/tagurize_tags.txt

This file was deleted.

14 changes: 0 additions & 14 deletions spec/truffle/tags/library/yaml/to_yaml_tags.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,4 @@
fails:Object#to_yaml returns the YAML representation of an Array object
fails:Object#to_yaml returns the YAML representation of a Hash object
fails:Object#to_yaml returns the YAML representation of a Class object
fails:Object#to_yaml returns the YAML representation of a Date object
fails:Object#to_yaml returns the YAML representation of a FalseClass
fails:Object#to_yaml returns the YAML representation of a Float object
fails:Object#to_yaml returns the YAML representation of an Integer object
fails:Object#to_yaml returns the YAML representation of a NilClass object
fails:Object#to_yaml returns the YAML represenation of a RegExp object
fails:Object#to_yaml returns the YAML representation of a String object
fails:Object#to_yaml returns the YAML representation of a Struct object
fails:Object#to_yaml returns the YAML representation of a Symbol object
fails:Object#to_yaml returns the YAML representation of a Time object
fails:Object#to_yaml returns the YAML representation of a TrueClass
fails:Object#to_yaml returns the YAML representation of a Error object
fails:Object#to_yaml returns the YAML representation for Range objects
fails:Object#to_yaml returns the YAML representation of numeric constants
fails:Object#to_yaml returns the YAML representation of an array of hashes
3 changes: 2 additions & 1 deletion truffle/src/main/java/org/jruby/truffle/nodes/RubyNode.java
Original file line number Diff line number Diff line change
@@ -31,6 +31,7 @@
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.layouts.Layouts;
import org.jruby.truffle.runtime.sockets.NativeSockets;
import org.jruby.truffle.translator.TranslatorDriver;
import org.jruby.util.ByteList;
import org.jruby.util.StringSupport;

@@ -222,7 +223,7 @@ protected Object ruby(String expression, Object... arguments) {
protected Object ruby(Frame frame, String expression, Object... arguments) {
final MaterializedFrame evalFrame = setupFrame(frame, arguments);
final DynamicObject binding = Layouts.BINDING.createBinding(getContext().getCoreLibrary().getBindingFactory(), evalFrame);
return getContext().eval(expression, binding, true, "inline-ruby", this);
return getContext().eval(TranslatorDriver.ParserContext.INLINE, expression, binding, true, "inline-ruby", this);
}

private MaterializedFrame setupFrame(Frame frame, Object... arguments) {

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -7,9 +7,11 @@
* GNU General Public License version 2
* GNU Lesser General Public License version 2.1
*
* Some of this code is modifed from the Psych JRuby extension module
* This code is modified from the Psych JRuby extension module
* implementation with the following header:
*
* 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
@@ -41,6 +43,8 @@
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.source.SourceSection;
import org.jcodings.Encoding;
import org.jcodings.specific.UTF16BEEncoding;
import org.jcodings.specific.UTF16LEEncoding;
import org.jcodings.specific.UTF8Encoding;
import org.jcodings.unicode.UnicodeEncoding;
import org.jruby.RubyEncoding;
@@ -53,12 +57,14 @@
import org.jruby.truffle.nodes.objects.AllocateObjectNodeGen;
import org.jruby.truffle.runtime.NotProvided;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.adapaters.InputStreamAdapter;
import org.jruby.truffle.runtime.control.RaiseException;
import org.jruby.truffle.runtime.layouts.Layouts;
import org.jruby.util.ByteList;
import org.jruby.util.IOInputStream;
import org.jruby.util.StringSupport;
import org.jruby.util.io.EncodingUtils;
import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.error.Mark;
import org.yaml.snakeyaml.error.MarkedYAMLException;
import org.yaml.snakeyaml.events.*;
import org.yaml.snakeyaml.parser.Parser;
@@ -71,15 +77,24 @@
import java.io.ByteArrayInputStream;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Map;

@CoreClass(name = "Truffle::Psych::Parser")
@CoreClass(name = "Psych::Parser")
public abstract class PsychParserNodes {

public static final int ANY_ENCODING = 0;
public static final int UTF8_ENCODING = 1;
public static final int UTF16LE_ENCODING = 2;
public static final int UTF16BE_ENCODING = 3;
public enum YAMLEncoding {
YAML_ANY_ENCODING(UTF8Encoding.INSTANCE),
YAML_UTF8_ENCODING(UTF8Encoding.INSTANCE),
YAML_UTF16LE_ENCODING(UTF16LEEncoding.INSTANCE),
YAML_UTF16BE_ENCODING(UTF16BEEncoding.INSTANCE), ;

YAMLEncoding(Encoding encoding) {
this.encoding = encoding;
}

public final Encoding encoding;
}

@CoreMethod(names = "allocate", constructor = true)
public abstract static class AllocateNode extends CoreMethodArrayArgumentsNode {
@@ -105,17 +120,12 @@ public ParseNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

@Specialization(guards = "isRubyString(yaml)")
@Specialization
public Object parse(DynamicObject parserObject, DynamicObject yaml, NotProvided path) {
return doParse(parserObject, yaml, nil());
}

@Specialization(guards = {"isRubyString(yaml)", "isNil(path)"})
public Object parseNil(DynamicObject parserObject, DynamicObject yaml, DynamicObject path) {
return doParse(parserObject, yaml, nil());
}

@Specialization(guards = {"isRubyString(yaml)", "isRubyString(path)"})
@Specialization
public Object parse(DynamicObject parserObject, DynamicObject yaml, DynamicObject path) {
return doParse(parserObject, yaml, path);
}
@@ -128,7 +138,7 @@ private Object doParse(DynamicObject parserObject, DynamicObject yaml, DynamicOb

try {
parser = new ParserImpl(readerFor(yaml));
Layouts.PSYCH_PARSER_LAYOUT.setParser(parserObject, parser);
Layouts.PSYCH_PARSER.setParser(parserObject, parser);

if (isNil(path) && (boolean) ruby("yaml.respond_to? :path", "yaml", yaml)) {
path = (DynamicObject) ruby("yaml.path", "yaml", yaml);
@@ -138,11 +148,11 @@ private Object doParse(DynamicObject parserObject, DynamicObject yaml, DynamicOb

while (true) {
Event event = parser.getEvent();
Layouts.PSYCH_PARSER_LAYOUT.setEvent(parserObject, event);
Layouts.PSYCH_PARSER.setEvent(parserObject, event);

// FIXME: Event should expose a getID, so it can be switched
if (event.is(Event.ID.StreamStart)) {
invoke(handler, "start_stream", ANY_ENCODING);
invoke(handler, "start_stream", YAMLEncoding.YAML_ANY_ENCODING.ordinal());
} else if (event.is(Event.ID.DocumentStart)) {
handleDocumentStart((DocumentStartEvent) event, tainted, handler);
} else if (event.is(Event.ID.DocumentEnd)) {
@@ -169,23 +179,23 @@ private Object doParse(DynamicObject parserObject, DynamicObject yaml, DynamicOb
}
} catch (ParserException pe) {
parser = null;
Layouts.PSYCH_PARSER_LAYOUT.setParser(parserObject, parser);
Layouts.PSYCH_PARSER.setParser(parserObject, parser);
raiseParserException(yaml, pe, path);
} catch (ScannerException se) {
parser = null;
Layouts.PSYCH_PARSER_LAYOUT.setParser(parserObject, parser);
Layouts.PSYCH_PARSER.setParser(parserObject, parser);
StringBuilder message = new StringBuilder("syntax error");
if (se.getProblemMark() != null) {
message.append(se.getProblemMark().toString());
}
raiseParserException(yaml, se, path);
} catch (ReaderException re) {
parser = null;
Layouts.PSYCH_PARSER_LAYOUT.setParser(parserObject, parser);
Layouts.PSYCH_PARSER.setParser(parserObject, parser);
raiseParserException(yaml, re, path);
} catch (Throwable t) {
Helpers.throwException(t);
Layouts.PSYCH_PARSER_LAYOUT.setParser(parserObject, parser);
Layouts.PSYCH_PARSER.setParser(parserObject, parser);
return parserObject;
}

@@ -216,12 +226,11 @@ private StreamReader readerFor(DynamicObject yaml) {

// fall back on IOInputStream, using default charset
if ((boolean) ruby("yaml.respond_to? :read", "yaml", yaml)) {
Encoding enc = ((boolean) ruby("yaml.is_a? RubyIO", "yaml", yaml))
Encoding enc = ((boolean) ruby("yaml.is_a? IO", "yaml", yaml))
? UTF8Encoding.INSTANCE // ((RubyIO)yaml).getReadEncoding()
: UTF8Encoding.INSTANCE;
Charset charset = enc.getCharset();
throw new UnsupportedOperationException();
//return new StreamReader(new InputStreamReader(new IOInputStream(yaml), charset));
return new StreamReader(new InputStreamReader(new InputStreamAdapter(getContext(), yaml), charset));
} else {
throw new UnsupportedOperationException();
//throw runtime.newTypeError(yaml, runtime.getIO());
@@ -280,11 +289,25 @@ private void handleSequenceStart(SequenceStartEvent sse, boolean tainted, Object
}

private void raiseParserException(DynamicObject yaml, ReaderException re, DynamicObject rbPath) {
throw new UnsupportedOperationException();
ruby("raise Psych::SyntaxError.new(file, line, col, offset, problem, context)",
"file", rbPath,
"line", 0,
"col", 0,
"offset", re.getPosition(),
"problem", re.getName() == null ? nil() : Layouts.STRING.createString(getContext().getCoreLibrary().getStringFactory(), new ByteList(re.getName().getBytes(StandardCharsets.UTF_8)), StringSupport.CR_UNKNOWN, null),
"context", re.toString() == null ? nil() : Layouts.STRING.createString(getContext().getCoreLibrary().getStringFactory(), new ByteList(re.toString().getBytes(StandardCharsets.UTF_8)), StringSupport.CR_UNKNOWN, null));
}

private static void raiseParserException(DynamicObject yaml, MarkedYAMLException mye, DynamicObject rbPath) {
throw new UnsupportedOperationException();
private void raiseParserException(DynamicObject yaml, MarkedYAMLException mye, DynamicObject rbPath) {
final Mark mark = mye.getProblemMark();

ruby("raise Psych::SyntaxError.new(file, line, col, offset, problem, context)",
"file", rbPath,
"line", mark.getLine(),
"col", mark.getColumn(),
"offset", mark.getIndex(),
"problem", mye.getProblem() == null ? nil() : Layouts.STRING.createString(getContext().getCoreLibrary().getStringFactory(), new ByteList(mye.getProblem().getBytes(StandardCharsets.UTF_8)), StringSupport.CR_UNKNOWN, null),
"context", mye.getContext() == null ? nil() : Layouts.STRING.createString(getContext().getCoreLibrary().getStringFactory(), new ByteList(mye.getContext().getBytes(StandardCharsets.UTF_8)), StringSupport.CR_UNKNOWN, null));
}

private Object invoke(Object receiver, String name, Object... args) {
11 changes: 8 additions & 3 deletions truffle/src/main/java/org/jruby/truffle/runtime/RubyContext.java
Original file line number Diff line number Diff line change
@@ -350,17 +350,22 @@ public Object instanceEval(ByteList code, Object self, Node currentNode) {
}

@TruffleBoundary
public Object eval(String code, DynamicObject binding, boolean ownScopeForAssignments, String filename, Node currentNode) {
public Object eval(TranslatorDriver.ParserContext parserContext, String code, DynamicObject binding, boolean ownScopeForAssignments, String filename, Node currentNode) {
assert RubyGuards.isRubyBinding(binding);
return eval(ByteList.create(code), binding, ownScopeForAssignments, filename, currentNode);
return eval(parserContext, ByteList.create(code), binding, ownScopeForAssignments, filename, currentNode);
}

@TruffleBoundary
public Object eval(ByteList code, DynamicObject binding, boolean ownScopeForAssignments, String filename, Node currentNode) {
return eval(TranslatorDriver.ParserContext.EVAL, code, binding, ownScopeForAssignments, filename, currentNode);
}

@TruffleBoundary
public Object eval(TranslatorDriver.ParserContext parserContext, ByteList code, DynamicObject binding, boolean ownScopeForAssignments, String filename, Node currentNode) {
assert RubyGuards.isRubyBinding(binding);
final Source source = Source.fromText(code, filename);
final MaterializedFrame frame = Layouts.BINDING.getFrame(binding);
return execute(source, code.getEncoding(), TranslatorDriver.ParserContext.EVAL, RubyArguments.getSelf(frame.getArguments()), frame, ownScopeForAssignments, currentNode, NodeWrapper.IDENTITY);
return execute(source, code.getEncoding(), parserContext, RubyArguments.getSelf(frame.getArguments()), frame, ownScopeForAssignments, currentNode, NodeWrapper.IDENTITY);
}

@TruffleBoundary
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* 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.runtime.adapaters;

import com.oracle.truffle.api.object.DynamicObject;
import org.jruby.truffle.runtime.RubyContext;

import java.io.IOException;
import java.io.InputStream;

public class InputStreamAdapter extends InputStream {

private final RubyContext context;
private final DynamicObject object;

public InputStreamAdapter(RubyContext context, DynamicObject object) {
this.context = context;
this.object = object;
}

@Override
public int read() throws IOException {
final Object result = context.send(object, "getbyte", null);

if (result == context.getCoreLibrary().getNilObject()) {
return -1;
}

return (int) result;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* 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.runtime.adapaters;

import com.oracle.truffle.api.object.DynamicObject;
import org.jcodings.Encoding;
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.io.IOException;
import java.io.OutputStream;

public class OutputStreamAdapter extends OutputStream {

private final RubyContext context;
private final DynamicObject object;
private final Encoding encoding;

public OutputStreamAdapter(RubyContext context, DynamicObject object, Encoding encoding) {
this.context = context;
this.object = object;
this.encoding = encoding;
}

@Override
public void write(int bite) throws IOException {
context.send(object, "write", null, Layouts.STRING.createString(context.getCoreLibrary().getStringFactory(),
new ByteList(new byte[]{(byte) bite}, encoding),
StringSupport.CR_VALID, null));
}

}
Original file line number Diff line number Diff line change
@@ -433,10 +433,12 @@ public CoreLibrary(RubyContext context) {
defineModule(truffleModule, "Zlib");
defineModule(truffleModule, "ObjSpace");
defineModule(truffleModule, "Etc");
psychModule = defineModule(truffleModule, "Psych");
psychModule = defineModule("Psych");
psychParserClass = defineClass(psychModule, objectClass, "Parser");
Layouts.CLASS.setInstanceFactoryUnsafe(psychParserClass, Layouts.PSYCH_PARSER_LAYOUT.createParserShape(psychParserClass, psychParserClass));
defineClass(psychModule, objectClass, "Emitter");
Layouts.CLASS.setInstanceFactoryUnsafe(psychParserClass, Layouts.PSYCH_PARSER.createParserShape(psychParserClass, psychParserClass));
final DynamicObject psychHandlerClass = defineClass(psychModule, objectClass, "Handler");
final DynamicObject psychEmitterClass = defineClass(psychModule, psychHandlerClass, "Emitter");
Layouts.CLASS.setInstanceFactoryUnsafe(psychEmitterClass, Layouts.PSYCH_EMITTER.createEmitterShape(psychEmitterClass, psychEmitterClass));

bigDecimalClass = defineClass(truffleModule, numericClass, "BigDecimal");
Layouts.CLASS.setInstanceFactoryUnsafe(bigDecimalClass, Layouts.BIG_DECIMAL.createBigDecimalShape(bigDecimalClass, bigDecimalClass));
@@ -636,10 +638,10 @@ private void initializeConstants() {
Layouts.MODULE.getFields(encodingConverterClass).setConstant(node, "XML_ATTR_CONTENT_DECORATOR", EConvFlags.XML_ATTR_CONTENT_DECORATOR);
Layouts.MODULE.getFields(encodingConverterClass).setConstant(node, "XML_ATTR_QUOTE_DECORATOR", EConvFlags.XML_ATTR_QUOTE_DECORATOR);

Layouts.MODULE.getFields(psychParserClass).setConstant(node, "ANY", PsychParserNodes.ANY_ENCODING);
Layouts.MODULE.getFields(psychParserClass).setConstant(node, "UTF8", PsychParserNodes.UTF8_ENCODING);
Layouts.MODULE.getFields(psychParserClass).setConstant(node, "UTF16LE", PsychParserNodes.UTF16LE_ENCODING);
Layouts.MODULE.getFields(psychParserClass).setConstant(node, "UTF16BE", PsychParserNodes.UTF16BE_ENCODING);
Layouts.MODULE.getFields(psychParserClass).setConstant(node, "ANY", PsychParserNodes.YAMLEncoding.YAML_ANY_ENCODING.ordinal());
Layouts.MODULE.getFields(psychParserClass).setConstant(node, "UTF8", PsychParserNodes.YAMLEncoding.YAML_UTF8_ENCODING.ordinal());
Layouts.MODULE.getFields(psychParserClass).setConstant(node, "UTF16LE", PsychParserNodes.YAMLEncoding.YAML_UTF16LE_ENCODING.ordinal());
Layouts.MODULE.getFields(psychParserClass).setConstant(node, "UTF16BE", PsychParserNodes.YAMLEncoding.YAML_UTF16BE_ENCODING.ordinal());
}

private void initializeSignalConstants() {
@@ -938,7 +940,6 @@ public DynamicObject breakFromProcClosure(Node currentNode) {

public DynamicObject unexpectedReturn(Node currentNode) {
CompilerAsserts.neverPartOfCompilation();
new Exception().printStackTrace();
return localJumpError("unexpected return", currentNode);
}

Original file line number Diff line number Diff line change
@@ -12,6 +12,8 @@
import com.oracle.truffle.api.object.HiddenKey;
import org.jruby.truffle.runtime.layouts.ext.BigDecimalLayout;
import org.jruby.truffle.runtime.layouts.ext.BigDecimalLayoutImpl;
import org.jruby.truffle.runtime.layouts.ext.psych.EmitterLayout;
import org.jruby.truffle.runtime.layouts.ext.psych.EmitterLayoutImpl;
import org.jruby.truffle.runtime.layouts.ext.psych.ParserLayout;
import org.jruby.truffle.runtime.layouts.ext.psych.ParserLayoutImpl;
import org.jruby.truffle.runtime.layouts.rubinius.*;
@@ -53,7 +55,8 @@ public abstract class Layouts {
public static final TimeLayout TIME = TimeLayoutImpl.INSTANCE;
public static final UnboundMethodLayout UNBOUND_METHOD = UnboundMethodLayoutImpl.INSTANCE;
public static final WeakRefLayout WEAK_REF_LAYOUT = WeakRefLayoutImpl.INSTANCE;
public static final ParserLayout PSYCH_PARSER_LAYOUT = ParserLayoutImpl.INSTANCE;
public static final ParserLayout PSYCH_PARSER = ParserLayoutImpl.INSTANCE;
public static final EmitterLayout PSYCH_EMITTER = EmitterLayoutImpl.INSTANCE;

// Other standard identifiers

Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* 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.runtime.layouts.ext.psych;

import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.object.DynamicObjectFactory;
import org.jruby.truffle.om.dsl.api.Layout;
import org.jruby.truffle.om.dsl.api.Nullable;
import org.jruby.truffle.runtime.layouts.BasicObjectLayout;
import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.emitter.Emitter;
import org.yaml.snakeyaml.events.Event;
import org.yaml.snakeyaml.parser.Parser;

@Layout
public interface EmitterLayout extends BasicObjectLayout {

DynamicObjectFactory createEmitterShape(DynamicObject logicalClass,
DynamicObject metaClass);

DynamicObject createEmitter(DynamicObjectFactory factory,
@Nullable Emitter emitter,
@Nullable DumperOptions options,
@Nullable Object io);

boolean isEmitter(DynamicObject object);

Emitter getEmitter(DynamicObject object);
void setEmitter(DynamicObject object, Emitter emitter);

DumperOptions getOptions(DynamicObject object);
void setOptions(DynamicObject object, DumperOptions options);

Object getIo(DynamicObject object);
void setIo(DynamicObject object, Object io);

}
Original file line number Diff line number Diff line change
@@ -1135,12 +1135,6 @@ public RubyNode visitDefsNode(org.jruby.ast.DefsNode node) {
}

protected RubyNode translateMethodDefinition(SourceSection sourceSection, RubyNode classNode, String methodName, org.jruby.ast.Node parseTree, org.jruby.ast.ArgsNode argsNode, org.jruby.ast.Node bodyNode) {
// Psych calls method names generated from class hierarchies. We have Truffle::Psych, so we need to adapt

if (methodName.startsWith("visit_Psych_Nodes_")) {
methodName = "visit_Truffle_Psych_Nodes_" + methodName.substring("visit_Psych_Nodes_".length());
}

final SharedMethodInfo sharedMethodInfo = new SharedMethodInfo(sourceSection, environment.getLexicalScope(), MethodTranslator.getArity(argsNode), methodName, false, Helpers.argsNodeToArgumentDescriptors(parseTree.findFirstChild(ArgsNode.class)), false);

final TranslatorEnvironment newEnvironment = new TranslatorEnvironment(
Original file line number Diff line number Diff line change
@@ -41,7 +41,7 @@
public class TranslatorDriver {

public static enum ParserContext {
TOP_LEVEL, SHELL, MODULE, EVAL
TOP_LEVEL, SHELL, MODULE, EVAL, INLINE
}

private final ParseEnvironment parseEnvironment;
@@ -167,7 +167,7 @@ private RubyRootNode parse(Node currentNode, RubyContext context, Source source,

// Catch return

if (parserContext != ParserContext.EVAL) {
if (parserContext != ParserContext.INLINE) {
truffleNode = new CatchReturnAsErrorNode(context, truffleNode.getSourceSection(), truffleNode);
}

3 changes: 3 additions & 0 deletions truffle/src/main/ruby/core.rb
Original file line number Diff line number Diff line change
@@ -282,3 +282,6 @@ def self.omit(reason)
require_relative 'core/truffle/cext/cext'
require_relative 'core/truffle/cext/mkmf'
require_relative 'core/truffle/cext/require'

require_relative 'core/post'

16 changes: 16 additions & 0 deletions truffle/src/main/ruby/core/post.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# 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

# We defined Psych at the top level becuase several things depend on its name.
# Here we fix that up and put it back into Truffle.

Truffle::Psych = Psych

class Object
remove_const :Psych
end