Skip to content

Commit a8d608a

Browse files
committed
Merge branch 'master' into truffle-head
2 parents 15473b8 + 156c62d commit a8d608a

File tree

27 files changed

+221
-263
lines changed

27 files changed

+221
-263
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ nbproject/private
9393

9494
# Eclipse project files
9595
/.metadata
96+
core/.classpath
97+
core/.project
98+
core/.settings
9699

97100
# Truffle benchmark stuff
98101
reference.txt

core/.classpath

Lines changed: 0 additions & 53 deletions
This file was deleted.

core/.project

Lines changed: 0 additions & 14 deletions
This file was deleted.

core/.settings/org.eclipse.jdt.apt.core.prefs

Lines changed: 0 additions & 4 deletions
This file was deleted.

core/.settings/org.eclipse.jdt.core.prefs

Lines changed: 0 additions & 18 deletions
This file was deleted.

core/.settings/org.eclipse.jdt.ui.prefs

Lines changed: 0 additions & 60 deletions
This file was deleted.

core/src/main/java/org/jruby/truffle/TruffleBridgeImpl.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@
1313
import com.oracle.truffle.api.source.Source;
1414
import com.oracle.truffle.api.Truffle;
1515
import com.oracle.truffle.api.frame.MaterializedFrame;
16+
import com.oracle.truffle.api.source.SourceSection;
1617
import org.jruby.TruffleBridge;
1718
import org.jruby.runtime.builtin.IRubyObject;
1819
import org.jruby.truffle.nodes.RubyNode;
1920
import org.jruby.truffle.nodes.TopLevelRaiseHandler;
21+
import org.jruby.truffle.nodes.control.SequenceNode;
2022
import org.jruby.truffle.nodes.core.*;
2123
import org.jruby.truffle.runtime.core.*;
2224
import org.jruby.truffle.runtime.RubyContext;
@@ -143,7 +145,11 @@ public Object execute(final TranslatorDriver.ParserContext parserContext, final
143145
return truffleContext.execute(truffleContext, source, parserContext, self, parentFrame, null, new NodeWrapper() {
144146
@Override
145147
public RubyNode wrap(RubyNode node) {
146-
return new TopLevelRaiseHandler(node.getContext(), node.getSourceSection(), node);
148+
RubyContext context = node.getContext();
149+
SourceSection sourceSection = node.getSourceSection();
150+
return SequenceNode.sequence(context, sourceSection,
151+
new SetTopLevelBindingNode(context, sourceSection),
152+
new TopLevelRaiseHandler(context, sourceSection, node));
147153
}
148154
});
149155
}

core/src/main/java/org/jruby/truffle/nodes/core/KernelNodes.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1606,6 +1606,34 @@ public boolean require(RubyString feature) {
16061606
}
16071607
}
16081608

