Skip to content

Commit

Permalink
Showing 191 changed files with 1,456 additions and 1,193 deletions.
Original file line number Diff line number Diff line change
@@ -275,6 +275,7 @@ public Instr decodeInstr() {
case RESCUE_EQQ: return RescueEQQInstr.decode(this);
case RESTORE_ERROR_INFO: return RestoreErrorInfoInstr.decode(this);
case RETURN: return ReturnInstr.decode(this);
case RETURN_OR_RETHROW_SAVED_EXC: return ReturnOrRethrowSavedExcInstr.decode(this);
case RUNTIME_HELPER: return RuntimeHelperCall.decode(this);
case SEARCH_CONST: return SearchConstInstr.decode(this);
case SET_CAPTURED_VAR: return SetCapturedVarInstr.decode(this);
18 changes: 8 additions & 10 deletions core/src/main/java/org/jruby/ir/runtime/IRRuntimeHelpers.java
Original file line number Diff line number Diff line change
@@ -200,7 +200,7 @@ public static IRubyObject handleBreakAndReturnsInLambdas(ThreadContext context,
return ((IRWrappedLambdaReturnValue)exc).returnValue;
} else if ((exc instanceof IRBreakJump) && inNonMethodBodyLambda(scope, blockType)) {
// We just unwound all the way up because of a non-local break
context.setSavedExceptionInLambda(IRException.BREAK_LocalJumpError.getException(context.getRuntime()));
context.setSavedExceptionInLambda(IRException.BREAK_LocalJumpError.getException(context.runtime));
return null;
} else if (exc instanceof IRReturnJump && (blockType == null || inLambda(blockType))) {
try {
@@ -247,7 +247,7 @@ public static IRubyObject handlePropagatedBreak(ThreadContext context, DynamicSc
IRScopeType scopeType = scope.getScopeType();
if (!scopeType.isClosureType()) {
// Error -- breaks can only be initiated in closures
throw IRException.BREAK_LocalJumpError.getException(context.getRuntime());
throw IRException.BREAK_LocalJumpError.getException(context.runtime);
} else {
bj.breakInEval = false;
throw bj;
@@ -311,7 +311,7 @@ public static IRubyObject undefMethod(ThreadContext context, Object nameArg, Dyn

module.undef(context, name);

return context.runtime.getNil();
return context.nil;
}

public static double unboxFloat(IRubyObject val) {
@@ -702,7 +702,7 @@ protected static void checkSuperDisabledOrOutOfMethod(ThreadContext context, Rub
if (methodName == null || !methodName.equals("")) {
throw context.runtime.newNameError("superclass method '" + methodName + "' disabled", methodName);
} else {
throw context.runtime.newNoMethodError("super called outside of method", null, context.runtime.getNil());
throw context.runtime.newNoMethodError("super called outside of method", null, context.nil);
}
}
}
@@ -904,7 +904,7 @@ public static IRubyObject receiveKeywordArg(ThreadContext context, IRubyObject[]

if (keywordArguments == null) return UndefinedValue.UNDEFINED;

RubySymbol keywordName = context.getRuntime().newSymbol(argName);
RubySymbol keywordName = context.runtime.newSymbol(argName);

if (keywordArguments.fastARef(keywordName) == null) return UndefinedValue.UNDEFINED;

@@ -916,7 +916,7 @@ public static IRubyObject receiveKeywordArg(ThreadContext context, IRubyObject[]
public static IRubyObject receiveKeywordRestArg(ThreadContext context, IRubyObject[] args, int required, boolean keywordArgumentSupplied) {
RubyHash keywordArguments = extractKwargsHash(args, required, keywordArgumentSupplied);

return keywordArguments == null ? RubyHash.newSmallHash(context.getRuntime()) : keywordArguments;
return keywordArguments == null ? RubyHash.newSmallHash(context.runtime) : keywordArguments;
}

public static IRubyObject setCapturedVar(ThreadContext context, IRubyObject matchRes, String varName) {
@@ -1114,8 +1114,7 @@ public static RubyHash dupKwargsHashAndPopulateFromArray(ThreadContext context,

@JIT
public static IRubyObject searchConst(ThreadContext context, StaticScope staticScope, String constName, boolean noPrivateConsts) {
Ruby runtime = context.getRuntime();
RubyModule object = runtime.getObject();
RubyModule object = context.runtime.getObject();
IRubyObject constant = (staticScope == null) ? object.getConstant(constName) : staticScope.getConstantInner(constName);

// Inheritance lookup
@@ -1136,12 +1135,11 @@ public static IRubyObject searchConst(ThreadContext context, StaticScope staticS

@JIT
public static IRubyObject inheritedSearchConst(ThreadContext context, IRubyObject cmVal, String constName, boolean noPrivateConsts) {
Ruby runtime = context.runtime;
RubyModule module;
if (cmVal instanceof RubyModule) {
module = (RubyModule) cmVal;
} else {
throw runtime.newTypeError(cmVal + " is not a type/class");
throw context.runtime.newTypeError(cmVal + " is not a type/class");
}

IRubyObject constant = noPrivateConsts ? module.getConstantFromNoConstMissing(constName, false) : module.getConstantNoConstMissing(constName);
1 change: 1 addition & 0 deletions core/src/main/java/org/jruby/util/cli/Options.java
Original file line number Diff line number Diff line change
@@ -246,6 +246,7 @@ public class Options {
public static final Option<Integer> TRUFFLE_PACK_CACHE = integer(TRUFFLE, "truffle.pack.cache", TRUFFLE_DEFAULT_CACHE.load(), "Array#pack cache size");
public static final Option<Integer> TRUFFLE_UNPACK_CACHE = integer(TRUFFLE, "truffle.unpack.cache", TRUFFLE_DEFAULT_CACHE.load(), "String#unpack cache size");
public static final Option<Integer> TRUFFLE_EVAL_CACHE = integer(TRUFFLE, "truffle.eval.cache", TRUFFLE_DEFAULT_CACHE.load(), "eval lookup cache size");
public static final Option<Integer> TRUFFLE_CLASS_CACHE = integer(TRUFFLE, "truffle.class.cache", TRUFFLE_DEFAULT_CACHE.load(), ".class and .metaclass cache size");
public static final Option<Integer> TRUFFLE_ENCODING_COMPATIBLE_QUERY_CACHE = integer(TRUFFLE, "truffle.encoding_compatible_query.cache", TRUFFLE_DEFAULT_CACHE.load(), "Encoding.compatible? cache size");

public static final Option<Boolean> TRUFFLE_CLONE_DEFAULT = bool(TRUFFLE, "truffle.clone.default", true, "Default option for cloning.");
2 changes: 1 addition & 1 deletion test/truffle/integration/backtraces/backtraces.rb
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ def check(file)
expected = nil

File.open('test/truffle/integration/backtraces/' + file) do |f|
expected = f.lines.map(&:strip)
expected = f.each_line.map(&:strip)
end

begin
4 changes: 2 additions & 2 deletions test/truffle/integration/backtraces/eval.rb
Original file line number Diff line number Diff line change
@@ -6,10 +6,10 @@
# GNU General Public License version 2
# GNU Lesser General Public License version 2.1

require_relative 'backtraces'

# TODO CS 3-Feb-16 Not compliant with MRI - here as a regression test

require_relative 'backtraces'

def m1
eval 'm2'
end
4 changes: 2 additions & 2 deletions test/truffle/integration/backtraces/send.rb
Original file line number Diff line number Diff line change
@@ -6,10 +6,10 @@
# GNU General Public License version 2
# GNU Lesser General Public License version 2.1

require_relative 'backtraces'

# TODO CS 3-Feb-16 Not compliant with MRI - here as a regression test

require_relative 'backtraces'

def m1
send :m2
end
9 changes: 9 additions & 0 deletions test/truffle/integration/tracing.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash

set -e

for f in test/truffle/integration/tracing/*.rb
do
echo $f
ruby -X+T $f
done
34 changes: 34 additions & 0 deletions test/truffle/integration/tracing/binding.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Copyright (c) 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

# TODO CS 19-Feb-16 Not compliant with MRI - here as a regression test

require_relative 'tracing'

def add(a)
a + yield
end

outside_trace = 1
captured_in_scope = 2
modified = 3

set_trace_func $trace_proc

inside_trace = 4
modified = 5

result = add(14) {
captured_in_scope
}

result

set_trace_func nil

check('binding.trace')
11 changes: 11 additions & 0 deletions test/truffle/integration/tracing/binding.trace
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
["line", "/binding.rb", 23, nil, {:captured_in_scope=>2, :inside_trace=>nil, :modified=>3, :outside_trace=>1, :result=>nil}, nil]
["line", "/binding.rb", 24, nil, {:captured_in_scope=>2, :inside_trace=>4, :modified=>3, :outside_trace=>1, :result=>nil}, nil]
["line", "/binding.rb", 26, nil, {:captured_in_scope=>2, :inside_trace=>4, :modified=>5, :outside_trace=>1, :result=>nil}, nil]
["call", "/binding.rb", 26, :add, {:captured_in_scope=>2, :inside_trace=>4, :modified=>5, :outside_trace=>1, :result=>nil}, Object]
["line", "/binding.rb", 14, nil, {:a=>14}, nil]
["call", "/binding.rb", 14, :"<main>", {:a=>14}, Object]
["line", "/binding.rb", 27, nil, {:captured_in_scope=>2, :inside_trace=>4, :modified=>5, :outside_trace=>1, :result=>16}, nil]
["call", "/binding.rb", 14, :+, {:a=>14}, Fixnum]
["line", "/binding.rb", 30, nil, {:captured_in_scope=>2, :inside_trace=>4, :modified=>5, :outside_trace=>1, :result=>16}, nil]
["line", "/binding.rb", 32, nil, {:captured_in_scope=>2, :inside_trace=>4, :modified=>5, :outside_trace=>1, :result=>16}, nil]
["call", "/binding.rb", 32, :set_trace_func, {:captured_in_scope=>2, :inside_trace=>4, :modified=>5, :outside_trace=>1, :result=>16}, Object]
27 changes: 27 additions & 0 deletions test/truffle/integration/tracing/modules.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright (c) 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

# TODO CS 19-Feb-16 Not compliant with MRI - here as a regression test

require_relative 'tracing'

def add(a, b)
a + b
end

set_trace_func $trace_proc

module Foo
end

class Bar
end

set_trace_func nil

check('modules.trace')
9 changes: 9 additions & 0 deletions test/truffle/integration/tracing/modules.trace
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
["class", "/modules.rb", 19, nil, {}, nil]
["line", "/modules.rb", 19, nil, {}, nil]
["call", "/modules.rb", 19, :Foo, {}, Module]
["class", "/modules.rb", 22, nil, {}, nil]
["line", "/modules.rb", 22, nil, {}, nil]
["call", "/modules.rb", 22, :inherited, {}, Class]
["call", "/modules.rb", 22, :Bar, {}, Class]
["line", "/modules.rb", 25, nil, {}, nil]
["call", "/modules.rb", 25, :set_trace_func, {}, Object]
23 changes: 23 additions & 0 deletions test/truffle/integration/tracing/simple.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright (c) 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

# TODO CS 19-Feb-16 Not compliant with MRI - here as a regression test

require_relative 'tracing'

def add(a, b)
a + b
end

set_trace_func $trace_proc

add(14, 2)

set_trace_func nil

check('simple.trace')
6 changes: 6 additions & 0 deletions test/truffle/integration/tracing/simple.trace
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
["line", "/simple.rb", 19, nil, {}, nil]
["call", "/simple.rb", 19, :add, {}, Object]
["line", "/simple.rb", 14, nil, {:a=>14, :b=>2}, nil]
["call", "/simple.rb", 14, :+, {:a=>14, :b=>2}, Fixnum]
["line", "/simple.rb", 21, nil, {}, nil]
["call", "/simple.rb", 21, :set_trace_func, {}, Object]
82 changes: 82 additions & 0 deletions test/truffle/integration/tracing/tracing.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Copyright (c) 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

$trace = []

$trace_proc = proc { |*args|
args[4] = args[4].dup
$trace << args
}

class MockBinding

def local_variables
[]
end

end

def check(file)
expected = nil

File.open('test/truffle/integration/tracing/' + file) do |f|
expected = f.each_line.map { |line| eval(line) }
end

actual = $trace

empty_binding = MockBinding.new

while actual.size < expected.size
actual.push ['missing', 'missing', :missing, :missing, empty_binding, :missing]
end

while expected.size < actual.size
expected.push ['missing', 'missing', :missing, :missing, empty_binding, :missing]
end

success = true

expected.zip(actual).each do |e, a|
unless a[0] == e[0]
puts "Expected #{e[0].inspect}, actually #{a[0].inspect}"
success = false
end

unless a[1].end_with?(e[1])
puts "Expected #{e[1].inspect}, actually #{a[1].inspect}"
success = false
end

unless a[2] == e[2]
puts "Expected #{e[2].inspect}, actually #{a[2].inspect}"
success = false
end

unless a[3] == e[3]
puts "Expected #{e[3].inspect}, actually #{a[3].inspect}"
success = false
end

ab = Hash[a[4].local_variables.sort.map { |v| [v, a[4].local_variable_get(v)] }]

unless ab == e[4]
puts "Expected Binding, actually #{ab.inspect}"
success = false
end

unless a[5] == e[5]
puts "Expected #{e[5].inspect}, actually #{a[5].inspect}"
success = false
end
end

unless success
exit 1
end
end
6 changes: 5 additions & 1 deletion tool/jt.rb
Original file line number Diff line number Diff line change
@@ -161,7 +161,11 @@ def raw_sh(*args)
false
else
$stderr.puts "FAILED (#{$?}): #{printable_cmd(args)}"
exit $?.exitstatus
if $?
exit $?.exitstatus
else
exit 1
end
end
end
end
13 changes: 10 additions & 3 deletions truffle/src/main/java/org/jruby/truffle/core/CoreLibrary.java
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@
import com.oracle.truffle.api.CompilerAsserts;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
import com.oracle.truffle.api.TruffleOptions;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.interop.java.JavaInterop;
@@ -925,8 +926,8 @@ public DynamicObject systemStackError(String message, Node currentNode) {
return ExceptionNodes.createRubyException(systemStackErrorClass, StringOperations.createString(context, StringOperations.encodeRope(message, UTF8Encoding.INSTANCE)), context.getCallStack().getBacktrace(currentNode));
}

@TruffleBoundary
public DynamicObject frozenError(String className, Node currentNode) {
CompilerAsserts.neverPartOfCompilation();
return runtimeError(String.format("can't modify frozen %s", className), currentNode);
}

@@ -1033,6 +1034,12 @@ public DynamicObject noBlockToYieldTo(Node currentNode) {
return localJumpError("no block given (yield)", currentNode);
}

@TruffleBoundary
public DynamicObject typeErrorCantCreateInstanceOfSingletonClass(Node currentNode) {
return typeError("can't create instance of singleton class", currentNode, null);
}

@TruffleBoundary
public DynamicObject typeError(String message, Node currentNode) {
return typeError(message, currentNode, null);
}
@@ -1133,8 +1140,8 @@ public DynamicObject nameErrorUninitializedConstant(DynamicObject module, String
return nameError(message, name, currentNode);
}

@TruffleBoundary
public DynamicObject nameErrorUninitializedClassVariable(DynamicObject module, String name, Node currentNode) {
CompilerAsserts.neverPartOfCompilation();
assert RubyGuards.isRubyModule(module);
return nameError(String.format("uninitialized class variable %s in %s", name, Layouts.MODULE.getFields(module).getName()), name, currentNode);
}
@@ -1304,7 +1311,7 @@ public DynamicObject rangeError(String message, Node currentNode) {
}

public DynamicObject internalError(String message, Node currentNode) {
return internalError(message, currentNode);
return internalError(message, currentNode, null);
}

public DynamicObject internalError(String message, Node currentNode, Throwable javaThrowable) {
Original file line number Diff line number Diff line change
@@ -34,7 +34,6 @@
import org.jruby.truffle.language.arguments.ReadCallerFrameNode;
import org.jruby.truffle.language.arguments.ReadPreArgumentNode;
import org.jruby.truffle.language.arguments.ReadRemainingArgumentsNode;
import org.jruby.truffle.language.control.SequenceNode;
import org.jruby.truffle.language.methods.Arity;
import org.jruby.truffle.language.methods.ExceptionTranslatingNode;
import org.jruby.truffle.language.methods.InternalMethod;
4 changes: 2 additions & 2 deletions truffle/src/main/java/org/jruby/truffle/core/MainNodes.java
Original file line number Diff line number Diff line change
@@ -34,7 +34,7 @@ public PublicNode(RubyContext context, SourceSection sourceSection) {

@Specialization
public DynamicObject doPublic(VirtualFrame frame, Object[] args) {
final DynamicObject object = getContext().getCoreLibrary().getObjectClass();
final DynamicObject object = coreLibrary().getObjectClass();
return publicNode.executePublic(frame, object, args);
}
}
@@ -51,7 +51,7 @@ public PrivateNode(RubyContext context, SourceSection sourceSection) {

@Specialization
public DynamicObject doPrivate(VirtualFrame frame, Object[] args) {
final DynamicObject object = getContext().getCoreLibrary().getObjectClass();
final DynamicObject object = coreLibrary().getObjectClass();
return privateNode.executePrivate(frame, object, args);
}
}
56 changes: 28 additions & 28 deletions truffle/src/main/java/org/jruby/truffle/core/MathNodes.java
Original file line number Diff line number Diff line change
@@ -39,7 +39,7 @@ public ACosNode(RubyContext context, SourceSection sourceSection) {
protected double doFunction(double a) {
if (a < -1.0 || a > 1.0) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().mathDomainError("acos", this));
throw new RaiseException(coreLibrary().mathDomainError("acos", this));
}

return Math.acos(a);
@@ -62,7 +62,7 @@ protected double doFunction(double a) {
return Double.NaN;
} else if (a < 1) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().mathDomainError("acosh", this));
throw new RaiseException(coreLibrary().mathDomainError("acosh", this));
} else if (a < 94906265.62) {
return Math.log(a + Math.sqrt(a * a - 1.0));
} else{
@@ -83,7 +83,7 @@ public ASinNode(RubyContext context, SourceSection sourceSection) {
protected double doFunction(double a) {
if (a < -1.0 || a > 1.0) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().mathDomainError("asin", this));
throw new RaiseException(coreLibrary().mathDomainError("asin", this));
}

return Math.asin(a);
@@ -162,7 +162,7 @@ protected double doFunction(double a) {

if (a < -1.0 || a > 1.0) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().mathDomainError("atanh", this));
throw new RaiseException(coreLibrary().mathDomainError("atanh", this));
}

final double y = Math.abs(a);
@@ -358,16 +358,16 @@ public DynamicObject frexp(double a) {
for (; mantissa >= 1.0; mantissa *= 0.5, exponent +=1) { }
}

return Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), new Object[]{sign * mantissa, exponent}, 2);
return Layouts.ARRAY.createArray(coreLibrary().getArrayFactory(), new Object[]{sign * mantissa, exponent}, 2);
}

@Fallback
public DynamicObject frexp(VirtualFrame frame, Object a) {
if (isANode.executeIsA(a, getContext().getCoreLibrary().getNumericClass())) {
if (isANode.executeIsA(a, coreLibrary().getNumericClass())) {
return frexp(floatNode.callFloat(frame, a, "to_f", null));
} else {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().typeErrorCantConvertInto(a, "Float", this));
throw new RaiseException(coreLibrary().typeErrorCantConvertInto(a, "Float", this));
}
}

@@ -386,7 +386,7 @@ protected double doFunction(double a) {

if (a == -1) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().mathDomainError("gamma", this));
throw new RaiseException(coreLibrary().mathDomainError("gamma", this));
}

if (Double.isNaN(a)) {
@@ -398,7 +398,7 @@ protected double doFunction(double a) {
return Double.POSITIVE_INFINITY;
} else {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().mathDomainError("gamma", this));
throw new RaiseException(coreLibrary().mathDomainError("gamma", this));
}
}

@@ -418,7 +418,7 @@ protected double doFunction(double a) {

if (Double.isNaN(a)) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().mathDomainError("gamma", this));
throw new RaiseException(coreLibrary().mathDomainError("gamma", this));
}

return result;
@@ -513,21 +513,21 @@ public double function(double a, long b) {
public double function(double a, double b) {
if (Double.isNaN(b)) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().rangeError("float", Double.toString(b), "integer", this));
throw new RaiseException(coreLibrary().rangeError("float", Double.toString(b), "integer", this));
}

return a * Math.pow(2, b);
}

@Fallback
public double function(VirtualFrame frame, Object a, Object b) {
if (isANode.executeIsA(a, getContext().getCoreLibrary().getNumericClass())) {
if (isANode.executeIsA(a, coreLibrary().getNumericClass())) {
return function(
floatANode.callFloat(frame, a, "to_f", null),
integerBNode.callLongFixnum(frame, b, "to_int", null));
} else {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().typeErrorCantConvertInto(a, "Float", this));
throw new RaiseException(coreLibrary().typeErrorCantConvertInto(a, "Float", this));
}
}

@@ -568,21 +568,21 @@ public DynamicObject lgamma(double a) {

if (a < 0 && Double.isInfinite(a)) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().mathDomainError("log2", this));
throw new RaiseException(coreLibrary().mathDomainError("log2", this));
}

final RubyMath.NemesLogGamma l = new RubyMath.NemesLogGamma(a);

return Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), new Object[]{l.value, l.sign}, 2);
return Layouts.ARRAY.createArray(coreLibrary().getArrayFactory(), new Object[]{l.value, l.sign}, 2);
}

@Fallback
public DynamicObject lgamma(VirtualFrame frame, Object a) {
if (isANode.executeIsA(a, getContext().getCoreLibrary().getNumericClass())) {
if (isANode.executeIsA(a, coreLibrary().getNumericClass())) {
return lgamma(floatNode.callFloat(frame, a, "to_f", null));
} else {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().typeErrorCantConvertInto(a, "Float", this));
throw new RaiseException(coreLibrary().typeErrorCantConvertInto(a, "Float", this));
}
}

@@ -617,18 +617,18 @@ public double function(double a, NotProvided b) {

@Specialization
public double function(VirtualFrame frame, Object a, NotProvided b) {
if (isANode.executeIsA(a, getContext().getCoreLibrary().getNumericClass())) {
if (isANode.executeIsA(a, coreLibrary().getNumericClass())) {
return doFunction(floatANode.callFloat(frame, a, "to_f", null));
} else {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().typeErrorCantConvertInto(a, "Float", this));
throw new RaiseException(coreLibrary().typeErrorCantConvertInto(a, "Float", this));
}
}

private double doFunction(double a) {
if (a < 0) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().mathDomainError("log", this));
throw new RaiseException(coreLibrary().mathDomainError("log", this));
}

return Math.log(a);
@@ -638,7 +638,7 @@ private double doFunction(double a) {
protected double doFunction(double a, double b) {
if (a < 0) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().mathDomainError("log", this));
throw new RaiseException(coreLibrary().mathDomainError("log", this));
}

return Math.log(a) / Math.log(b);
@@ -657,7 +657,7 @@ public Log10Node(RubyContext context, SourceSection sourceSection) {
protected double doFunction(double a) {
if (a < 0) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().mathDomainError("log10", this));
throw new RaiseException(coreLibrary().mathDomainError("log10", this));
}

return Math.log10(a);
@@ -678,7 +678,7 @@ public Log2Node(RubyContext context, SourceSection sourceSection) {
protected double doFunction(double a) {
if (a < 0) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().mathDomainError("log2", this));
throw new RaiseException(coreLibrary().mathDomainError("log2", this));
}

return Math.log(a) / LOG2;
@@ -795,11 +795,11 @@ public double function(double a) {

@Fallback
public double function(VirtualFrame frame, Object a) {
if (isANode.executeIsA(a, getContext().getCoreLibrary().getNumericClass())) {
if (isANode.executeIsA(a, coreLibrary().getNumericClass())) {
return doFunction(floatNode.callFloat(frame, a, "to_f", null));
} else {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().typeErrorCantConvertInto(a, "Float", this));
throw new RaiseException(coreLibrary().typeErrorCantConvertInto(a, "Float", this));
}
}

@@ -906,15 +906,15 @@ public double function(double a, double b) {

@Fallback
public double function(VirtualFrame frame, Object a, Object b) {
if (isANode.executeIsA(a, getContext().getCoreLibrary().getNumericClass()) &&
isANode.executeIsA(b, getContext().getCoreLibrary().getNumericClass())) {
if (isANode.executeIsA(a, coreLibrary().getNumericClass()) &&
isANode.executeIsA(b, coreLibrary().getNumericClass())) {
return doFunction(
floatANode.callFloat(frame, a, "to_f", null),
floatBNode.callFloat(frame, b, "to_f", null));
} else {
CompilerDirectives.transferToInterpreter();

throw new RaiseException(getContext().getCoreLibrary().typeErrorCantConvertInto(a, "Float", this));
throw new RaiseException(coreLibrary().typeErrorCantConvertInto(a, "Float", this));
}
}

Original file line number Diff line number Diff line change
@@ -86,7 +86,7 @@ private Object clock_gettime_clock_id(int clock_id, DynamicObject unit) {
int r = libCClockGetTime.clock_gettime(clock_id, timeSpec);
if (r != 0) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().systemCallError("clock_gettime failed: " + r, this));
throw new RaiseException(coreLibrary().systemCallError("clock_gettime failed: " + r, this));
}
long nanos = timeSpec.getTVsec() * 1_000_000_000 + timeSpec.getTVnsec();
return timeToUnit(nanos, unit);
@@ -146,7 +146,7 @@ private int raise(String signalName) {
try {
getContext().getNativePlatform().getSignalManager().raise(signal);
} catch (IllegalArgumentException e) {
throw new RaiseException(getContext().getCoreLibrary().argumentError(e.getMessage(), this));
throw new RaiseException(coreLibrary().argumentError(e.getMessage(), this));
}
return 1;
}
Original file line number Diff line number Diff line change
@@ -34,8 +34,8 @@ public Object execute(VirtualFrame frame) {

if (isFrozenNode.executeIsFrozen(result)) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().frozenError(
Layouts.MODULE.getFields(getContext().getCoreLibrary().getLogicalClass(result)).getName(), this));
throw new RaiseException(coreLibrary().frozenError(
Layouts.MODULE.getFields(coreLibrary().getLogicalClass(result)).getName(), this));
}

return result;
Original file line number Diff line number Diff line change
@@ -25,7 +25,7 @@ public SetTopLevelBindingNode(RubyContext context, SourceSection sourceSection)
@Override
public Object execute(VirtualFrame frame) {
final DynamicObject binding = BindingNodes.createBinding(getContext(), frame.materialize());
Layouts.MODULE.getFields(getContext().getCoreLibrary().getObjectClass()).setConstant(getContext(), this, "TOPLEVEL_BINDING", binding);
Layouts.MODULE.getFields(coreLibrary().getObjectClass()).setConstant(getContext(), this, "TOPLEVEL_BINDING", binding);
return nil();
}

Original file line number Diff line number Diff line change
@@ -63,7 +63,7 @@ private DynamicObject executeSingle(VirtualFrame frame, Object store, int length
store = arrayBuilderNode.appendValue(store, length, childObject);
length++;
}
return Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), arrayBuilderNode.finish(store, length), length);
return Layouts.ARRAY.createArray(coreLibrary().getArrayFactory(), arrayBuilderNode.finish(store, length), length);
}

@ExplodeLoop
@@ -85,7 +85,7 @@ private DynamicObject executeRubyArray(VirtualFrame frame, Object store, int len
}
}

return Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), arrayBuilderNode.finish(store, length), length);
return Layouts.ARRAY.createArray(coreLibrary().getArrayFactory(), arrayBuilderNode.finish(store, length), length);
}

@ExplodeLoop
Original file line number Diff line number Diff line change
@@ -35,17 +35,17 @@ public ArrayDropTailNode(RubyContext context, SourceSection sourceSection, int i
public DynamicObject getHeadNull(DynamicObject array) {
CompilerDirectives.transferToInterpreter();

return Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), null, 0);
return Layouts.ARRAY.createArray(coreLibrary().getArrayFactory(), null, 0);
}

@Specialization(guards = "isIntArray(array)")
public DynamicObject getHeadIntegerFixnum(DynamicObject array) {
CompilerDirectives.transferToInterpreter();

if (index >= Layouts.ARRAY.getSize(array)) {
return Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), null, 0);
return Layouts.ARRAY.createArray(coreLibrary().getArrayFactory(), null, 0);
} else {
return Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), ArrayUtils.extractRange((int[]) Layouts.ARRAY.getStore(array), 0, Layouts.ARRAY.getSize(array) - index), Layouts.ARRAY.getSize(array) - index);
return Layouts.ARRAY.createArray(coreLibrary().getArrayFactory(), ArrayUtils.extractRange((int[]) Layouts.ARRAY.getStore(array), 0, Layouts.ARRAY.getSize(array) - index), Layouts.ARRAY.getSize(array) - index);
}
}

@@ -54,10 +54,10 @@ public DynamicObject geHeadLongFixnum(DynamicObject array) {
CompilerDirectives.transferToInterpreter();

if (index >= Layouts.ARRAY.getSize(array)) {
return Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), null, 0);
return Layouts.ARRAY.createArray(coreLibrary().getArrayFactory(), null, 0);
} else {
final int size = Layouts.ARRAY.getSize(array) - index;
return Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), ArrayUtils.extractRange((long[]) Layouts.ARRAY.getStore(array), 0, size), size);
return Layouts.ARRAY.createArray(coreLibrary().getArrayFactory(), ArrayUtils.extractRange((long[]) Layouts.ARRAY.getStore(array), 0, size), size);
}
}

@@ -66,10 +66,10 @@ public DynamicObject getHeadFloat(DynamicObject array) {
CompilerDirectives.transferToInterpreter();

if (index >= Layouts.ARRAY.getSize(array)) {
return Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), null, 0);
return Layouts.ARRAY.createArray(coreLibrary().getArrayFactory(), null, 0);
} else {
final int size = Layouts.ARRAY.getSize(array) - index;
return Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), ArrayUtils.extractRange((double[]) Layouts.ARRAY.getStore(array), 0, size), size);
return Layouts.ARRAY.createArray(coreLibrary().getArrayFactory(), ArrayUtils.extractRange((double[]) Layouts.ARRAY.getStore(array), 0, size), size);
}
}

@@ -78,10 +78,10 @@ public DynamicObject getHeadObject(DynamicObject array) {
CompilerDirectives.transferToInterpreter();

if (index >= Layouts.ARRAY.getSize(array)) {
return Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), null, 0);
return Layouts.ARRAY.createArray(coreLibrary().getArrayFactory(), null, 0);
} else {
final int size = Layouts.ARRAY.getSize(array) - index;
return Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), ArrayUtils.extractRange((Object[]) Layouts.ARRAY.getStore(array), 0, size), size);
return Layouts.ARRAY.createArray(coreLibrary().getArrayFactory(), ArrayUtils.extractRange((Object[]) Layouts.ARRAY.getStore(array), 0, size), size);
}
}

Original file line number Diff line number Diff line change
@@ -39,41 +39,41 @@ public ArrayDupNode(RubyContext context, SourceSection sourceSection) {

@Specialization(guards = "isNullArray(from)")
public DynamicObject dupNull(DynamicObject from) {
return allocateNode.allocate(getContext().getCoreLibrary().getArrayClass(), null, 0);
return allocateNode.allocateArray(coreLibrary().getArrayClass(), null, 0);
}

@Specialization(guards = "isIntArray(from)")
public DynamicObject dupIntegerFixnum(DynamicObject from) {
final int[] store = (int[]) Layouts.ARRAY.getStore(from);
return allocateNode.allocate(
getContext().getCoreLibrary().getArrayClass(),
return allocateNode.allocateArray(
coreLibrary().getArrayClass(),
store.clone(),
Layouts.ARRAY.getSize(from));
}

@Specialization(guards = "isLongArray(from)")
public DynamicObject dupLongFixnum(DynamicObject from) {
final long[] store = (long[]) Layouts.ARRAY.getStore(from);
return allocateNode.allocate(
getContext().getCoreLibrary().getArrayClass(),
return allocateNode.allocateArray(
coreLibrary().getArrayClass(),
store.clone(),
Layouts.ARRAY.getSize(from));
}

@Specialization(guards = "isDoubleArray(from)")
public DynamicObject dupFloat(DynamicObject from) {
final double[] store = (double[]) Layouts.ARRAY.getStore(from);
return allocateNode.allocate(
getContext().getCoreLibrary().getArrayClass(),
return allocateNode.allocateArray(
coreLibrary().getArrayClass(),
store.clone(),
Layouts.ARRAY.getSize(from));
}

@Specialization(guards = "isObjectArray(from)")
public DynamicObject dupObject(DynamicObject from) {
final Object[] store = (Object[]) Layouts.ARRAY.getStore(from);
return allocateNode.allocate(
getContext().getCoreLibrary().getArrayClass(),
return allocateNode.allocateArray(
coreLibrary().getArrayClass(),
ArrayUtils.copy(store),
Layouts.ARRAY.getSize(from));
}
Original file line number Diff line number Diff line change
@@ -35,17 +35,17 @@ public ArrayGetTailNode(RubyContext context, SourceSection sourceSection, int in
public DynamicObject getTailNull(DynamicObject array) {
CompilerDirectives.transferToInterpreter();

return Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), null, 0);
return Layouts.ARRAY.createArray(coreLibrary().getArrayFactory(), null, 0);
}

@Specialization(guards = "isIntArray(array)")
public DynamicObject getTailIntegerFixnum(DynamicObject array) {
CompilerDirectives.transferToInterpreter();

if (index >= Layouts.ARRAY.getSize(array)) {
return Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), null, 0);
return Layouts.ARRAY.createArray(coreLibrary().getArrayFactory(), null, 0);
} else {
return Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), ArrayUtils.extractRange((int[]) Layouts.ARRAY.getStore(array), index, Layouts.ARRAY.getSize(array)), Layouts.ARRAY.getSize(array) - index);
return Layouts.ARRAY.createArray(coreLibrary().getArrayFactory(), ArrayUtils.extractRange((int[]) Layouts.ARRAY.getStore(array), index, Layouts.ARRAY.getSize(array)), Layouts.ARRAY.getSize(array) - index);
}
}

@@ -54,9 +54,9 @@ public DynamicObject getTailLongFixnum(DynamicObject array) {
CompilerDirectives.transferToInterpreter();

if (index >= Layouts.ARRAY.getSize(array)) {
return Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), null, 0);
return Layouts.ARRAY.createArray(coreLibrary().getArrayFactory(), null, 0);
} else {
return Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), ArrayUtils.extractRange((long[]) Layouts.ARRAY.getStore(array), index, Layouts.ARRAY.getSize(array)), Layouts.ARRAY.getSize(array) - index);
return Layouts.ARRAY.createArray(coreLibrary().getArrayFactory(), ArrayUtils.extractRange((long[]) Layouts.ARRAY.getStore(array), index, Layouts.ARRAY.getSize(array)), Layouts.ARRAY.getSize(array) - index);
}
}

@@ -65,9 +65,9 @@ public DynamicObject getTailFloat(DynamicObject array) {
CompilerDirectives.transferToInterpreter();

if (index >= Layouts.ARRAY.getSize(array)) {
return Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), null, 0);
return Layouts.ARRAY.createArray(coreLibrary().getArrayFactory(), null, 0);
} else {
return Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), ArrayUtils.extractRange((double[]) Layouts.ARRAY.getStore(array), index, Layouts.ARRAY.getSize(array)), Layouts.ARRAY.getSize(array) - index);
return Layouts.ARRAY.createArray(coreLibrary().getArrayFactory(), ArrayUtils.extractRange((double[]) Layouts.ARRAY.getStore(array), index, Layouts.ARRAY.getSize(array)), Layouts.ARRAY.getSize(array) - index);
}
}

@@ -76,9 +76,9 @@ public DynamicObject getTailObject(DynamicObject array) {
CompilerDirectives.transferToInterpreter();

if (index >= Layouts.ARRAY.getSize(array)) {
return Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), null, 0);
return Layouts.ARRAY.createArray(coreLibrary().getArrayFactory(), null, 0);
} else {
return Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), ArrayUtils.extractRange((Object[]) Layouts.ARRAY.getStore(array), index, Layouts.ARRAY.getSize(array)), Layouts.ARRAY.getSize(array) - index);
return Layouts.ARRAY.createArray(coreLibrary().getArrayFactory(), ArrayUtils.extractRange((Object[]) Layouts.ARRAY.getStore(array), index, Layouts.ARRAY.getSize(array)), Layouts.ARRAY.getSize(array) - index);
}
}

Original file line number Diff line number Diff line change
@@ -51,7 +51,7 @@ protected DynamicObject makeGeneric(VirtualFrame frame, Object[] alreadyExecuted
}
}

return allocateObjectNode.allocate(getContext().getCoreLibrary().getArrayClass(), executedValues, executedValues.length);
return allocateObjectNode.allocate(coreLibrary().getArrayClass(), executedValues, executedValues.length);
}

@Override
@@ -90,7 +90,7 @@ public EmptyArrayLiteralNode(RubyContext context, SourceSection sourceSection, R

@Override
public Object execute(VirtualFrame frame) {
return allocateObjectNode.allocate(getContext().getCoreLibrary().getArrayClass(), null, 0);
return allocateObjectNode.allocate(coreLibrary().getArrayClass(), null, 0);
}

}
@@ -114,7 +114,7 @@ public Object execute(VirtualFrame frame) {
}
}

return allocateObjectNode.allocate(getContext().getCoreLibrary().getArrayClass(), executedValues, values.length);
return allocateObjectNode.allocate(coreLibrary().getArrayClass(), executedValues, values.length);
}

private DynamicObject makeGeneric(VirtualFrame frame,
@@ -149,7 +149,7 @@ public Object execute(VirtualFrame frame) {
}
}

return allocateObjectNode.allocate(getContext().getCoreLibrary().getArrayClass(), executedValues, values.length);
return allocateObjectNode.allocate(coreLibrary().getArrayClass(), executedValues, values.length);
}

private DynamicObject makeGeneric(VirtualFrame frame,
@@ -184,7 +184,7 @@ public Object execute(VirtualFrame frame) {
}
}

return allocateObjectNode.allocate(getContext().getCoreLibrary().getArrayClass(), executedValues, values.length);
return allocateObjectNode.allocate(coreLibrary().getArrayClass(), executedValues, values.length);
}

private DynamicObject makeGeneric(VirtualFrame frame,
@@ -215,7 +215,7 @@ public Object execute(VirtualFrame frame) {
executedValues[n] = values[n].execute(frame);
}

return allocateObjectNode.allocate(getContext().getCoreLibrary().getArrayClass(), executedValues, values.length);
return allocateObjectNode.allocate(coreLibrary().getArrayClass(), executedValues, values.length);
}

}
@@ -237,7 +237,7 @@ public Object execute(VirtualFrame frame) {
executedValues[n] = values[n].execute(frame);
}

final DynamicObject array = allocateObjectNode.allocate(getContext().getCoreLibrary().getArrayClass(), storeSpecialisedFromObjects(executedValues), executedValues.length);
final DynamicObject array = allocateObjectNode.allocate(coreLibrary().getArrayClass(), storeSpecialisedFromObjects(executedValues), executedValues.length);
final Object store = Layouts.ARRAY.getStore(array);

if (store == null) {
@@ -314,7 +314,7 @@ public Object storeSpecialisedFromObjects(Object... objects) {
final double[] store = new double[objects.length];

for (int n = 0; n < objects.length; n++) {
store[n] = CoreLibrary.toDouble(objects[n], getContext().getCoreLibrary().getNilObject());
store[n] = CoreLibrary.toDouble(objects[n], coreLibrary().getNilObject());
}

return store;
134 changes: 67 additions & 67 deletions truffle/src/main/java/org/jruby/truffle/core/array/ArrayNodes.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -39,7 +39,7 @@ public ArraySliceNode(RubyContext context, SourceSection sourceSection, int from
public DynamicObject sliceNull(DynamicObject array) {
CompilerDirectives.transferToInterpreter();

return Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), null, 0);
return Layouts.ARRAY.createArray(coreLibrary().getArrayFactory(), null, 0);
}

@Specialization(guards = "isIntArray(array)")
@@ -48,9 +48,9 @@ public DynamicObject sliceIntegerFixnum(DynamicObject array) {
final int to = Layouts.ARRAY.getSize(array) + this.to;

if (from >= to) {
return Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), null, 0);
return Layouts.ARRAY.createArray(coreLibrary().getArrayFactory(), null, 0);
} else {
return Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), ArrayUtils.extractRange((int[]) Layouts.ARRAY.getStore(array), from, to), to - from);
return Layouts.ARRAY.createArray(coreLibrary().getArrayFactory(), ArrayUtils.extractRange((int[]) Layouts.ARRAY.getStore(array), from, to), to - from);
}
}

@@ -60,9 +60,9 @@ public DynamicObject sliceLongFixnum(DynamicObject array) {
final int to = Layouts.ARRAY.getSize(array) + this.to;

if (from >= to) {
return Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), null, 0);
return Layouts.ARRAY.createArray(coreLibrary().getArrayFactory(), null, 0);
} else {
return Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), ArrayUtils.extractRange((long[]) Layouts.ARRAY.getStore(array), from, to), to - from);
return Layouts.ARRAY.createArray(coreLibrary().getArrayFactory(), ArrayUtils.extractRange((long[]) Layouts.ARRAY.getStore(array), from, to), to - from);
}
}

@@ -72,9 +72,9 @@ public DynamicObject sliceFloat(DynamicObject array) {
final int to = Layouts.ARRAY.getSize(array) + this.to;

if (from >= to) {
return Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), null, 0);
return Layouts.ARRAY.createArray(coreLibrary().getArrayFactory(), null, 0);
} else {
return Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), ArrayUtils.extractRange((double[]) Layouts.ARRAY.getStore(array), from, to), to - from);
return Layouts.ARRAY.createArray(coreLibrary().getArrayFactory(), ArrayUtils.extractRange((double[]) Layouts.ARRAY.getStore(array), from, to), to - from);
}
}

@@ -84,9 +84,9 @@ public DynamicObject sliceObject(DynamicObject array) {
final int to = Layouts.ARRAY.getSize(array) + this.to;

if (from >= to) {
return Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), null, 0);
return Layouts.ARRAY.createArray(coreLibrary().getArrayFactory(), null, 0);
} else {
return Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), ArrayUtils.extractRange((Object[]) Layouts.ARRAY.getStore(array), from, to), to - from);
return Layouts.ARRAY.createArray(coreLibrary().getArrayFactory(), ArrayUtils.extractRange((Object[]) Layouts.ARRAY.getStore(array), from, to), to - from);
}
}

Original file line number Diff line number Diff line change
@@ -11,16 +11,16 @@

import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.RubyContext;
import org.jruby.truffle.core.numeric.FixnumLiteralNode;
import org.jruby.truffle.language.RubyNode;
import org.jruby.truffle.language.literal.IntegerFixnumLiteralNode;

public abstract class PrimitiveArrayNodeFactory {

/**
* Create a node to read from an array with a constant denormalized index.
*/
public static RubyNode read(RubyContext context, SourceSection sourceSection, RubyNode array, int index) {
final RubyNode literalIndex = new FixnumLiteralNode.IntegerFixnumLiteralNode(context, sourceSection, index);
final RubyNode literalIndex = new IntegerFixnumLiteralNode(context, sourceSection, index);

if (index >= 0) {
return ArrayReadNormalizedNodeGen.create(context, sourceSection, array, literalIndex);
@@ -33,8 +33,8 @@ public static RubyNode read(RubyContext context, SourceSection sourceSection, Ru
* Create a node to read a slice from an array with a constant denormalized start and exclusive end.
*/
public static RubyNode readSlice(RubyContext context, SourceSection sourceSection, RubyNode array, int start, int exclusiveEnd) {
final RubyNode literalStart = new FixnumLiteralNode.IntegerFixnumLiteralNode(context, sourceSection, start);
final RubyNode literalExclusiveEnd = new FixnumLiteralNode.IntegerFixnumLiteralNode(context, sourceSection, exclusiveEnd);
final RubyNode literalStart = new IntegerFixnumLiteralNode(context, sourceSection, start);
final RubyNode literalExclusiveEnd = new IntegerFixnumLiteralNode(context, sourceSection, exclusiveEnd);

if (start >= 0 && exclusiveEnd >= 0) {
return ArrayReadSliceNormalizedNodeGen.create(context, sourceSection, array, literalStart, literalExclusiveEnd);
Original file line number Diff line number Diff line change
@@ -188,7 +188,7 @@ public Object instanceExec(VirtualFrame frame, Object receiver, Object[] argumen
public Object instanceExec(Object receiver, Object[] arguments, NotProvided block) {
CompilerDirectives.transferToInterpreter();

throw new RaiseException(getContext().getCoreLibrary().localJumpError("no block given", this));
throw new RaiseException(coreLibrary().localJumpError("no block given", this));
}

}
@@ -233,7 +233,7 @@ public MethodMissingNode(RubyContext context, SourceSection sourceSection) {
@Specialization
public Object methodMissingNoName(Object self, NotProvided name, Object[] args, NotProvided block) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().argumentError("no id given", this));
throw new RaiseException(coreLibrary().argumentError("no id given", this));
}

@Specialization
@@ -251,13 +251,13 @@ private Object methodMissing(Object self, DynamicObject nameObject, Object[] arg
final String name = nameObject.toString();

if (lastCallWasSuper()) {
throw new RaiseException(getContext().getCoreLibrary().noSuperMethodError(name, this));
throw new RaiseException(coreLibrary().noSuperMethodError(name, this));
} else if (lastCallWasCallingPrivateMethod(self, name)) {
throw new RaiseException(getContext().getCoreLibrary().privateMethodError(name, self, this));
throw new RaiseException(coreLibrary().privateMethodError(name, self, this));
} else if (lastCallWasVCall()) {
throw new RaiseException(getContext().getCoreLibrary().nameErrorUndefinedLocalVariableOrMethod(name, self, this));
throw new RaiseException(coreLibrary().nameErrorUndefinedLocalVariableOrMethod(name, self, this));
} else {
throw new RaiseException(getContext().getCoreLibrary().noMethodErrorOnReceiver(name, self, this));
throw new RaiseException(coreLibrary().noMethodErrorOnReceiver(name, self, this));
}
}

@@ -271,7 +271,7 @@ private boolean lastCallWasSuper() {
* The only way to fail if method is not null and not undefined is visibility.
*/
private boolean lastCallWasCallingPrivateMethod(Object self, String name) {
final InternalMethod method = ModuleOperations.lookupMethod(getContext().getCoreLibrary().getMetaClass(self), name);
final InternalMethod method = ModuleOperations.lookupMethod(coreLibrary().getMetaClass(self), name);
return method != null && !method.isUndefined();
}

Original file line number Diff line number Diff line change
@@ -165,7 +165,7 @@ public Object localVariableGetCached(DynamicObject binding, DynamicObject symbol
public Object localVariableGetUncached(DynamicObject binding, DynamicObject symbol) {
final FrameSlotAndDepth frameSlot = findFrameSlotOrNull(binding, symbol);
if (frameSlot == null) {
throw new RaiseException(getContext().getCoreLibrary().nameErrorLocalVariableNotDefined(Layouts.SYMBOL.getString(symbol), binding, this));
throw new RaiseException(coreLibrary().nameErrorLocalVariableNotDefined(Layouts.SYMBOL.getString(symbol), binding, this));
} else {
final MaterializedFrame frame = RubyArguments.getDeclarationFrame(Layouts.BINDING.getFrame(binding), frameSlot.depth);
return frame.getValue(frameSlot.slot);
@@ -179,7 +179,7 @@ public Object localVariableGetLastLine(DynamicObject binding, DynamicObject symb
final FrameSlot frameSlot = frame.getFrameDescriptor().findFrameSlot(Layouts.SYMBOL.getString(symbol));

if (frameSlot == null) {
throw new RaiseException(getContext().getCoreLibrary().nameErrorLocalVariableNotDefined(Layouts.SYMBOL.getString(symbol), binding, this));
throw new RaiseException(coreLibrary().nameErrorLocalVariableNotDefined(Layouts.SYMBOL.getString(symbol), binding, this));
}

final Object value = frame.getValue(frameSlot);
@@ -194,8 +194,22 @@ protected boolean compatibleFrames(DynamicObject binding1, DynamicObject binding
final FrameDescriptor fd1 = getFrameDescriptor(binding1);
final FrameDescriptor fd2 = getFrameDescriptor(binding2);

return ((fd1 == fd2) || (fd1.getSize() == 0 && fd2.getSize() == 0)) &&
getDeclarationFrame(binding1).getFrameDescriptor() == getDeclarationFrame(binding2).getFrameDescriptor();
if (!((fd1 == fd2) || (fd1.getSize() == 0 && fd2.getSize() == 0))) {
return false;
}

final MaterializedFrame df1 = getDeclarationFrame(binding1);
final MaterializedFrame df2 = getDeclarationFrame(binding2);

if ((df1 == null) != (df2 == null)) {
return false;
}

if (df1 == null) {
return true;
}

return df1.getFrameDescriptor() == df2.getFrameDescriptor();
}

protected ReadFrameSlotNode createReadNode(FrameSlotAndDepth frameSlot) {
@@ -337,7 +351,7 @@ public AllocateNode(RubyContext context, SourceSection sourceSection) {
@TruffleBoundary
@Specialization
public DynamicObject allocate(DynamicObject rubyClass) {
throw new RaiseException(getContext().getCoreLibrary().typeErrorAllocatorUndefinedFor(rubyClass, this));
throw new RaiseException(coreLibrary().typeErrorAllocatorUndefinedFor(rubyClass, this));
}

}
Original file line number Diff line number Diff line change
@@ -52,7 +52,7 @@ public int doLongFixnum(long value) {
@Specialization(guards = "!inBounds(value)")
public int doLongFixnumOutOfBounds(long value) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().argumentError(String.format("%s out of int range", indexName), this));
throw new RaiseException(coreLibrary().argumentError(String.format("%s out of int range", indexName), this));
}

@Specialization(guards = "inBounds(value)")
@@ -63,13 +63,13 @@ public int doDouble(double value) {
@Specialization(guards = "!inBounds(value)")
public int doDoubleOutOfBounds(double value) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().argumentError(String.format("%s out of int range", indexName), this));
throw new RaiseException(coreLibrary().argumentError(String.format("%s out of int range", indexName), this));
}

@Specialization(guards = "isRubyBignum(value)")
public DynamicObject doBignum(DynamicObject value) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().argumentError(String.format("%s out of int range", indexName), this));
throw new RaiseException(coreLibrary().argumentError(String.format("%s out of int range", indexName), this));
}


@@ -91,7 +91,7 @@ public Object coerce(VirtualFrame frame, DynamicObject value, @Cached("create(ge
@Fallback
public int doBasicObject(Object object) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().
throw new RaiseException(coreLibrary().
typeErrorIsNotA(object.toString(), "Fixnum (fitting in int)", this));
}

Original file line number Diff line number Diff line change
@@ -81,10 +81,10 @@ public DynamicObject castArray(DynamicObject array) {
public Object cast(Object nil) {
switch (nilBehavior) {
case EMPTY_ARRAY:
return Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), null, 0);
return Layouts.ARRAY.createArray(coreLibrary().getArrayFactory(), null, 0);

case ARRAY_WITH_NIL:
return Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), new Object[]{nil()}, 1);
return Layouts.ARRAY.createArray(coreLibrary().getArrayFactory(), new Object[]{nil()}, 1);

case NIL:
return nil;
@@ -109,7 +109,7 @@ public Object cast(VirtualFrame frame, DynamicObject object) {

if (!RubyGuards.isRubyArray(result)) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().typeErrorCantConvertTo(object, "Array", "to_ary", result, this));
throw new RaiseException(coreLibrary().typeErrorCantConvertTo(object, "Array", "to_ary", result, this));
}

return result;
Original file line number Diff line number Diff line change
@@ -90,10 +90,10 @@ public int cmpBignum(DynamicObject value, Object receiver, Object other) {
@Specialization(guards = "isNil(nil)")
public int cmpNil(Object nil, Object receiver, Object other) {
throw new RaiseException(
getContext().getCoreLibrary().argumentError(
coreLibrary().argumentError(
String.format("comparison of %s with %s failed",
Layouts.MODULE.getFields(getContext().getCoreLibrary().getLogicalClass(receiver)).getName(),
Layouts.MODULE.getFields(getContext().getCoreLibrary().getLogicalClass(other)).getName()), this)
Layouts.MODULE.getFields(coreLibrary().getLogicalClass(receiver)).getName(),
Layouts.MODULE.getFields(coreLibrary().getLogicalClass(other)).getName()), this)
);
}

Original file line number Diff line number Diff line change
@@ -83,7 +83,7 @@ public Object cast(VirtualFrame frame, DynamicObject object) {

if (!RubyGuards.isRubyHash(result)) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().typeErrorCantConvertTo(object, "Hash", "to_hash", result, this));
throw new RaiseException(coreLibrary().typeErrorCantConvertTo(object, "Hash", "to_hash", result, this));
}

return result;
Original file line number Diff line number Diff line change
@@ -49,7 +49,7 @@ public int doLongFixnum(long value) {
@Fallback
public int doBasicObject(Object object) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().
throw new RaiseException(coreLibrary().
typeErrorIsNotA(object.toString(), "Fixnum (fitting in int)", this));
}

Original file line number Diff line number Diff line change
@@ -60,18 +60,18 @@ protected double castNumeric(VirtualFrame frame, DynamicObject value) {
return (double) result;
} else {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().typeErrorCantConvertTo(value, "Float", method, result, this));
throw new RaiseException(coreLibrary().typeErrorCantConvertTo(value, "Float", method, result, this));
}
}

@Fallback
protected double fallback(Object value) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().typeErrorCantConvertInto(value, "Float", this));
throw new RaiseException(coreLibrary().typeErrorCantConvertInto(value, "Float", this));
}

protected boolean isNumeric(VirtualFrame frame, Object value) {
return isANode.executeIsA(value, getContext().getCoreLibrary().getNumericClass());
return isANode.executeIsA(value, coreLibrary().getNumericClass());
}

}
Original file line number Diff line number Diff line change
@@ -41,7 +41,7 @@ protected Object castSingle(Object[] args) {
@TruffleBoundary
@Specialization(guards = { "!noArguments(args)", "!singleArgument(args)" })
protected DynamicObject castMany(Object[] args) {
return Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), args, args.length);
return Layouts.ARRAY.createArray(coreLibrary().getArrayFactory(), args, args.length);
}

protected boolean noArguments(Object[] args) {
Original file line number Diff line number Diff line change
@@ -66,10 +66,10 @@ public SplatCastNode(RubyContext context, SourceSection sourceSection, NilBehavi
public Object splatNil(VirtualFrame frame, Object nil) {
switch (nilBehavior) {
case EMPTY_ARRAY:
return Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), null, 0);
return Layouts.ARRAY.createArray(coreLibrary().getArrayFactory(), null, 0);

case ARRAY_WITH_NIL:
return Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), new Object[]{nil()}, 1);
return Layouts.ARRAY.createArray(coreLibrary().getArrayFactory(), new Object[]{nil()}, 1);

case CONVERT:
return toA.call(frame, nil, "to_a", null);
@@ -101,14 +101,14 @@ public DynamicObject splat(VirtualFrame frame, Object object) {
return (DynamicObject) array;
} else if (array == nil() || array == DispatchNode.MISSING) {
CompilerDirectives.transferToInterpreter();
return Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), new Object[] { object }, 1);
return Layouts.ARRAY.createArray(coreLibrary().getArrayFactory(), new Object[] { object }, 1);
} else {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().typeErrorCantConvertTo(object, "Array", Layouts.SYMBOL.getString(conversionMethod), array, this));
throw new RaiseException(coreLibrary().typeErrorCantConvertTo(object, "Array", Layouts.SYMBOL.getString(conversionMethod), array, this));
}
}

return Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), new Object[] { object }, 1);
return Layouts.ARRAY.createArray(coreLibrary().getArrayFactory(), new Object[] { object }, 1);
}

}
Original file line number Diff line number Diff line change
@@ -57,7 +57,7 @@ public Object maybeTaint(DynamicObject source, DynamicObject result) {
taintNode = insert(TaintNodeGen.create(getContext(), getSourceSection(), null));
}

taintNode.taint(result);
taintNode.executeTaint(result);
}

return result;
Original file line number Diff line number Diff line change
@@ -56,9 +56,9 @@ public String coerceObject(VirtualFrame frame, Object object) {
try {
coerced = toStr.call(frame, object, "to_str", null);
} catch (RaiseException e) {
if (Layouts.BASIC_OBJECT.getLogicalClass(e.getException()) == getContext().getCoreLibrary().getNoMethodErrorClass()) {
if (Layouts.BASIC_OBJECT.getLogicalClass(e.getException()) == coreLibrary().getNoMethodErrorClass()) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().typeErrorNoImplicitConversion(object, "String", this));
throw new RaiseException(coreLibrary().typeErrorNoImplicitConversion(object, "String", this));
} else {
throw e;
}
@@ -68,7 +68,7 @@ public String coerceObject(VirtualFrame frame, Object object) {
return coerced.toString();
} else {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().typeErrorBadCoercion(object, "String", "to_str", coerced, this));
throw new RaiseException(coreLibrary().typeErrorBadCoercion(object, "String", "to_str", coerced, this));
}
}
}
Original file line number Diff line number Diff line change
@@ -56,9 +56,9 @@ public DynamicObject coerceObject(VirtualFrame frame, Object object) {
try {
coerced = toStr.call(frame, object, "to_str", null);
} catch (RaiseException e) {
if (Layouts.BASIC_OBJECT.getLogicalClass(e.getException()) == getContext().getCoreLibrary().getNoMethodErrorClass()) {
if (Layouts.BASIC_OBJECT.getLogicalClass(e.getException()) == coreLibrary().getNoMethodErrorClass()) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().typeErrorNoImplicitConversion(object, "String", this));
throw new RaiseException(coreLibrary().typeErrorNoImplicitConversion(object, "String", this));
} else {
throw e;
}
@@ -68,7 +68,7 @@ public DynamicObject coerceObject(VirtualFrame frame, Object object) {
return (DynamicObject) coerced;
} else {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().typeErrorBadCoercion(object, "String", "to_str", coerced, this));
throw new RaiseException(coreLibrary().typeErrorBadCoercion(object, "String", "to_str", coerced, this));
}
}
}
Original file line number Diff line number Diff line change
@@ -49,9 +49,9 @@ public DynamicObject coerceObject(VirtualFrame frame, Object object) {
try {
coerced = toAryNode.call(frame, object, "to_ary", null);
} catch (RaiseException e) {
if (Layouts.BASIC_OBJECT.getLogicalClass(e.getException()) == getContext().getCoreLibrary().getNoMethodErrorClass()) {
if (Layouts.BASIC_OBJECT.getLogicalClass(e.getException()) == coreLibrary().getNoMethodErrorClass()) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().typeErrorNoImplicitConversion(object, "Array", this));
throw new RaiseException(coreLibrary().typeErrorNoImplicitConversion(object, "Array", this));
} else {
throw e;
}
@@ -61,7 +61,7 @@ public DynamicObject coerceObject(VirtualFrame frame, Object object) {
return (DynamicObject) coerced;
} else {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().typeErrorBadCoercion(object, "Array", "to_ary", coerced, this));
throw new RaiseException(coreLibrary().typeErrorBadCoercion(object, "Array", "to_ary", coerced, this));
}
}
}
Original file line number Diff line number Diff line change
@@ -80,19 +80,19 @@ private double coerceObject(VirtualFrame frame, Object object) {
try {
coerced = toFNode.call(frame, object, "to_f", null);
} catch (RaiseException e) {
if (Layouts.BASIC_OBJECT.getLogicalClass(e.getException()) == getContext().getCoreLibrary().getNoMethodErrorClass()) {
if (Layouts.BASIC_OBJECT.getLogicalClass(e.getException()) == coreLibrary().getNoMethodErrorClass()) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().typeErrorNoImplicitConversion(object, "Float", this));
throw new RaiseException(coreLibrary().typeErrorNoImplicitConversion(object, "Float", this));
} else {
throw e;
}
}

