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

Commits on Apr 28, 2016

  1. Copy the full SHA
    e643147 View commit details
  2. Copy the full SHA
    68e9995 View commit details
  3. [Truffle] Truffle::Fixnum.lower

    Might start in general putting Ruby core methods into X, and supporting methods into Truffle::X
    chrisseaton committed Apr 28, 2016
    Copy the full SHA
    2193aa5 View commit details
  4. [Truffle] Truffle::Safe

    chrisseaton committed Apr 28, 2016
    Copy the full SHA
    b96bdcf View commit details
16 changes: 8 additions & 8 deletions spec/truffle/specs/truffle/fixnum/and_spec.rb
Original file line number Diff line number Diff line change
@@ -11,30 +11,30 @@
describe "Fixnum#&" do
before :each do
@long = (1 << 48) + 1
@mask = Truffle.fixnum_lower((1 << 30) - 1)
@mask = Truffle::Fixnum.lower((1 << 30) - 1)
end

it "returns an int for (int, int)" do
result = (1 & 3)
result.should == 1
Truffle::Runtime.java_class_of(result).should == 'Integer'
Truffle.java_class_of(result).should == 'Integer'
end

it "returns an int for (long, int)" do
Truffle::Runtime.java_class_of(@long).should == 'Long'
Truffle::Runtime.java_class_of(@mask).should == 'Integer'
Truffle.java_class_of(@long).should == 'Long'
Truffle.java_class_of(@mask).should == 'Integer'

result = (@long & @mask)
result.should == 1
Truffle::Runtime.java_class_of(result).should == 'Integer'
Truffle.java_class_of(result).should == 'Integer'
end

it "returns an int for (int, long)" do
Truffle::Runtime.java_class_of(@long).should == 'Long'
Truffle::Runtime.java_class_of(@mask).should == 'Integer'
Truffle.java_class_of(@long).should == 'Long'
Truffle.java_class_of(@mask).should == 'Integer'

result = (@mask & @long)
result.should == 1
Truffle::Runtime.java_class_of(result).should == 'Integer'
Truffle.java_class_of(result).should == 'Integer'
end
end
Original file line number Diff line number Diff line change
@@ -6,36 +6,36 @@
# GNU General Public License version 2
# GNU Lesser General Public License version 2.1

require_relative '../../../../ruby/spec_helper'
require_relative '../../../ruby/spec_helper'

describe "Truffle::Runtime.java_class_of" do
describe "Truffle.java_class_of" do

it "returns a String" do
Truffle::Runtime.java_class_of(14).should be_kind_of(String)
Truffle.java_class_of(14).should be_kind_of(String)
end

it "returns 'Boolean' for true" do
Truffle::Runtime.java_class_of(true).should == 'Boolean'
Truffle.java_class_of(true).should == 'Boolean'
end

it "returns 'Boolean' for false" do
Truffle::Runtime.java_class_of(false).should == 'Boolean'
Truffle.java_class_of(false).should == 'Boolean'
end

it "returns 'Integer' for a small Fixnum" do
Truffle::Runtime.java_class_of(14).should == 'Integer'
Truffle.java_class_of(14).should == 'Integer'
end

it "returns 'Long' for a large Fixnum" do
Truffle::Runtime.java_class_of(0xffffffffffff).should == 'Long'
Truffle.java_class_of(0xffffffffffff).should == 'Long'
end

it "returns 'Double' for a Float" do
Truffle::Runtime.java_class_of(3.14).should == 'Double'
Truffle.java_class_of(3.14).should == 'Double'
end

it "returns 'DynamicObject*' for a String" do
Truffle::Runtime.java_class_of('test').start_with?('DynamicObject').should be_true
Truffle.java_class_of('test').start_with?('DynamicObject').should be_true
end

end
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@

require_relative '../../../../ruby/spec_helper'

describe "Truffle::Runtime.debug_print" do
describe "Truffle::Ropes.debug_print" do

it "needs to be reviewed for spec completeness"

Original file line number Diff line number Diff line change
@@ -8,18 +8,18 @@

require_relative '../../../../ruby/spec_helper'

describe "Truffle::Runtime.dump_string" do
describe "Truffle::Ropes.dump_string" do

it "returns a String" do
Truffle::Runtime.dump_string('foo').should be_kind_of(String)
Truffle::Ropes.dump_string('foo').should be_kind_of(String)
end

