Skip to content

Commit

Permalink
Merge branch 'master' into truffle-head
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisseaton committed Dec 15, 2014
2 parents 15473b8 + 156c62d commit a8d608a
Show file tree
Hide file tree
Showing 27 changed files with 221 additions and 263 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -93,6 +93,9 @@ nbproject/private

# Eclipse project files
/.metadata
core/.classpath
core/.project
core/.settings

# Truffle benchmark stuff
reference.txt
53 changes: 0 additions & 53 deletions core/.classpath

This file was deleted.

14 changes: 0 additions & 14 deletions core/.project

This file was deleted.

4 changes: 0 additions & 4 deletions core/.settings/org.eclipse.jdt.apt.core.prefs

This file was deleted.

18 changes: 0 additions & 18 deletions core/.settings/org.eclipse.jdt.core.prefs

This file was deleted.

60 changes: 0 additions & 60 deletions core/.settings/org.eclipse.jdt.ui.prefs

This file was deleted.

8 changes: 7 additions & 1 deletion core/src/main/java/org/jruby/truffle/TruffleBridgeImpl.java
Expand Up @@ -13,10 +13,12 @@
import com.oracle.truffle.api.source.Source;
import com.oracle.truffle.api.Truffle;
import com.oracle.truffle.api.frame.MaterializedFrame;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.TruffleBridge;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.TopLevelRaiseHandler;
import org.jruby.truffle.nodes.control.SequenceNode;
import org.jruby.truffle.nodes.core.*;
import org.jruby.truffle.runtime.core.*;
import org.jruby.truffle.runtime.RubyContext;
Expand Down Expand Up @@ -143,7 +145,11 @@ public Object execute(final TranslatorDriver.ParserContext parserContext, final
return truffleContext.execute(truffleContext, source, parserContext, self, parentFrame, null, new NodeWrapper() {
@Override
public RubyNode wrap(RubyNode node) {
return new TopLevelRaiseHandler(node.getContext(), node.getSourceSection(), node);
RubyContext context = node.getContext();
SourceSection sourceSection = node.getSourceSection();
return SequenceNode.sequence(context, sourceSection,
new SetTopLevelBindingNode(context, sourceSection),
new TopLevelRaiseHandler(context, sourceSection, node));
}
});
}
Expand Down
28 changes: 28 additions & 0 deletions core/src/main/java/org/jruby/truffle/nodes/core/KernelNodes.java
Expand Up @@ -1606,6 +1606,34 @@ public boolean require(RubyString feature) {
}
}

@CoreMethod(names = "require_relative", isModuleFunction = true, required = 1)
public abstract static class RequireRelativeNode extends CoreMethodNode {

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

public RequireRelativeNode(RequireRelativeNode prev) {
super(prev);
}

@Specialization
public boolean require(VirtualFrame frame, RubyString feature) {
notDesignedForCompilation();

final String sourcePath = Truffle.getRuntime().getCallerFrame().getCallNode().getEncapsulatingSourceSection().getSource().getPath();
final String directoryPath = new File(sourcePath).getParent();

try {
getContext().getFeatureManager().requireInPath(directoryPath, feature.toString(), this);
} catch (IOException e) {
throw new RuntimeException(e);
}

return true;
}
}

