Skip to content

Commit

Permalink
Showing 66 changed files with 1,210 additions and 64 deletions.
1 change: 1 addition & 0 deletions lib/ruby/truffle/mri/psych.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require_relative '../../stdlib/' + File.basename(__FILE__)
1 change: 1 addition & 0 deletions lib/ruby/truffle/mri/psych/class_loader.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require_relative '../../../stdlib/psych/' + File.basename(__FILE__)
1 change: 1 addition & 0 deletions lib/ruby/truffle/mri/psych/coder.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require_relative '../../../stdlib/psych/' + File.basename(__FILE__)
1 change: 1 addition & 0 deletions lib/ruby/truffle/mri/psych/core_ext.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require_relative '../../../stdlib/psych/' + File.basename(__FILE__)
1 change: 1 addition & 0 deletions lib/ruby/truffle/mri/psych/deprecated.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require_relative '../../../stdlib/psych/' + File.basename(__FILE__)
1 change: 1 addition & 0 deletions lib/ruby/truffle/mri/psych/exception.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require_relative '../../../stdlib/psych/' + File.basename(__FILE__)
1 change: 1 addition & 0 deletions lib/ruby/truffle/mri/psych/handler.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require_relative '../../../stdlib/psych/' + File.basename(__FILE__)
1 change: 1 addition & 0 deletions lib/ruby/truffle/mri/psych/handlers/document_stream.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require_relative '../../../../stdlib/psych/handlers/' + File.basename(__FILE__)
1 change: 1 addition & 0 deletions lib/ruby/truffle/mri/psych/handlers/recorder.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require_relative '../../../../stdlib/psych/handlers/' + File.basename(__FILE__)
1 change: 1 addition & 0 deletions lib/ruby/truffle/mri/psych/json/ruby_events.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require_relative '../../../../stdlib/psych/json/' + File.basename(__FILE__)
1 change: 1 addition & 0 deletions lib/ruby/truffle/mri/psych/json/stream.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require_relative '../../../../stdlib/psych/json/' + File.basename(__FILE__)
1 change: 1 addition & 0 deletions lib/ruby/truffle/mri/psych/json/tree_builder.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require_relative '../../../../stdlib/psych/json/' + File.basename(__FILE__)
1 change: 1 addition & 0 deletions lib/ruby/truffle/mri/psych/json/yaml_events.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require_relative '../../../../stdlib/psych/json/' + File.basename(__FILE__)
1 change: 1 addition & 0 deletions lib/ruby/truffle/mri/psych/nodes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require_relative '../../../stdlib/psych/' + File.basename(__FILE__)
1 change: 1 addition & 0 deletions lib/ruby/truffle/mri/psych/nodes/alias.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require_relative '../../../../stdlib/psych/nodes/' + File.basename(__FILE__)
1 change: 1 addition & 0 deletions lib/ruby/truffle/mri/psych/nodes/document.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require_relative '../../../../stdlib/psych/nodes/' + File.basename(__FILE__)
1 change: 1 addition & 0 deletions lib/ruby/truffle/mri/psych/nodes/mapping.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require_relative '../../../../stdlib/psych/nodes/' + File.basename(__FILE__)
1 change: 1 addition & 0 deletions lib/ruby/truffle/mri/psych/nodes/node.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require_relative '../../../../stdlib/psych/nodes/' + File.basename(__FILE__)
1 change: 1 addition & 0 deletions lib/ruby/truffle/mri/psych/nodes/scalar.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require_relative '../../../../stdlib/psych/nodes/' + File.basename(__FILE__)
1 change: 1 addition & 0 deletions lib/ruby/truffle/mri/psych/nodes/sequence.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require_relative '../../../../stdlib/psych/nodes/' + File.basename(__FILE__)
1 change: 1 addition & 0 deletions lib/ruby/truffle/mri/psych/nodes/stream.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require_relative '../../../../stdlib/psych/nodes/' + File.basename(__FILE__)
1 change: 1 addition & 0 deletions lib/ruby/truffle/mri/psych/omap.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require_relative '../../../stdlib/psych/' + File.basename(__FILE__)
1 change: 1 addition & 0 deletions lib/ruby/truffle/mri/psych/parser.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require_relative '../../../stdlib/psych/' + File.basename(__FILE__)
1 change: 1 addition & 0 deletions lib/ruby/truffle/mri/psych/scalar_scanner.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require_relative '../../../stdlib/psych/' + File.basename(__FILE__)
1 change: 1 addition & 0 deletions lib/ruby/truffle/mri/psych/set.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require_relative '../../../stdlib/psych/' + File.basename(__FILE__)
1 change: 1 addition & 0 deletions lib/ruby/truffle/mri/psych/stream.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require_relative '../../../stdlib/psych/' + File.basename(__FILE__)
1 change: 1 addition & 0 deletions lib/ruby/truffle/mri/psych/streaming.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require_relative '../../../stdlib/psych/' + File.basename(__FILE__)
1 change: 1 addition & 0 deletions lib/ruby/truffle/mri/psych/syntax_error.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require_relative '../../../stdlib/psych/' + File.basename(__FILE__)
1 change: 1 addition & 0 deletions lib/ruby/truffle/mri/psych/tree_builder.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require_relative '../../../stdlib/psych/' + File.basename(__FILE__)
1 change: 1 addition & 0 deletions lib/ruby/truffle/mri/psych/versions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require_relative '../../../stdlib/psych/' + File.basename(__FILE__)
1 change: 1 addition & 0 deletions lib/ruby/truffle/mri/psych/visitors.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require_relative '../../../stdlib/psych/' + File.basename(__FILE__)
1 change: 1 addition & 0 deletions lib/ruby/truffle/mri/psych/visitors/depth_first.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require_relative '../../../../stdlib/psych/visitors/' + File.basename(__FILE__)
1 change: 1 addition & 0 deletions lib/ruby/truffle/mri/psych/visitors/emitter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require_relative '../../../../stdlib/psych/visitors/' + File.basename(__FILE__)
1 change: 1 addition & 0 deletions lib/ruby/truffle/mri/psych/visitors/json_tree.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require_relative '../../../../stdlib/psych/visitors/' + File.basename(__FILE__)
1 change: 1 addition & 0 deletions lib/ruby/truffle/mri/psych/visitors/to_ruby.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require_relative '../../../../stdlib/psych/visitors/' + File.basename(__FILE__)
1 change: 1 addition & 0 deletions lib/ruby/truffle/mri/psych/visitors/visitor.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require_relative '../../../../stdlib/psych/visitors/' + File.basename(__FILE__)
1 change: 1 addition & 0 deletions lib/ruby/truffle/mri/psych/visitors/yaml_tree.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require_relative '../../../../stdlib/psych/visitors/' + File.basename(__FILE__)
1 change: 1 addition & 0 deletions lib/ruby/truffle/mri/psych/y.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require_relative '../../../stdlib/psych/' + File.basename(__FILE__)
1 change: 1 addition & 0 deletions lib/ruby/truffle/mri/yaml.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require_relative '../../stdlib/' + File.basename(__FILE__)
28 changes: 28 additions & 0 deletions lib/ruby/truffle/truffle/truffle/psych.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# 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

