Skip to content

Commit

Permalink
Showing 27 changed files with 221 additions and 263 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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;
@@ -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));
}
});
}
28 changes: 28 additions & 0 deletions core/src/main/java/org/jruby/truffle/nodes/core/KernelNodes.java
Original file line number Diff line number Diff line change
@@ -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 {

33 changes: 9 additions & 24 deletions core/src/main/java/org/jruby/truffle/runtime/core/CoreLibrary.java
Original file line number Diff line number Diff line change
@@ -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;
@@ -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"));
@@ -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);
@@ -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);
}
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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.*;
@@ -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;
Original file line number Diff line number Diff line change
@@ -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);
20 changes: 20 additions & 0 deletions core/src/main/ruby/jruby/truffle/core.rb
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
67 changes: 4 additions & 63 deletions core/src/main/ruby/jruby/truffle/core/kernel.rb
Original file line number Diff line number Diff line change
@@ -8,6 +8,10 @@

module Kernel

def itself
self
end

module_function

def p(*args)
@@ -44,69 +48,6 @@ def Complex(real, imaginary)

end

# Standard file handle shims

module STDIN
def self.external_encoding
@external || Encoding.default_external
end

def self.internal_encoding
@internal
end

def self.set_encoding(external, internal)
@external = external
@internal = internal
end
end

module STDOUT
def self.print(*values)
Kernel.send(:print, *values)
end

def self.write(value)
print value
end

def self.flush
Truffle::Debug.flush_stdout
end

def self.external_encoding
@external
end

def self.internal_encoding
@internal
end

def self.set_encoding(external, internal)
@external = external
@internal = internal
end
end

$stdout = STDOUT

module STDERR
def self.external_encoding
@external
end

def self.internal_encoding
@internal
end

def self.set_encoding(external, internal)
@external = external
@internal = internal
end
end

ARGF = Object.new

# Here temporarily while we adapt to the newly imported specs

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

NIL = nil
TRUE = true
FALSE = false

module STDIN
def self.external_encoding
@external || Encoding.default_external
end

def self.internal_encoding
@internal
end

def self.set_encoding(external, internal)
@external = external
@internal = internal
end
end

module STDOUT
def self.print(*values)
Kernel.send(:print, *values)
end

def self.write(value)
print value
end

def self.flush
Truffle::Debug.flush_stdout
end

def self.external_encoding
@external
end

def self.internal_encoding
@internal
end

def self.set_encoding(external, internal)
@external = external
@internal = internal
end
end

$stdout = STDOUT

module STDERR
def self.external_encoding
@external
end

def self.internal_encoding
@internal
end

def self.set_encoding(external, internal)
@external = external
@internal = internal
end
end

ARGF = Object.new
14 changes: 14 additions & 0 deletions core/src/main/ruby/jruby/truffle/core/math.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# 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

module Math

PI = 3.14159265358979323846
E = 2.7182818284590452354

end
22 changes: 22 additions & 0 deletions core/src/main/ruby/jruby/truffle/core/rubinius/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
`kernel` contains the Ruby component of the Rubinius kernel (core library)
implementation, in some cases modified. We have taken files from version 2.4.1
of Rubinius. This code was written by Evan Phoenix, Brian Shirai, et al.

https://github.com/rubinius/rubinius

`api` contains code from `rubinius-core-api`, the Rubinius API implementation
written in Ruby, in some cases modified. We have taken files from commit
8d01207061518355da9b53274fe8766ecf85fdfe. This code was written by Evan Phoenix,
Charles Nutter, et al.

Some of the code from `rubinius-core-api` is also found at
`core/src/main/java/org/jruby/truffle/runtime/rubinius`, and again may be
modified.

https://github.com/rubinius/rubinius-core-api

We try not to modify files, so that they can easily be merged from upstream in
the future, but we have found it easier to modify inline in a few cases, rather
than somehow patch things from within JRuby+Truffle.

We have also directly attached copyright and license information to each file.
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:

#
# * Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:

#
# * Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:

#
# * Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:

#
# * Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:

#
# * Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:

#
# * Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice
1 change: 1 addition & 0 deletions spec/truffle/tags/core/dir/fileno_tags.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fails:Dir#fileno returns the file descriptor of the dir
2 changes: 2 additions & 0 deletions spec/truffle/tags/core/file/flock_tags.txt
Original file line number Diff line number Diff line change
@@ -3,3 +3,5 @@ fails:File#flock non-exclusively locks a file
fails:File#flock returns false if trying to lock an exclusively locked file
fails:File#flock blocks if trying to lock an exclusively locked file
fails:File#flock returns 0 if trying to lock a non-exclusively locked file
fails:File#flock fails with EBADF acquiring exclusive lock on read-only File
fails:File#flock fails with EBADF acquiring shared lock on read-only File
8 changes: 8 additions & 0 deletions test/truffle/test_methods_parity.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# 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

=begin
Run first with JRuby+Truffle, then with MRI:

0 comments on commit a8d608a

Please sign in to comment.