if (getContext().getCoreLibrary().getLogicalClass(coerced) == getContext().getCoreLibrary().getFloatClass()) {
if (coreLibrary().getLogicalClass(coerced) == coreLibrary().getFloatClass()) {
return (double) coerced;
} else {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().typeErrorBadCoercion(object, "Float", "to_f", coerced, this));
throw new RaiseException(coreLibrary().typeErrorBadCoercion(object, "Float", "to_f", coerced, this));
}
}

Original file line number Diff line number Diff line change
@@ -64,7 +64,7 @@ public int doInt(VirtualFrame frame, Object object) {

CompilerDirectives.transferToInterpreter();
if (RubyGuards.isRubyBignum(object)) {
throw new RaiseException(getContext().getCoreLibrary().rangeError("bignum too big to convert into `long'", this));
throw new RaiseException(coreLibrary().rangeError("bignum too big to convert into `long'", this));
} else {
throw new UnsupportedOperationException(object.getClass().toString());
}
@@ -85,7 +85,7 @@ public long coerceLong(long value) {
@Specialization(guards = "isRubyBignum(value)")
public DynamicObject coerceRubyBignum(DynamicObject value) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().rangeError("bignum too big to convert into `long'", this));
throw new RaiseException(coreLibrary().rangeError("bignum too big to convert into `long'", this));
}