@CoreMethod(names = "respond_to?", required = 1, optional = 1)
public abstract static class RespondToNode extends CoreMethodNode {

Expand Down
33 changes: 9 additions & 24 deletions core/src/main/java/org/jruby/truffle/runtime/core/CoreLibrary.java
Expand Up @@ -15,6 +15,7 @@
import com.oracle.truffle.api.source.Source;
import org.jcodings.Encoding;
import org.jcodings.EncodingDB;
import org.jruby.embed.variable.Constant;
import org.jruby.runtime.Constants;
import org.jruby.runtime.Visibility;
import org.jruby.runtime.encoding.EncodingService;
Expand Down Expand Up @@ -239,10 +240,10 @@ public void initialize() {

// Set constants

objectClass.setConstant(null, "RUBY_VERSION", RubyString.fromJavaString(stringClass, "2.1.0"));
objectClass.setConstant(null, "RUBY_PATCHLEVEL", 0);
objectClass.setConstant(null, "RUBY_ENGINE", RubyString.fromJavaString(stringClass, "jrubytruffle"));
objectClass.setConstant(null, "RUBY_PLATFORM", RubyString.fromJavaString(stringClass, "jvm"));
objectClass.setConstant(null, "RUBY_VERSION", RubyString.fromJavaString(stringClass, Constants.RUBY_VERSION));
objectClass.setConstant(null, "RUBY_PATCHLEVEL", Constants.RUBY_PATCHLEVEL);
objectClass.setConstant(null, "RUBY_ENGINE", RubyString.fromJavaString(stringClass, Constants.ENGINE + "+truffle"));
objectClass.setConstant(null, "RUBY_PLATFORM", RubyString.fromJavaString(stringClass, Constants.PLATFORM));

final LinkedHashMap<Object, Object> configHashMap = new LinkedHashMap<>();
configHashMap.put(RubyString.fromJavaString(stringClass, "ruby_install_name"), RubyString.fromJavaString(stringClass, "rubytruffle"));
Expand Down Expand Up @@ -288,20 +289,10 @@ public void initialize() {
envHash = getSystemEnv();
objectClass.setConstant(null, "ARGV", argv);
objectClass.setConstant(null, "ENV", envHash);
objectClass.setConstant(null, "TRUE", true);
objectClass.setConstant(null, "FALSE", false);
objectClass.setConstant(null, "NIL", nilObject);

final RubyHash configHash = new RubyHash(hashClass, null, null, configHashMap, 0);
configModule.setConstant(null, "CONFIG", configHash);

floatClass.setConstant(null, "EPSILON", org.jruby.RubyFloat.EPSILON);
floatClass.setConstant(null, "INFINITY", org.jruby.RubyFloat.INFINITY);
floatClass.setConstant(null, "NAN", org.jruby.RubyFloat.NAN);

mathModule.setConstant(null, "PI", Math.PI);
mathModule.setConstant(null, "E", Math.E);

fileClass.setConstant(null, "SEPARATOR", RubyString.fromJavaString(stringClass, File.separator));
fileClass.setConstant(null, "Separator", RubyString.fromJavaString(stringClass, File.separator));
fileClass.setConstant(null, "ALT_SEPARATOR", nilObject);
Expand All @@ -316,24 +307,18 @@ public void initializeAfterMethodsAdded() {
objectClass.setConstant(null, "RUBY_RELEASE_DATE", context.makeString(Constants.COMPILE_DATE));
objectClass.setConstant(null, "RUBY_DESCRIPTION", context.makeString(OutputStrings.getVersionString()));

if (Options.TRUFFLE_LOAD_CORE.load()) {
final String[] files = new String[]{
"jruby/truffle/core/kernel.rb"
};
rubiniusLibrary = new RubiniusLibrary(this);

for (String file : files) {
loadRubyCore(file);
}
if (Options.TRUFFLE_LOAD_CORE.load()) {
loadRubyCore("jruby/truffle/core.rb");
}

rubiniusLibrary = new RubiniusLibrary(this);
}

public void loadRubyCore(String fileName) {
final Source source;

try {
source = Source.fromReader(new InputStreamReader(context.getRuntime().getLoadService().getClassPathResource(context.getRuntime().getJRubyClassLoader(), fileName).getInputStream()), fileName);
source = Source.fromReader(new InputStreamReader(context.getRuntime().getLoadService().getClassPathResource(context.getRuntime().getJRubyClassLoader(), fileName).getInputStream()), "core:/" + fileName);
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand Down
Expand Up @@ -63,21 +63,6 @@ public RubiniusLibrary(CoreLibrary coreLib) {
vmExceptionClass = new RubyClass(context, rubiniusModule, coreLib.getExceptionClass(), "VMException");
objectBoundsExceededErrorClass = new RubyClass(context, rubiniusModule, vmExceptionClass, "ObjectBoundsExceededError");
assertionErrorClass = new RubyClass(context, rubiniusModule, vmExceptionClass, "AssertionError");

final String[] files = new String[]{
"jruby/truffle/core/rubinius/api/bootstrap/channel.rb",
"jruby/truffle/core/rubinius/api/common/bytearray.rb",
"jruby/truffle/core/rubinius/api/common/channel.rb",
"jruby/truffle/core/rubinius/api/common/thread.rb",
"jruby/truffle/core/rubinius/api/common/tuple.rb",
"jruby/truffle/core/rubinius/api/common/type.rb",
"jruby/truffle/core/rubinius/kernel/common/struct.rb"
//"jruby/truffle/core/rubinius/kernel/common/time.rb"
};

for (String file : files) {
coreLib.loadRubyCore(file);
}
}

// helper function, should maybe be moved elsewhere
Expand Down
Expand Up @@ -13,6 +13,7 @@
import java.net.*;
import java.util.Arrays;

import com.oracle.truffle.api.Truffle;
import com.oracle.truffle.api.source.Source;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.runtime.*;
Expand Down Expand Up @@ -138,7 +139,15 @@ private boolean requireFile(String fileName, RubyNode currentNode) throws IOExce
* is a valid file name, as well as a valid URL. We try as a file path first.
*/

if (new File(fileName).isFile()) {
if (fileName.startsWith("core:/")) {
try {
context.getCoreLibrary().loadRubyCore(fileName.substring("core:/".length()));
return true;
} catch (Exception e) {
// TODO(CS): obviously not the best way to do this
return false;
}
} else if (new File(fileName).isFile()) {
context.loadFile(fileName, currentNode);
context.getCoreLibrary().getLoadedFeatures().slowPush(context.makeString(fileName));
return true;
Expand Down
Expand Up @@ -186,10 +186,6 @@ public RubyRootNode parse(RubyNode currentNode, RubyContext context, Source sour

truffleNode = wrapper.wrap(truffleNode);

// Binding

truffleNode = SequenceNode.sequence(context, sourceSection, new SetTopLevelBindingNode(context, sourceSection), truffleNode);

// Shell result

return new RubyRootNode(context, truffleNode.getSourceSection(), environment.getFrameDescriptor(), sharedMethodInfo, truffleNode);
Expand Down
20 changes: 20 additions & 0 deletions core/src/main/ruby/jruby/truffle/core.rb
@@ -0,0 +1,20 @@
# Copyright (c) 2014 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

require_relative 'core/main'
require_relative 'core/kernel'
require_relative 'core/float'
require_relative 'core/math'

require_relative 'core/rubinius/api/bootstrap/channel'
require_relative 'core/rubinius/api/common/bytearray'
require_relative 'core/rubinius/api/common/channel'
require_relative 'core/rubinius/api/common/thread'
require_relative 'core/rubinius/api/common/tuple'
require_relative 'core/rubinius/api/common/type'
require_relative 'core/rubinius/kernel/common/struct'
15 changes: 15 additions & 0 deletions core/src/main/ruby/jruby/truffle/core/float.rb
@@ -0,0 +1,15 @@
# Copyright (c) 2014 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

class Float

NAN = 0.0 / 0.0
INFINITY = 1.0 / 0.0
EPSILON = 2.2204460492503131e-16

end

0 comments on commit a8d608a

Please sign in to comment.