it "returns a sequence of escaped bytes in lower case" do
Truffle::Runtime.dump_string('foo').should =~ /(\\x[0-9a-f][0-9a-f])+/
Truffle::Ropes.dump_string('foo').should =~ /(\\x[0-9a-f][0-9a-f])+/
end

it "returns correct bytes for the given string" do
Truffle::Runtime.dump_string('foo').should == "\\x66\\x6f\\x6f"
Truffle::Ropes.dump_string('foo').should == "\\x66\\x6f\\x6f"
end

end
2 changes: 1 addition & 1 deletion spec/truffle/tags/truffle/runtime/java_class_of_tags.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
graalvm:Truffle::Runtime.java_class_of returns 'DynamicObject*' for a String
graalvm:Truffle.java_class_of returns 'DynamicObject*' for a String
6 changes: 3 additions & 3 deletions test/truffle/integration/safe.sh
Original file line number Diff line number Diff line change
@@ -18,11 +18,11 @@ safe -e 14

# Check our safe_puts is safe

safe -e "Truffle.safe_puts 'hello, world'"
safe -e "Truffle::Safe.puts 'hello, world'"

# But we can make that unsafe as well if really don't want any output

unsafe -Xtruffle.platform.safe_puts=false -e "Truffle.safe_puts 'hello, world'"
unsafe -Xtruffle.platform.safe_puts=false -e "Truffle::Safe.puts 'hello, world'"

# Try some unsafe operations

@@ -38,7 +38,7 @@ safe -Xtruffle.platform.safe.exit=true -e 'exit!'

# Check that safe_puts sanitises correctly

if [[ `run -e "Truffle.safe_puts 'foo © bar'"` != 'foo ? bar' ]]
if [[ `run -e "Truffle::Safe.puts 'foo © bar'"` != 'foo ? bar' ]]
then
echo safe_puts is not sanitising output
exit 1
2 changes: 1 addition & 1 deletion tool/truffle/callgraph2html.rb
Original file line number Diff line number Diff line change
@@ -55,7 +55,7 @@ def core?
end

def hidden?
source.file == 'run_jruby_root' || source.file == 'context' || name == 'Truffle#run_jruby_root' || name == 'Truffle#context'
source.file == 'run_jruby_root' || source.file == 'context' || name == 'Truffle::Boot#run_jruby_root' || name == 'Truffle::Boot#context'
end