@Specialization
@@ -117,19 +117,19 @@ private Object coerceObject(VirtualFrame frame, Object object) {
try {
coerced = toIntNode.call(frame, object, "to_int", null);
} catch (RaiseException e) {
if (Layouts.BASIC_OBJECT.getLogicalClass(e.getException()) == getContext().getCoreLibrary().getNoMethodErrorClass()) {
if (Layouts.BASIC_OBJECT.getLogicalClass(e.getException()) == coreLibrary().getNoMethodErrorClass()) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().typeErrorNoImplicitConversion(object, "Integer", this));
throw new RaiseException(coreLibrary().typeErrorNoImplicitConversion(object, "Integer", this));
} else {
throw e;
}
}

if (getContext().getCoreLibrary().getLogicalClass(coerced) == getContext().getCoreLibrary().getFixnumClass()) {
if (coreLibrary().getLogicalClass(coerced) == coreLibrary().getFixnumClass()) {
return coerced;
} else {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().typeErrorBadCoercion(object, "Integer", "to_int", coerced, this));
throw new RaiseException(coreLibrary().typeErrorBadCoercion(object, "Integer", "to_int", coerced, this));
}
}

Original file line number Diff line number Diff line change
@@ -51,9 +51,9 @@ public DynamicObject doObject(VirtualFrame frame, Object object,
try {
coerced = toProc.call(frame, object, "to_proc", null);
} catch (RaiseException e) {
if (Layouts.BASIC_OBJECT.getLogicalClass(e.getException()) == getContext().getCoreLibrary().getNoMethodErrorClass()) {
if (Layouts.BASIC_OBJECT.getLogicalClass(e.getException()) == coreLibrary().getNoMethodErrorClass()) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().typeErrorNoImplicitConversion(object, "Proc", this));
throw new RaiseException(coreLibrary().typeErrorNoImplicitConversion(object, "Proc", this));
} else {
throw e;
}
@@ -63,7 +63,7 @@ public DynamicObject doObject(VirtualFrame frame, Object object,
return (DynamicObject) coerced;
} else {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().typeErrorBadCoercion(object, "Proc", "to_proc", coerced, this));
throw new RaiseException(coreLibrary().typeErrorBadCoercion(object, "Proc", "to_proc", coerced, this));
}
}