1609+
@CoreMethod(names = "require_relative", isModuleFunction = true, required = 1)
1610+
public abstract static class RequireRelativeNode extends CoreMethodNode {
1611+
1612+
public RequireRelativeNode(RubyContext context, SourceSection sourceSection) {
1613+
super(context, sourceSection);
1614+
}
1615+
1616+
public RequireRelativeNode(RequireRelativeNode prev) {
1617+
super(prev);
1618+
}
1619+
1620+
@Specialization
1621+
public boolean require(VirtualFrame frame, RubyString feature) {
1622+
notDesignedForCompilation();
1623+
1624+
final String sourcePath = Truffle.getRuntime().getCallerFrame().getCallNode().getEncapsulatingSourceSection().getSource().getPath();
1625+
final String directoryPath = new File(sourcePath).getParent();
1626+
1627+
try {
1628+
getContext().getFeatureManager().requireInPath(directoryPath, feature.toString(), this);
1629+
} catch (IOException e) {
1630+
throw new RuntimeException(e);
1631+
}
1632+
1633+
return true;
1634+
}
1635+
}
1636+
16091637
@CoreMethod(names = "respond_to?", required = 1, optional = 1)
16101638
public abstract static class RespondToNode extends CoreMethodNode {
16111639

core/src/main/java/org/jruby/truffle/runtime/core/CoreLibrary.java

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import com.oracle.truffle.api.source.Source;
1616
import org.jcodings.Encoding;
1717
import org.jcodings.EncodingDB;
18+
import org.jruby.embed.variable.Constant;
1819
import org.jruby.runtime.Constants;
1920
import org.jruby.runtime.Visibility;
2021
import org.jruby.runtime.encoding.EncodingService;
@@ -239,10 +240,10 @@ public void initialize() {
239240

240241
// Set constants
241242

242-
objectClass.setConstant(null, "RUBY_VERSION", RubyString.fromJavaString(stringClass, "2.1.0"));
243-
objectClass.setConstant(null, "RUBY_PATCHLEVEL", 0);
244-
objectClass.setConstant(null, "RUBY_ENGINE", RubyString.fromJavaString(stringClass, "jrubytruffle"));
245-
objectClass.setConstant(null, "RUBY_PLATFORM", RubyString.fromJavaString(stringClass, "jvm"));
243+
objectClass.setConstant(null, "RUBY_VERSION", RubyString.fromJavaString(stringClass, Constants.RUBY_VERSION));
244+
objectClass.setConstant(null, "RUBY_PATCHLEVEL", Constants.RUBY_PATCHLEVEL);
245+
objectClass.setConstant(null, "RUBY_ENGINE", RubyString.fromJavaString(stringClass, Constants.ENGINE + "+truffle"));
246+
objectClass.setConstant(null, "RUBY_PLATFORM", RubyString.fromJavaString(stringClass, Constants.PLATFORM));
246247

247248
final LinkedHashMap<Object, Object> configHashMap = new LinkedHashMap<>();
248249
configHashMap.put(RubyString.fromJavaString(stringClass, "ruby_install_name"), RubyString.fromJavaString(stringClass, "rubytruffle"));
@@ -288,20 +289,10 @@ public void initialize() {
288289
envHash = getSystemEnv();
289290
objectClass.setConstant(null, "ARGV", argv);
290291
objectClass.setConstant(null, "ENV", envHash);
291-
objectClass.setConstant(null, "TRUE", true);
292-
objectClass.setConstant(null, "FALSE", false);
293-
objectClass.setConstant(null, "NIL", nilObject);
294292

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

298-
floatClass.setConstant(null, "EPSILON", org.jruby.RubyFloat.EPSILON);
299-
floatClass.setConstant(null, "INFINITY", org.jruby.RubyFloat.INFINITY);
300-
floatClass.setConstant(null, "NAN", org.jruby.RubyFloat.NAN);
301-
302-
mathModule.setConstant(null, "PI", Math.PI);
303-
mathModule.setConstant(null, "E", Math.E);
304-
305296
fileClass.setConstant(null, "SEPARATOR", RubyString.fromJavaString(stringClass, File.separator));
306297
fileClass.setConstant(null, "Separator", RubyString.fromJavaString(stringClass, File.separator));
307298
fileClass.setConstant(null, "ALT_SEPARATOR", nilObject);
@@ -316,24 +307,18 @@ public void initializeAfterMethodsAdded() {
316307
objectClass.setConstant(null, "RUBY_RELEASE_DATE", context.makeString(Constants.COMPILE_DATE));
317308
objectClass.setConstant(null, "RUBY_DESCRIPTION", context.makeString(OutputStrings.getVersionString()));
318309

319-
if (Options.TRUFFLE_LOAD_CORE.load()) {
320-
final String[] files = new String[]{
321-
"jruby/truffle/core/kernel.rb"
322-
};
310+
rubiniusLibrary = new RubiniusLibrary(this);
323311

324-
for (String file : files) {
325-
loadRubyCore(file);
326-
}
312+
if (Options.TRUFFLE_LOAD_CORE.load()) {
313+
loadRubyCore("jruby/truffle/core.rb");
327314
}
328-
329-
rubiniusLibrary = new RubiniusLibrary(this);
330315
}
331316

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

335320
try {
336-
source = Source.fromReader(new InputStreamReader(context.getRuntime().getLoadService().getClassPathResource(context.getRuntime().getJRubyClassLoader(), fileName).getInputStream()), fileName);
321+
source = Source.fromReader(new InputStreamReader(context.getRuntime().getLoadService().getClassPathResource(context.getRuntime().getJRubyClassLoader(), fileName).getInputStream()), "core:/" + fileName);
337322
} catch (IOException e) {
338323
throw new RuntimeException(e);
339324
}

core/src/main/java/org/jruby/truffle/runtime/rubinius/RubiniusLibrary.java

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -63,21 +63,6 @@ public RubiniusLibrary(CoreLibrary coreLib) {
6363
vmExceptionClass = new RubyClass(context, rubiniusModule, coreLib.getExceptionClass(), "VMException");
6464
objectBoundsExceededErrorClass = new RubyClass(context, rubiniusModule, vmExceptionClass, "ObjectBoundsExceededError");
6565
assertionErrorClass = new RubyClass(context, rubiniusModule, vmExceptionClass, "AssertionError");
66-
67-
final String[] files = new String[]{
68-
"jruby/truffle/core/rubinius/api/bootstrap/channel.rb",
69-
"jruby/truffle/core/rubinius/api/common/bytearray.rb",
70-
"jruby/truffle/core/rubinius/api/common/channel.rb",
71-
"jruby/truffle/core/rubinius/api/common/thread.rb",
72-
"jruby/truffle/core/rubinius/api/common/tuple.rb",
73-
"jruby/truffle/core/rubinius/api/common/type.rb",
74-
"jruby/truffle/core/rubinius/kernel/common/struct.rb"
75-
//"jruby/truffle/core/rubinius/kernel/common/time.rb"
76-
};
77-
78-
for (String file : files) {
79-
coreLib.loadRubyCore(file);
80-
}
8166
}
8267

8368
// helper function, should maybe be moved elsewhere

core/src/main/java/org/jruby/truffle/runtime/subsystems/FeatureManager.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import java.net.*;
1414
import java.util.Arrays;
1515

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

141-
if (new File(fileName).isFile()) {
142+
if (fileName.startsWith("core:/")) {
143+
try {
144+
context.getCoreLibrary().loadRubyCore(fileName.substring("core:/".length()));
145+
return true;
146+
} catch (Exception e) {
147+
// TODO(CS): obviously not the best way to do this
148+
return false;
149+
}
150+
} else if (new File(fileName).isFile()) {
142151
context.loadFile(fileName, currentNode);
143152
context.getCoreLibrary().getLoadedFeatures().slowPush(context.makeString(fileName));
144153
return true;

core/src/main/java/org/jruby/truffle/translator/TranslatorDriver.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,6 @@ public RubyRootNode parse(RubyNode currentNode, RubyContext context, Source sour
186186

187187
truffleNode = wrapper.wrap(truffleNode);
188188

189-
// Binding
190-
191-
truffleNode = SequenceNode.sequence(context, sourceSection, new SetTopLevelBindingNode(context, sourceSection), truffleNode);
192-
193189
// Shell result
194190

195191
return new RubyRootNode(context, truffleNode.getSourceSection(), environment.getFrameDescriptor(), sharedMethodInfo, truffleNode);
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Copyright (c) 2014 Oracle and/or its affiliates. All rights reserved. This
2+
# code is released under a tri EPL/GPL/LGPL license. You can use it,
3+
# redistribute it and/or modify it under the terms of the:
4+
#
5+
# Eclipse Public License version 1.0
6+
# GNU General Public License version 2
7+
# GNU Lesser General Public License version 2.1
8+
9+
require_relative 'core/main'
10+
require_relative 'core/kernel'
11+
require_relative 'core/float'
12+
require_relative 'core/math'
13+
14+
require_relative 'core/rubinius/api/bootstrap/channel'
15+
require_relative 'core/rubinius/api/common/bytearray'
16+
require_relative 'core/rubinius/api/common/channel'
17+
require_relative 'core/rubinius/api/common/thread'
18+
require_relative 'core/rubinius/api/common/tuple'
19+
require_relative 'core/rubinius/api/common/type'
20+
require_relative 'core/rubinius/kernel/common/struct'
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Copyright (c) 2014 Oracle and/or its affiliates. All rights reserved. This
2+
# code is released under a tri EPL/GPL/LGPL license. You can use it,
3+
# redistribute it and/or modify it under the terms of the:
4+
#
5+
# Eclipse Public License version 1.0
6+
# GNU General Public License version 2
7+
# GNU Lesser General Public License version 2.1
8+
9+
class Float
10+
11+
NAN = 0.0 / 0.0
12+
INFINITY = 1.0 / 0.0
13+
EPSILON = 2.2204460492503131e-16
14+
15+
end

0 commit comments

Comments
 (0)