def reachable
4 changes: 2 additions & 2 deletions truffle/src/main/java/org/jruby/truffle/JRubyTruffleImpl.java
Original file line number Diff line number Diff line change
@@ -33,7 +33,7 @@ public JRubyTruffleImpl(Ruby runtime) {
.build();

try {
context = (RubyContext) engine.eval(Source.fromText("Truffle.context", "context")
context = (RubyContext) engine.eval(Source.fromText("Truffle::Boot.context", "context")
.withMimeType(RubyLanguage.MIME_TYPE)).get();
} catch (IOException e) {
throw new RuntimeException(e);
@@ -51,7 +51,7 @@ public Object execute(org.jruby.ast.RootNode rootNode) {
context.setInitialJRubyRootNode(rootNode);

try {
return engine.eval(Source.fromText("Truffle.run_jruby_root", "run_jruby_root")
return engine.eval(Source.fromText("Truffle::Boot.run_jruby_root", "run_jruby_root")
.withMimeType(RubyLanguage.MIME_TYPE)).get();
} catch (IOException e) {
if (e.getCause() instanceof ExitException) {
12 changes: 12 additions & 0 deletions truffle/src/main/java/org/jruby/truffle/core/CoreLibrary.java
Original file line number Diff line number Diff line change
@@ -53,13 +53,15 @@
import org.jruby.truffle.core.numeric.FixnumNodesFactory;
import org.jruby.truffle.core.numeric.FloatNodesFactory;
import org.jruby.truffle.core.numeric.IntegerNodesFactory;
import org.jruby.truffle.core.numeric.TruffleFixnumNodesFactory;
import org.jruby.truffle.core.objectspace.ObjectSpaceNodesFactory;
import org.jruby.truffle.core.proc.ProcNodesFactory;
import org.jruby.truffle.core.queue.QueueNodesFactory;
import org.jruby.truffle.core.queue.SizedQueueNodesFactory;
import org.jruby.truffle.core.range.RangeNodesFactory;
import org.jruby.truffle.core.regexp.MatchDataNodesFactory;
import org.jruby.truffle.core.regexp.RegexpNodesFactory;
import org.jruby.truffle.core.rope.TruffleRopesNodesFactory;
import org.jruby.truffle.core.rubinius.AtomicReferenceNodesFactory;
import org.jruby.truffle.core.rubinius.ByteArrayNodesFactory;
import org.jruby.truffle.core.rubinius.PosixNodesFactory;
@@ -80,6 +82,7 @@
import org.jruby.truffle.language.RubyGuards;
import org.jruby.truffle.language.RubyNode;
import org.jruby.truffle.language.RubyRootNode;
import org.jruby.truffle.language.TruffleSafeNodesFactory;
import org.jruby.truffle.language.backtrace.BacktraceFormatter;
import org.jruby.truffle.language.control.RaiseException;
import org.jruby.truffle.language.control.TruffleFatalException;
@@ -88,6 +91,7 @@
import org.jruby.truffle.language.methods.DeclarationContext;
import org.jruby.truffle.language.methods.InternalMethod;
import org.jruby.truffle.language.objects.FreezeNode;
import org.jruby.truffle.language.BootNodesFactory;
import org.jruby.truffle.language.objects.FreezeNodeGen;
import org.jruby.truffle.language.objects.SingletonClassNode;
import org.jruby.truffle.language.objects.SingletonClassNodeGen;
@@ -569,8 +573,12 @@ public CoreLibrary(RubyContext context) {
defineModule(truffleModule, "Etc");
defineModule(truffleModule, "Coverage");
defineModule(truffleModule, "Graal");
defineModule(truffleModule, "Ropes");
defineModule(truffleModule, "GC");
defineModule(truffleModule, "Attachments");
defineModule(truffleModule, "Boot");
defineModule(truffleModule, "Fixnum");
defineModule(truffleModule, "Safe");
psychModule = defineModule("Psych");
psychParserClass = defineClass(psychModule, objectClass, "Parser");
final DynamicObject psychHandlerClass = defineClass(psychModule, objectClass, "Handler");
@@ -698,6 +706,7 @@ public void addCoreMethods() {
coreMethodNodeManager.addCoreMethodNodes(TrueClassNodesFactory.getFactories());
coreMethodNodeManager.addCoreMethodNodes(TruffleNodesFactory.getFactories());
coreMethodNodeManager.addCoreMethodNodes(GCNodesFactory.getFactories());
coreMethodNodeManager.addCoreMethodNodes(BootNodesFactory.getFactories());
coreMethodNodeManager.addCoreMethodNodes(AttachmentsNodesFactory.getFactories());
coreMethodNodeManager.addCoreMethodNodes(GraalNodesFactory.getFactories());
coreMethodNodeManager.addCoreMethodNodes(EncodingNodesFactory.getFactories());
@@ -720,6 +729,9 @@ public void addCoreMethods() {
coreMethodNodeManager.addCoreMethodNodes(AtomicReferenceNodesFactory.getFactories());
coreMethodNodeManager.addCoreMethodNodes(TracePointNodesFactory.getFactories());
coreMethodNodeManager.addCoreMethodNodes(CoverageNodesFactory.getFactories());
coreMethodNodeManager.addCoreMethodNodes(TruffleRopesNodesFactory.getFactories());
coreMethodNodeManager.addCoreMethodNodes(TruffleFixnumNodesFactory.getFactories());
coreMethodNodeManager.addCoreMethodNodes(TruffleSafeNodesFactory.getFactories());

coreMethodNodeManager.allMethodInstalled();

Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright (c) 2013, 2016 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.core.numeric;

import com.oracle.truffle.api.dsl.Specialization;
import org.jruby.truffle.core.CoreClass;
import org.jruby.truffle.core.CoreLibrary;
import org.jruby.truffle.core.CoreMethod;
import org.jruby.truffle.core.UnaryCoreMethodNode;

@CoreClass(name = "Truffle::Fixnum")
public abstract class TruffleFixnumNodes {

@CoreMethod(names = "lower", isModuleFunction = true, required = 1)
public abstract static class LowerPrimitiveNode extends UnaryCoreMethodNode {

@Specialization
public int lower(int value) {
return value;
}

@Specialization(guards = "canLower(value)")
public int lower(long value) {
return (int) value;
}

@Specialization(guards = "!canLower(value)")
public long lowerFails(long value) {
return value;
}

protected static boolean canLower(long value) {
return CoreLibrary.fitsIntoInteger(value);
}

}

}
Loading