Original file line number Diff line number Diff line change
@@ -47,9 +47,9 @@ public DynamicObject coerceObject(VirtualFrame frame, Object object) {
try {
coerced = toStrNode.call(frame, object, "to_str", null);
} catch (RaiseException e) {
if (Layouts.BASIC_OBJECT.getLogicalClass(e.getException()) == getContext().getCoreLibrary().getNoMethodErrorClass()) {
if (Layouts.BASIC_OBJECT.getLogicalClass(e.getException()) == coreLibrary().getNoMethodErrorClass()) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().typeErrorNoImplicitConversion(object, "String", this));
throw new RaiseException(coreLibrary().typeErrorNoImplicitConversion(object, "String", this));
} else {
throw e;
}
@@ -59,7 +59,7 @@ public DynamicObject coerceObject(VirtualFrame frame, Object object) {
return (DynamicObject) coerced;
} else {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().typeErrorBadCoercion(object, "String", "to_str", coerced, this));
throw new RaiseException(coreLibrary().typeErrorBadCoercion(object, "String", "to_str", coerced, this));
}
}

Original file line number Diff line number Diff line change
@@ -72,7 +72,7 @@ public DynamicObject initialize(DynamicObject self, Object source, Object destin
// by Rubinius. Rubinius will do the heavy lifting of parsing the options hash and setting the `@options`
// ivar to the resulting int for EConv flags. Since we don't pass the proper data structures to EncodingUtils,
// we must override the flags after its had a pass in order to correct the bad flags value.
ecflags[0] = rubiniusToJRubyFlags((int) self.get("@options", getContext().getCoreLibrary().getNilObject()));
ecflags[0] = rubiniusToJRubyFlags((int) self.get("@options", coreLibrary().getNilObject()));

EConv econv = EncodingUtils.econvOpenOpts(runtime.getCurrentContext(), encNames[0], encNames[1], ecflags[0], ecopts[0]);

@@ -147,11 +147,11 @@ public TranscodingMapNode(RubyContext context, SourceSection sourceSection) {

@Specialization
public Object transcodingMap(VirtualFrame frame) {
final Object ret = newLookupTableNode.call(frame, getContext().getCoreLibrary().getLookupTableClass(), "new", null);
final Object ret = newLookupTableNode.call(frame, coreLibrary().getLookupTableClass(), "new", null);

for (CaseInsensitiveBytesHash<TranscoderDB.Entry> sourceEntry : TranscoderDB.transcoders) {
Object key = null;
final Object value = newLookupTableNode.call(frame, getContext().getCoreLibrary().getLookupTableClass(), "new", null);
final Object value = newLookupTableNode.call(frame, coreLibrary().getLookupTableClass(), "new", null);

for (Hash.HashEntry<TranscoderDB.Entry> destinationEntry : sourceEntry.entryIterator()) {
final TranscoderDB.Entry e = destinationEntry.value;
@@ -163,7 +163,7 @@ public Object transcodingMap(VirtualFrame frame) {

final Object upcasedLookupTableKey = upcaseNode.call(frame, createString(new ByteList(e.getDestination())), "upcase", null);
final Object lookupTableKey = toSymNode.call(frame, upcasedLookupTableKey, "to_sym", null);
final Object lookupTableValue = newTranscodingNode.call(frame, getContext().getCoreLibrary().getTranscodingClass(), "create", null, key, lookupTableKey);
final Object lookupTableValue = newTranscodingNode.call(frame, coreLibrary().getTranscodingClass(), "create", null, key, lookupTableKey);
lookupTableWriteNode.call(frame, value, "[]=", null, lookupTableKey, lookupTableValue);
}

Original file line number Diff line number Diff line change
@@ -337,7 +337,7 @@ public DynamicObject defaultExternal(DynamicObject encodingString) {

@Specialization(guards = "isNil(nil)")
public DynamicObject defaultExternal(Object nil) {
throw new RaiseException(getContext().getCoreLibrary().argumentError("default external can not be nil", this));
throw new RaiseException(coreLibrary().argumentError("default external can not be nil", this));
}

@Specialization(guards = { "!isRubyEncoding(encoding)", "!isRubyString(encoding)", "!isNil(encoding)" })
@@ -410,7 +410,7 @@ public DynamicObject list() {

final Object[] encodings = cloneEncodingList();

return Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), encodings, encodings.length);
return Layouts.ARRAY.createArray(coreLibrary().getArrayFactory(), encodings, encodings.length);
}
}

@@ -464,13 +464,13 @@ public EncodingMapNode(RubyContext context, SourceSection sourceSection) {

@Specialization
public Object encodingMap(VirtualFrame frame) {
Object ret = newLookupTableNode.call(frame, getContext().getCoreLibrary().getLookupTableClass(), "new", null);
Object ret = newLookupTableNode.call(frame, coreLibrary().getLookupTableClass(), "new", null);

final DynamicObject[] encodings = ENCODING_LIST;
for (int i = 0; i < encodings.length; i++) {
final Object upcased = upcaseNode.call(frame, createString(Layouts.ENCODING.getName(encodings[i])), "upcase", null);
final Object key = toSymNode.call(frame, upcased, "to_sym", null);
final Object value = newTupleNode.call(frame, getContext().getCoreLibrary().getTupleClass(), "create", null, nil(), i);
final Object value = newTupleNode.call(frame, coreLibrary().getTupleClass(), "create", null, nil(), i);

lookupTableWriteNode.call(frame, ret, "[]=", null, key, value);
}
@@ -486,7 +486,7 @@ public Object encodingMap(VirtualFrame frame) {
final int index = e.value.getIndex();


final Object value = newTupleNode.call(frame, getContext().getCoreLibrary().getTupleClass(), "create", null, alias, index);
final Object value = newTupleNode.call(frame, coreLibrary().getTupleClass(), "create", null, alias, index);
lookupTableWriteNode.call(frame, ret, "[]=", null, key, value);
}

@@ -510,7 +510,7 @@ public Object encodingMap(VirtualFrame frame) {
}

private Object makeTuple(VirtualFrame frame, CallDispatchHeadNode newTupleNode, Object... values) {
return newTupleNode.call(frame, getContext().getCoreLibrary().getTupleClass(), "create", null, values);
return newTupleNode.call(frame, coreLibrary().getTupleClass(), "create", null, values);
}

@TruffleBoundary
@@ -563,7 +563,7 @@ public AllocateNode(RubyContext context, SourceSection sourceSection) {
@TruffleBoundary
@Specialization
public DynamicObject allocate(DynamicObject rubyClass) {
throw new RaiseException(getContext().getCoreLibrary().typeErrorAllocatorUndefinedFor(rubyClass, this));
throw new RaiseException(coreLibrary().typeErrorAllocatorUndefinedFor(rubyClass, this));
}

}
Original file line number Diff line number Diff line change
@@ -26,8 +26,8 @@
import org.jruby.truffle.language.backtrace.BacktraceFormatter;
import org.jruby.truffle.language.objects.AllocateObjectNode;
import org.jruby.truffle.language.objects.AllocateObjectNodeGen;
import org.jruby.truffle.language.objects.ReadHeadObjectFieldNode;
import org.jruby.truffle.language.objects.ReadHeadObjectFieldNodeGen;
import org.jruby.truffle.language.objects.ReadObjectFieldNode;
import org.jruby.truffle.language.objects.ReadObjectFieldNodeGen;

import java.util.EnumSet;
import java.util.List;
@@ -85,11 +85,11 @@ public DynamicObject initialize(DynamicObject exception, Object message) {
@CoreMethod(names = "backtrace")
public abstract static class BacktraceNode extends CoreMethodArrayArgumentsNode {

@Child ReadHeadObjectFieldNode readCustomBacktrace;
@Child ReadObjectFieldNode readCustomBacktrace;

public BacktraceNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
readCustomBacktrace = ReadHeadObjectFieldNodeGen.create(getContext(), "@custom_backtrace", null);
readCustomBacktrace = ReadObjectFieldNodeGen.create(getContext(), "@custom_backtrace", null);
}

@Specialization
Original file line number Diff line number Diff line change
@@ -238,13 +238,13 @@ protected Object transfer(VirtualFrame frame, DynamicObject fiber, boolean isYie
CompilerDirectives.transferToInterpreter();

if (!Layouts.FIBER.getAlive(fiber)) {
throw new RaiseException(getContext().getCoreLibrary().deadFiberCalledError(this));
throw new RaiseException(coreLibrary().deadFiberCalledError(this));
}

DynamicObject currentThread = getContext().getThreadManager().getCurrentThread();
if (Layouts.FIBER.getRubyThread(fiber) != currentThread) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().fiberError("fiber called across threads", this));
throw new RaiseException(coreLibrary().fiberError("fiber called across threads", this));
}

final DynamicObject sendingFiber = Layouts.THREAD.getFiberManager(currentThread).getCurrentFiber();
@@ -304,7 +304,7 @@ public Object yield(VirtualFrame frame, Object[] args) {
final DynamicObject fiberYieldedTo = Layouts.FIBER.getLastResumedByFiber(yieldingFiber);

if (Layouts.FIBER.getRootFiber(yieldingFiber) || fiberYieldedTo == null) {
throw new RaiseException(getContext().getCoreLibrary().yieldFromRootFiberError(this));
throw new RaiseException(coreLibrary().yieldFromRootFiberError(this));
}

return fiberTransferNode.executeTransferControlTo(frame, fiberYieldedTo, true, args);
Original file line number Diff line number Diff line change
@@ -77,7 +77,7 @@ public EmptyHashLiteralNode(RubyContext context, SourceSection sourceSection) {
@ExplodeLoop
@Override
public Object execute(VirtualFrame frame) {
return Layouts.HASH.createHash(getContext().getCoreLibrary().getHashFactory(), null, 0, null, null, null, null, false);
return Layouts.HASH.createHash(coreLibrary().getHashFactory(), null, 0, null, null, null, null, false);
}

}
@@ -135,7 +135,7 @@ public Object execute(VirtualFrame frame) {
size++;
}

return Layouts.HASH.createHash(getContext().getCoreLibrary().getHashFactory(), store, size, null, null, null, null, false);
return Layouts.HASH.createHash(coreLibrary().getHashFactory(), store, size, null, null, null, null, false);
}

}
@@ -159,7 +159,7 @@ public Object execute(VirtualFrame frame) {
final int bucketsCount = BucketsStrategy.capacityGreaterThan(keyValues.length / 2) * BucketsStrategy.OVERALLOCATE_FACTOR;
final Entry[] newEntries = new Entry[bucketsCount];

final DynamicObject hash = Layouts.HASH.createHash(getContext().getCoreLibrary().getHashFactory(), newEntries, 0, null, null, null, null, false);
final DynamicObject hash = Layouts.HASH.createHash(coreLibrary().getHashFactory(), newEntries, 0, null, null, null, null, false);

for (int n = 0; n < keyValues.length; n += 2) {
final Object key = keyValues[n].execute(frame);
18 changes: 9 additions & 9 deletions truffle/src/main/java/org/jruby/truffle/core/hash/HashNodes.java
Original file line number Diff line number Diff line change
@@ -128,7 +128,7 @@ public Object construct(VirtualFrame frame, DynamicObject hashClass, Object[] ar

@Specialization(guards = "!isSmallArrayOfPairs(args)")
public Object constructFallback(VirtualFrame frame, DynamicObject hashClass, Object[] args) {
return ruby("_constructor_fallback(*args)", "args", Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), args, args.length));
return ruby("_constructor_fallback(*args)", "args", Layouts.ARRAY.createArray(coreLibrary().getArrayFactory(), args, args.length));
}

public boolean isSmallArrayOfPairs(Object[] args) {
@@ -610,7 +610,7 @@ public Object each(VirtualFrame frame, DynamicObject hash, NotProvided block) {
}

private Object yieldPair(VirtualFrame frame, DynamicObject block, Object key, Object value) {
return yield(frame, block, Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), new Object[] { key, value }, 2));
return yield(frame, block, Layouts.ARRAY.createArray(coreLibrary().getArrayFactory(), new Object[] { key, value }, 2));
}

}
@@ -685,7 +685,7 @@ public DynamicObject initialize(DynamicObject hash, Object defaultValue, NotProv
@Specialization(guards = "wasProvided(defaultValue)")
public Object initialize(DynamicObject hash, Object defaultValue, DynamicObject block) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().argumentError("wrong number of arguments (1 for 0)", this));
throw new RaiseException(coreLibrary().argumentError("wrong number of arguments (1 for 0)", this));
}

}
@@ -777,7 +777,7 @@ public MapNode(RubyContext context, SourceSection sourceSection) {
public DynamicObject mapNull(VirtualFrame frame, DynamicObject hash, DynamicObject block) {
assert HashOperations.verifyStore(getContext(), hash);

return Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), null, 0);
return Layouts.ARRAY.createArray(coreLibrary().getArrayFactory(), null, 0);
}