Psych = Truffle::Psych

module Psych

def self.libyaml_version
# 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

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
1 change: 1 addition & 0 deletions truffle/pom.rb
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@

'jruby.basedir' => '${basedir}/..' )

jar 'org.yaml:snakeyaml:1.14'
jar 'org.jruby:jruby-core', '${project.version}', :scope => 'provided'

jar 'com.oracle:truffle:0.7'
5 changes: 5 additions & 0 deletions truffle/pom.xml
Original file line number Diff line number Diff line change
@@ -22,6 +22,11 @@ DO NOT MODIFIY - GENERATED CODE
<polyglot.dump.pom>pom.xml</polyglot.dump.pom>
</properties>
<dependencies>
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>1.14</version>
</dependency>
<dependency>
<groupId>org.jruby</groupId>
<artifactId>jruby-core</artifactId>
17 changes: 17 additions & 0 deletions truffle/src/main/java/org/jruby/truffle/nodes/RubyNode.java
Original file line number Diff line number Diff line change
@@ -9,6 +9,18 @@
*/
package org.jruby.truffle.nodes;

import com.oracle.truffle.api.CompilerAsserts;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.Truffle;
import com.oracle.truffle.api.dsl.ImportStatic;
import com.oracle.truffle.api.dsl.TypeSystemReference;
import com.oracle.truffle.api.frame.*;
import com.oracle.truffle.api.instrument.ProbeNode;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.nodes.UnexpectedResultException;
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.object.DynamicObjectFactory;
import com.oracle.truffle.api.source.SourceSection;
import jnr.ffi.provider.MemoryManager;
import jnr.posix.POSIX;