@ExplodeLoop
@@ -805,7 +805,7 @@ public DynamicObject mapPackedArray(VirtualFrame frame, DynamicObject hash, Dyna
}
}

return Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), arrayBuilderNode.finish(resultStore, length), length);
return Layouts.ARRAY.createArray(coreLibrary().getArrayFactory(), arrayBuilderNode.finish(resultStore, length), length);
}

@Specialization(guards = "isBucketHash(hash)")
@@ -829,11 +829,11 @@ public DynamicObject mapBuckets(VirtualFrame frame, DynamicObject hash, DynamicO
}
}

return Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), arrayBuilderNode.finish(store, length), length);
return Layouts.ARRAY.createArray(coreLibrary().getArrayFactory(), arrayBuilderNode.finish(store, length), length);
}

private Object yieldPair(VirtualFrame frame, DynamicObject block, Object key, Object value) {
return yield(frame, block, Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), new Object[] { key, value }, 2));
return yield(frame, block, Layouts.ARRAY.createArray(coreLibrary().getArrayFactory(), new Object[] { key, value }, 2));
}

}
@@ -1231,7 +1231,7 @@ public DynamicObject shiftPackedArray(DynamicObject hash) {
assert HashOperations.verifyStore(getContext(), hash);

Object[] objects = new Object[]{key, value};
return Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), objects, objects.length);
return Layouts.ARRAY.createArray(coreLibrary().getArrayFactory(), objects, objects.length);
}

@Specialization(guards = {"!isEmptyHash(hash)", "isBucketHash(hash)"})
@@ -1291,7 +1291,7 @@ public DynamicObject shiftBuckets(DynamicObject hash) {
assert HashOperations.verifyStore(getContext(), hash);

Object[] objects = new Object[]{key, value};
return Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), objects, objects.length);
return Layouts.ARRAY.createArray(coreLibrary().getArrayFactory(), objects, objects.length);
}

}
108 changes: 54 additions & 54 deletions truffle/src/main/java/org/jruby/truffle/core/kernel/KernelNodes.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -117,7 +117,7 @@ public void newProbeInserted(Probe probe) {

@Override
public void probeTaggedAs(Probe probe, SyntaxTag tag, Object tagValue) {
if (eventFactories.containsKey(tag)) {
if (instruments != null && eventFactories.containsKey(tag)) {
instruments.add(context.getEnv().instrumenter().attach(probe, eventFactories.get(tag).createInstrumentListener(context, traceFunc), "set_trace_func"));
}
}
Original file line number Diff line number Diff line change
@@ -268,7 +268,7 @@ void moduleInitialize(VirtualFrame frame, DynamicObject rubyClass, DynamicObject

@Specialization
public DynamicObject initialize(VirtualFrame frame, DynamicObject rubyClass, NotProvided superclass, NotProvided block) {
return initializeGeneralWithoutBlock(frame, rubyClass, getContext().getCoreLibrary().getObjectClass());
return initializeGeneralWithoutBlock(frame, rubyClass, coreLibrary().getObjectClass());
}

@Specialization(guards = "isRubyClass(superclass)")
@@ -278,7 +278,7 @@ public DynamicObject initialize(VirtualFrame frame, DynamicObject rubyClass, Dyn

@Specialization
public DynamicObject initialize(VirtualFrame frame, DynamicObject rubyClass, NotProvided superclass, DynamicObject block) {
return initializeGeneralWithBlock(frame, rubyClass, getContext().getCoreLibrary().getObjectClass(), block);
return initializeGeneralWithBlock(frame, rubyClass, coreLibrary().getObjectClass(), block);
}

@Specialization(guards = "isRubyClass(superclass)")
@@ -349,7 +349,7 @@ public AllocateConstructorNode(RubyContext context, SourceSection sourceSection)

@Specialization
public DynamicObject allocate(DynamicObject rubyClass) {
return createRubyClass(getContext(), getContext().getCoreLibrary().getClassClass(), null, getContext().getCoreLibrary().getObjectClass(), null, false, null);
return createRubyClass(getContext(), coreLibrary().getClassClass(), null, coreLibrary().getObjectClass(), null, false, null);
}

}
Original file line number Diff line number Diff line change
@@ -44,8 +44,8 @@
import org.jruby.truffle.language.methods.CallMethodNodeGen;
import org.jruby.truffle.language.methods.DeclarationContext;
import org.jruby.truffle.language.methods.InternalMethod;
import org.jruby.truffle.language.objects.ClassNode;
import org.jruby.truffle.language.objects.ClassNodeGen;
import org.jruby.truffle.language.objects.LogicalClassNode;
import org.jruby.truffle.language.objects.LogicalClassNodeGen;

@CoreClass(name = "Method")
public abstract class MethodNodes {
@@ -198,7 +198,7 @@ public Object sourceLocation(DynamicObject method) {
} else {
DynamicObject file = createString(StringOperations.encodeRope(sourceSection.getSource().getName(), UTF8Encoding.INSTANCE));
Object[] objects = new Object[]{file, sourceSection.getStartLine()};
return Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), objects, objects.length);
return Layouts.ARRAY.createArray(coreLibrary().getArrayFactory(), objects, objects.length);
}
}

@@ -207,17 +207,17 @@ public Object sourceLocation(DynamicObject method) {
@CoreMethod(names = "unbind")
public abstract static class UnbindNode extends CoreMethodArrayArgumentsNode {

@Child private ClassNode classNode;
@Child private LogicalClassNode classNode;

public UnbindNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
classNode = ClassNodeGen.create(context, sourceSection, null);
classNode = LogicalClassNodeGen.create(context, sourceSection, null);
}

@Specialization
public DynamicObject unbind(VirtualFrame frame, DynamicObject method) {
final DynamicObject receiverClass = classNode.executeGetClass(frame, Layouts.METHOD.getReceiver(method));
return Layouts.UNBOUND_METHOD.createUnboundMethod(getContext().getCoreLibrary().getUnboundMethodFactory(), receiverClass, Layouts.METHOD.getMethod(method));
final DynamicObject receiverClass = classNode.executeLogicalClass(Layouts.METHOD.getReceiver(method));
return Layouts.UNBOUND_METHOD.createUnboundMethod(coreLibrary().getUnboundMethodFactory(), receiverClass, Layouts.METHOD.getMethod(method));
}

}
@@ -242,7 +242,7 @@ public DynamicObject toProcUncached(DynamicObject methodObject) {
final InternalMethod method = Layouts.METHOD.getMethod(methodObject);

return ProcNodes.createRubyProc(
getContext().getCoreLibrary().getProcFactory(),
coreLibrary().getProcFactory(),
ProcNodes.Type.LAMBDA,
method.getSharedMethodInfo(),
callTarget,
@@ -303,7 +303,7 @@ public AllocateNode(RubyContext context, SourceSection sourceSection) {
@TruffleBoundary
@Specialization
public DynamicObject allocate(DynamicObject rubyClass) {
throw new RaiseException(getContext().getCoreLibrary().typeErrorAllocatorUndefinedFor(rubyClass, this));
throw new RaiseException(coreLibrary().typeErrorAllocatorUndefinedFor(rubyClass, this));
}

}
Original file line number Diff line number Diff line change
@@ -88,15 +88,15 @@ public DynamicObject bind(DynamicObject unboundMethod, Object object) {
CompilerDirectives.transferToInterpreter();
final DynamicObject declaringModule = Layouts.UNBOUND_METHOD.getMethod(unboundMethod).getDeclaringModule();
if (RubyGuards.isRubyClass(declaringModule) && Layouts.CLASS.getIsSingleton(declaringModule)) {
throw new RaiseException(getContext().getCoreLibrary().typeError(
throw new RaiseException(coreLibrary().typeError(
"singleton method called for a different object", this));
} else {
throw new RaiseException(getContext().getCoreLibrary().typeError(
throw new RaiseException(coreLibrary().typeError(
"bind argument must be an instance of " + Layouts.MODULE.getFields(declaringModule).getName(), this));
}
}

return Layouts.METHOD.createMethod(getContext().getCoreLibrary().getMethodFactory(), object, Layouts.UNBOUND_METHOD.getMethod(unboundMethod));
return Layouts.METHOD.createMethod(coreLibrary().getMethodFactory(), object, Layouts.UNBOUND_METHOD.getMethod(unboundMethod));
}

protected DynamicObject metaClass(Object object) {
@@ -182,7 +182,7 @@ public Object sourceLocation(DynamicObject unboundMethod) {
} else {
DynamicObject file = createString(StringOperations.encodeRope(sourceSection.getSource().getName(), UTF8Encoding.INSTANCE));
Object[] objects = new Object[]{file, sourceSection.getStartLine()};
return Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), objects, objects.length);
return Layouts.ARRAY.createArray(coreLibrary().getArrayFactory(), objects, objects.length);
}
}

@@ -198,7 +198,7 @@ public AllocateNode(RubyContext context, SourceSection sourceSection) {
@TruffleBoundary
@Specialization
public DynamicObject allocate(DynamicObject rubyClass) {
throw new RaiseException(getContext().getCoreLibrary().typeErrorAllocatorUndefinedFor(rubyClass, this));
throw new RaiseException(coreLibrary().typeErrorAllocatorUndefinedFor(rubyClass, this));
}

}
Original file line number Diff line number Diff line change
@@ -25,7 +25,7 @@
import org.jruby.truffle.language.RubyGuards;
import org.jruby.truffle.language.RubyNode;
import org.jruby.truffle.language.control.RaiseException;
import org.jruby.truffle.language.literal.LiteralNode;
import org.jruby.truffle.language.literal.ObjectLiteralNode;
import org.jruby.truffle.language.methods.InternalMethod;
import org.jruby.truffle.language.objects.IsFrozenNodeGen;
import org.jruby.truffle.language.objects.ObjectGraphNode;
@@ -165,7 +165,7 @@ public void checkFrozen(RubyContext context, Node currentNode) {

// TODO CS 20-Aug-15 this needs to go
public static boolean verySlowIsFrozen(RubyContext context, Object object) {
final RubyNode node = IsFrozenNodeGen.create(context, null, new LiteralNode(context, null, object));
final RubyNode node = IsFrozenNodeGen.create(context, null, new ObjectLiteralNode(context, null, object));
new Node() {
@Child RubyNode child = node;
}.adoptChildren();

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -217,7 +217,7 @@ public long sleep(DynamicObject mutex, double duration) {

public long doSleepMillis(DynamicObject mutex, long durationInMillis) {
if (durationInMillis < 0) {
throw new RaiseException(getContext().getCoreLibrary().argumentError("time interval must be positive", this));
throw new RaiseException(coreLibrary().argumentError("time interval must be positive", this));
}

final ReentrantLock lock = Layouts.MUTEX.getLock(mutex);
Original file line number Diff line number Diff line change
@@ -538,7 +538,7 @@ public DynamicObject coerce(DynamicObject a, int b) {
// TODO (eregon, 16 Feb. 2015): This is NOT spec, but let's try to see if we can make it work.
// b is converted to a Bignum here in other implementations.
Object[] store = new Object[] { b, a };
return Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), store, store.length);
return Layouts.ARRAY.createArray(coreLibrary().getArrayFactory(), store, store.length);
}

@Specialization
@@ -548,15 +548,15 @@ public DynamicObject coerce(DynamicObject a, long b) {
// TODO (eregon, 16 Feb. 2015): This is NOT spec, but let's try to see if we can make it work.
// b is converted to a Bignum here in other implementations.
Object[] store = new Object[] { b, a };
return Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), store, store.length);
return Layouts.ARRAY.createArray(coreLibrary().getArrayFactory(), store, store.length);
}

@Specialization(guards = "isRubyBignum(b)")
public DynamicObject coerce(DynamicObject a, DynamicObject b) {
CompilerDirectives.transferToInterpreter();

Object[] store = new Object[] { b, a };
return Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), store, store.length);
return Layouts.ARRAY.createArray(coreLibrary().getArrayFactory(), store, store.length);
}

}
@@ -678,7 +678,7 @@ public DynamicObject toS(DynamicObject value, NotProvided base) {
public DynamicObject toS(DynamicObject value, int base) {
if (base < 2 || base > 36) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().argumentErrorInvalidRadix(base, this));
throw new RaiseException(coreLibrary().argumentErrorInvalidRadix(base, this));
}

return create7BitString(Layouts.BIGNUM.getValue(value).toString(base), USASCIIEncoding.INSTANCE);
@@ -696,7 +696,7 @@ public AllocateNode(RubyContext context, SourceSection sourceSection) {
@TruffleBoundary
@Specialization
public DynamicObject allocate(DynamicObject rubyClass) {
throw new RaiseException(getContext().getCoreLibrary().typeErrorAllocatorUndefinedFor(rubyClass, this));
throw new RaiseException(coreLibrary().typeErrorAllocatorUndefinedFor(rubyClass, this));
}

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -439,7 +439,7 @@ public Object mod(long a, DynamicObject b) {

if (mod < 0 && Layouts.BIGNUM.getValue(b).compareTo(BigInteger.ZERO) > 0 || mod > 0 && Layouts.BIGNUM.getValue(b).compareTo(BigInteger.ZERO) < 0) {
adjustProfile.enter();
return Layouts.BIGNUM.createBignum(getContext().getCoreLibrary().getBignumFactory(), BigInteger.valueOf(mod).add(Layouts.BIGNUM.getValue(b)));
return Layouts.BIGNUM.createBignum(coreLibrary().getBignumFactory(), BigInteger.valueOf(mod).add(Layouts.BIGNUM.getValue(b)));
}

return mod;
@@ -1007,7 +1007,7 @@ public long absInBounds(long n) {
@Specialization(contains = "absInBounds")
public Object abs(long n) {
if (n == Long.MIN_VALUE) {
return Layouts.BIGNUM.createBignum(getContext().getCoreLibrary().getBignumFactory(), BigInteger.valueOf(n).abs());
return Layouts.BIGNUM.createBignum(coreLibrary().getBignumFactory(), BigInteger.valueOf(n).abs());
}
return (n < 0) ? -n : n;
}
@@ -1138,7 +1138,7 @@ public DynamicObject toS(long n, NotProvided base) {
public DynamicObject toS(long n, int base) {
if (base < 2 || base > 36) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().argumentErrorInvalidRadix(base, this));
throw new RaiseException(coreLibrary().argumentErrorInvalidRadix(base, this));
}

return create7BitString(Long.toString(n, base), USASCIIEncoding.INSTANCE);
Original file line number Diff line number Diff line change
@@ -57,7 +57,7 @@ public Object fixnumOrBignum(BigInteger value) {
return longValue;
}
} else {
return Layouts.BIGNUM.createBignum(getContext().getCoreLibrary().getBignumFactory(), value);
return Layouts.BIGNUM.createBignum(coreLibrary().getBignumFactory(), value);
}
}

Original file line number Diff line number Diff line change
@@ -159,7 +159,7 @@ public Object pow(VirtualFrame frame, double a, double b) {
complexPowNode = insert(DispatchHeadNodeFactory.createMethodCall(getContext()));
}

final Object aComplex = complexConvertNode.call(frame, getContext().getCoreLibrary().getComplexClass(), "convert", null, a, 0);
final Object aComplex = complexConvertNode.call(frame, coreLibrary().getComplexClass(), "convert", null, a, 0);

return complexPowNode.call(frame, aComplex, "**", null, b);
} else {
@@ -237,7 +237,7 @@ public double mod(double a, long b) {
public double mod(double a, double b) {
if (b == 0) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().zeroDivisionError(this));
throw new RaiseException(coreLibrary().zeroDivisionError(this));
}

double result = Math.IEEEremainder(a, b);
@@ -645,12 +645,12 @@ public Object round(double n, NotProvided ndigits,

if (Double.isInfinite(n)) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().floatDomainError("Infinity", this));
throw new RaiseException(coreLibrary().floatDomainError("Infinity", this));
}

if (Double.isNaN(n)) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().floatDomainError("NaN", this));
throw new RaiseException(coreLibrary().floatDomainError("NaN", this));
}