@@ -19,6 +31,7 @@
import org.jruby.truffle.runtime.core.StringOperations;
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;

@@ -211,6 +224,10 @@ public MemoryManager getMemoryManager() {

// ruby() helper

protected Object ruby(String expression, Object... arguments) {
return getContext().inlineRubyHelper(this, expression, arguments);
}

protected Object ruby(VirtualFrame frame, String expression, Object... arguments) {
return getContext().inlineRubyHelper(this, frame, expression, arguments);
}
Original file line number Diff line number Diff line change
@@ -1541,9 +1541,21 @@ public RubyNode coerceFeatureToPath(RubyNode feature) {

@Specialization(guards = "isRubyString(featureString)")
public boolean require(DynamicObject featureString) {
CompilerDirectives.transferToInterpreter();
final String feature = featureString.toString();

// Pysch loads either the jar or the so - we need to intercept

if (feature.equals("psych.so") && RubyCallStack.getCallerFrame(getContext()).getCallNode()
.getEncapsulatingSourceSection().getSource().getName().endsWith("psych.rb")) {
try {
getContext().getFeatureLoader().require("truffle/psych.rb", this);
} catch (IOException e) {
throw new RuntimeException(e);
}

return true;
}

// TODO CS 1-Mar-15 ERB will use strscan if it's there, but strscan is not yet complete, so we need to hide it

if (feature.equals("strscan") && RubyCallStack.getCallerFrame(getContext()).getCallNode()
Original file line number Diff line number Diff line change
@@ -541,6 +541,28 @@ public Object synchronize(VirtualFrame frame, DynamicObject self, DynamicObject
}
}

@CoreMethod(names = "print_backtrace", onSingleton = true)
public abstract static class PrintBacktraceNode extends CoreMethodNode {

public PrintBacktraceNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

@TruffleBoundary
@Specialization
public DynamicObject printBacktrace() {
final List<String> rubyBacktrace = BacktraceFormatter.createDefaultFormatter(getContext())
.formatBacktrace(null, RubyCallStack.getBacktrace(this));

for (String line : rubyBacktrace) {
System.err.println(line);
}

return nil();
}

}

@CoreMethod(names = "print_interleaved_backtrace", onSingleton = true)
public abstract static class PrintInterleavedBacktraceNode extends CoreMethodNode {

Large diffs are not rendered by default.

Large diffs are not rendered by default.

20 changes: 15 additions & 5 deletions truffle/src/main/java/org/jruby/truffle/runtime/RubyContext.java
Original file line number Diff line number Diff line change
@@ -217,10 +217,15 @@ public static Object debugEval(String code) {
return getLatestInstance().inlineRubyHelper(null, currentFrame, code);
}

@TruffleBoundary
public Object inlineRubyHelper(Node currentNode, String expression, Object... arguments) {
return inlineRubyHelper(currentNode, Truffle.getRuntime().getCurrentFrame().getFrame(FrameAccess.MATERIALIZE, true), expression, arguments);
}

public Object inlineRubyHelper(Node currentNode, Frame frame, String expression, Object... arguments) {
final MaterializedFrame evalFrame = setupInlineRubyFrame(frame, arguments);
final DynamicObject binding = Layouts.BINDING.createBinding(getCoreLibrary().getBindingFactory(), evalFrame);
return eval(expression, binding, true, "inline-ruby", currentNode);
return eval(TranslatorDriver.ParserContext.INLINE, expression, binding, true, "inline-ruby", currentNode);
}

private MaterializedFrame setupInlineRubyFrame(Frame frame, Object... arguments) {
@@ -231,7 +236,7 @@ private MaterializedFrame setupInlineRubyFrame(Frame frame, Object... arguments)
null,
RubyArguments.getSelf(frame.getArguments()),
null,
new Object[] {}),
new Object[]{}),
new FrameDescriptor(frame.getFrameDescriptor().getDefaultValue()));

if (arguments.length % 2 == 1) {
@@ -392,17 +397,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
@@ -34,6 +34,9 @@
import org.jruby.truffle.nodes.core.fixnum.FixnumNodesFactory;
import org.jruby.truffle.nodes.core.hash.HashNodesFactory;
import org.jruby.truffle.nodes.ext.*;
import org.jruby.truffle.nodes.ext.psych.PsychEmitterNodesFactory;
import org.jruby.truffle.nodes.ext.psych.PsychParserNodes;
import org.jruby.truffle.nodes.ext.psych.PsychParserNodesFactory;
import org.jruby.truffle.nodes.objects.FreezeNode;
import org.jruby.truffle.nodes.objects.FreezeNodeGen;
import org.jruby.truffle.nodes.objects.SingletonClassNode;
@@ -154,6 +157,8 @@ public class CoreLibrary {
private final DynamicObject weakRefClass;
private final DynamicObjectFactory weakRefFactory;
private final DynamicObject objectSpaceModule;
private final DynamicObject psychModule;
private final DynamicObject psychParserClass;
private final DynamicObject randomizerClass;
private final DynamicObjectFactory randomizerFactory;

@@ -430,6 +435,13 @@ public CoreLibrary(RubyContext context) {
defineModule(truffleModule, "Zlib");
defineModule(truffleModule, "ObjSpace");
defineModule(truffleModule, "Etc");
psychModule = defineModule("Psych");
psychParserClass = defineClass(psychModule, objectClass, "Parser");
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));

@@ -555,6 +567,8 @@ private void addCoreMethods() {
coreMethodNodeManager.addCoreMethodNodes(ZlibNodesFactory.getFactories());
coreMethodNodeManager.addCoreMethodNodes(ObjSpaceNodesFactory.getFactories());
coreMethodNodeManager.addCoreMethodNodes(EtcNodesFactory.getFactories());
coreMethodNodeManager.addCoreMethodNodes(PsychParserNodesFactory.getFactories());
coreMethodNodeManager.addCoreMethodNodes(PsychEmitterNodesFactory.getFactories());
Main.printTruffleTimeMetric("after-load-truffle-nodes");

coreMethodNodeManager.allMethodInstalled();
@@ -628,6 +642,11 @@ private void initializeConstants() {
Layouts.MODULE.getFields(encodingConverterClass).setConstant(node, "XML_TEXT_DECORATOR", EConvFlags.XML_TEXT_DECORATOR);
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.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() {
Original file line number Diff line number Diff line change
@@ -353,7 +353,7 @@ public void removeMethod(String methodName) {
public void undefMethod(Node currentNode, String methodName) {
final InternalMethod method = ModuleOperations.lookupMethod(rubyModuleObject, methodName);
if (method == null) {
throw new UnsupportedOperationException();
throw new RaiseException(getContext().getCoreLibrary().nameErrorUndefinedMethod(methodName, rubyModuleObject, currentNode));
} else {
undefMethod(currentNode, method);
}
Original file line number Diff line number Diff line change
@@ -12,6 +12,10 @@
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.*;

public abstract class Layouts {
@@ -51,6 +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 = ParserLayoutImpl.INSTANCE;
public static final EmitterLayout PSYCH_EMITTER = EmitterLayoutImpl.INSTANCE;
public static final RandomizerLayout RANDOMIZER = RandomizerLayoutImpl.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
@@ -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.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.events.Event;
import org.yaml.snakeyaml.parser.Parser;

@Layout
public interface ParserLayout extends BasicObjectLayout {

DynamicObjectFactory createParserShape(DynamicObject logicalClass,
DynamicObject metaClass);

DynamicObject createParser(DynamicObjectFactory factory,
@Nullable Parser parser,
@Nullable Event event);

boolean isParser(DynamicObject object);

Parser getParser(DynamicObject object);
void setParser(DynamicObject object, Parser parser);

Event getEvent(DynamicObject object);
void setEvent(DynamicObject object, Event event);

}
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,9 @@ private RubyRootNode parse(Node currentNode, RubyContext context, Source source,

// Catch return

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

// Catch retry

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'

Original file line number Diff line number Diff line change
@@ -6,24 +6,11 @@
# GNU General Public License version 2
# GNU Lesser General Public License version 2.1

module YAML
# 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.

def load(string)
raise "YAML.load not implemented"
end
module_function :load

def dump(object)
raise "YAML.dump not implemented"
end
module_function :dump

end
Truffle::Psych = Psych

class Object

def to_yaml
raise "Object#to_yaml not implemented"
end

remove_const :Psych
end

0 comments on commit 09cfe9b

Please sign in to comment.