double f = n;
@@ -695,12 +695,12 @@ public ToINode(RubyContext context, SourceSection sourceSection) {
Object toI(double value) {
if (Double.isInfinite(value)) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().floatDomainError("Infinity", this));
throw new RaiseException(coreLibrary().floatDomainError("Infinity", this));
}

if (Double.isNaN(value)) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().floatDomainError("NaN", this));
throw new RaiseException(coreLibrary().floatDomainError("NaN", this));
}

return fixnumOrBignum.fixnumOrBignum(value);
Original file line number Diff line number Diff line change
@@ -111,13 +111,13 @@ private DynamicObject divMod(long a, long b) {

if (integerDiv instanceof Long && ((long) integerDiv) >= Integer.MIN_VALUE && ((long) integerDiv) <= Integer.MAX_VALUE && mod >= Integer.MIN_VALUE && mod <= Integer.MAX_VALUE) {
useFixnumPairProfile.enter();
return Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), new int[]{(int) (long) integerDiv, (int) mod}, 2);
return Layouts.ARRAY.createArray(coreLibrary().getArrayFactory(), new int[]{(int) (long) integerDiv, (int) mod}, 2);
} else if (integerDiv instanceof Long) {
useObjectPairProfile.enter();
return Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), new Object[]{integerDiv, mod}, 2);
return Layouts.ARRAY.createArray(coreLibrary().getArrayFactory(), new Object[]{integerDiv, mod}, 2);
} else {
useObjectPairProfile.enter();
return Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), new Object[]{
return Layouts.ARRAY.createArray(coreLibrary().getArrayFactory(), new Object[]{
fixnumOrBignumQuotient.fixnumOrBignum((BigInteger) integerDiv),
mod}, 2);
}
@@ -134,7 +134,7 @@ private DynamicObject divMod(double a, double b) {

if (Double.isNaN(mod)) {
nanProfile.enter();
throw new RaiseException(getContext().getCoreLibrary().floatDomainError("NaN", this));
throw new RaiseException(coreLibrary().floatDomainError("NaN", this));
}

final double div = Math.floor(a / b);
@@ -143,7 +143,7 @@ private DynamicObject divMod(double a, double b) {
mod += b;
}

return Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), new Object[]{
return Layouts.ARRAY.createArray(coreLibrary().getArrayFactory(), new Object[]{
fixnumOrBignumQuotient.fixnumOrBignum(div),
mod}, 2);
}
@@ -163,13 +163,13 @@ private DynamicObject divMod(BigInteger a, BigInteger b) {
bigIntegerResults[1] = b.add(bigIntegerResults[1]);
}

return Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), new Object[]{
return Layouts.ARRAY.createArray(coreLibrary().getArrayFactory(), new Object[]{
fixnumOrBignumQuotient.fixnumOrBignum(bigIntegerResults[0]),
fixnumOrBignumRemainder.fixnumOrBignum(bigIntegerResults[1])}, 2);
}

public DynamicObject create(BigInteger value) {
return Layouts.BIGNUM.createBignum(getContext().getCoreLibrary().getBignumFactory(), value);
return Layouts.BIGNUM.createBignum(coreLibrary().getBignumFactory(), value);
}

@Override
Original file line number Diff line number Diff line change
@@ -123,7 +123,7 @@ public DynamicObject times(VirtualFrame frame, int n, NotProvided block) {
array[i] = i;
}

return Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), array, n);
return Layouts.ARRAY.createArray(coreLibrary().getArrayFactory(), array, n);
}

@Specialization
Original file line number Diff line number Diff line change
@@ -30,8 +30,8 @@
import org.jruby.truffle.language.dispatch.DoesRespondDispatchHeadNode;
import org.jruby.truffle.language.objects.ObjectGraph;
import org.jruby.truffle.language.objects.ObjectIDOperations;
import org.jruby.truffle.language.objects.ReadHeadObjectFieldNode;
import org.jruby.truffle.language.objects.ReadHeadObjectFieldNodeGen;
import org.jruby.truffle.language.objects.ReadObjectFieldNode;
import org.jruby.truffle.language.objects.ReadObjectFieldNodeGen;

@CoreClass(name = "ObjectSpace")
public abstract class ObjectSpaceNodes {
@@ -68,15 +68,15 @@ public long id2RefSmallInt(long id) {
@Specialization(guards = "isBasicObjectID(id)")
public DynamicObject id2Ref(
final long id,
@Cached("createReadObjectIDNode()") ReadHeadObjectFieldNode readObjectIdNode) {
@Cached("createReadObjectIDNode()") ReadObjectFieldNode readObjectIdNode) {
for (DynamicObject object : ObjectGraph.stopAndGetAllObjects(this, getContext())) {
final long objectID = (long) readObjectIdNode.execute(object);
if (objectID == id) {
return object;
}
}

throw new RaiseException(getContext().getCoreLibrary().rangeError(String.format("0x%016x is not id value", id), this));
throw new RaiseException(coreLibrary().rangeError(String.format("0x%016x is not id value", id), this));
}

@Specialization(guards = { "isRubyBignum(id)", "isLargeFixnumID(id)" })
@@ -89,8 +89,8 @@ public double id2RefFloat(DynamicObject id) {
return Double.longBitsToDouble(Layouts.BIGNUM.getValue(id).longValue());
}

protected ReadHeadObjectFieldNode createReadObjectIDNode() {
return ReadHeadObjectFieldNodeGen.create(getContext(), Layouts.OBJECT_ID_IDENTIFIER, 0L);
protected ReadObjectFieldNode createReadObjectIDNode() {
return ReadObjectFieldNodeGen.create(getContext(), Layouts.OBJECT_ID_IDENTIFIER, 0L);
}

protected boolean isLargeFixnumID(DynamicObject id) {
@@ -166,10 +166,10 @@ public DynamicObject defineFinalizer(VirtualFrame frame, DynamicObject object, O
if (respondToCallNode.doesRespondTo(frame, "call", finalizer)) {
getContext().getObjectSpaceManager().defineFinalizer(object, finalizer);
Object[] objects = new Object[]{ 0, finalizer };
return Layouts.ARRAY.createArray(getContext().getCoreLibrary().getArrayFactory(), objects, objects.length);
return Layouts.ARRAY.createArray(coreLibrary().getArrayFactory(), objects, objects.length);
} else {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().argumentErrorWrongArgumentType(finalizer, "callable", this));
throw new RaiseException(coreLibrary().argumentErrorWrongArgumentType(finalizer, "callable", this));
}
}

Loading

0 comments on commit 461172d

Please sign in to comment.