Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: bd6298cdb85c
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 58546722a724
Choose a head ref
  • 3 commits
  • 7 files changed
  • 1 contributor

Commits on Jan 21, 2015

  1. [Truffle] Remove duplication between ClassNode and Kernel's version.

    * Always use the clean (and better implemetned for boolean) ClassNode.
    eregon committed Jan 21, 2015
    Copy the full SHA
    02ccb29 View commit details
  2. Copy the full SHA
    9f7835a View commit details
  3. [Truffle] Re-organize primitive classes: use the first word in the pr…

    …imitive.
    
    * Allows O(1) lookup from the file structure to find it.
    * Sort the nodes alphabetically.
    eregon committed Jan 21, 2015
    Copy the full SHA
    5854672 View commit details
52 changes: 15 additions & 37 deletions core/src/main/java/org/jruby/truffle/nodes/core/KernelNodes.java
Original file line number Diff line number Diff line change
@@ -26,6 +26,8 @@
import org.jruby.truffle.nodes.dispatch.*;
import org.jruby.truffle.nodes.globals.WrapInThreadLocalNode;
import org.jruby.truffle.nodes.literal.BooleanLiteralNode;
import org.jruby.truffle.nodes.objects.ClassNode;
import org.jruby.truffle.nodes.objects.ClassNodeFactory;
import org.jruby.truffle.nodes.objects.SingletonClassNode;
import org.jruby.truffle.nodes.objects.SingletonClassNodeFactory;
import org.jruby.truffle.nodes.objectstorage.ReadHeadObjectFieldNode;
@@ -420,47 +422,23 @@ public Object doCatch(VirtualFrame frame, Object tag, RubyProc block) {
}

@CoreMethod(names = "class")
public abstract static class ClassNode extends CoreMethodNode {
public abstract static class KernelClassNode extends CoreMethodNode {

public ClassNode(RubyContext context, SourceSection sourceSection) {
@Child private ClassNode classNode;

public KernelClassNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
classNode = ClassNodeFactory.create(context, sourceSection, null);
}

public ClassNode(ClassNode prev) {
public KernelClassNode(KernelClassNode prev) {
super(prev);
}

public abstract RubyClass executeGetClass(VirtualFrame frame, Object value);

@Specialization
public RubyClass getClass(boolean value) {
notDesignedForCompilation();

if (value) {
return getContext().getCoreLibrary().getTrueClass();
} else {
return getContext().getCoreLibrary().getFalseClass();
}
}

@Specialization
public RubyClass getClass(int value) {
return getContext().getCoreLibrary().getFixnumClass();
}

@Specialization
public RubyClass getClass(long value) {
return getContext().getCoreLibrary().getFixnumClass();
}

@Specialization
public RubyClass getClass(double value) {
return getContext().getCoreLibrary().getFloatClass();
classNode = prev.classNode;
}

@Specialization
public RubyClass getClass(RubyBasicObject self) {
return self.getLogicalClass();
public RubyClass getClass(Object self) {
return classNode.executeGetClass(self);
}

}
@@ -2186,13 +2164,13 @@ public String toHexString(RubyBignum value) {
public abstract static class ToSNode extends CoreMethodNode {

@Child private ClassNode classNode;
@Child private ObjectPrimitiveNodes.ObjectIDNode objectIDNode;
@Child private ObjectPrimitiveNodes.ObjectIDPrimitiveNode objectIDNode;
@Child private ToHexStringNode toHexStringNode;

public ToSNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
classNode = KernelNodesFactory.ClassNodeFactory.create(context, sourceSection, new RubyNode[]{null});
objectIDNode = ObjectPrimitiveNodesFactory.ObjectIDNodeFactory.create(context, sourceSection, new RubyNode[] { null });
classNode = ClassNodeFactory.create(context, sourceSection, null);
objectIDNode = ObjectPrimitiveNodesFactory.ObjectIDPrimitiveNodeFactory.create(context, sourceSection, new RubyNode[] { null });
toHexStringNode = KernelNodesFactory.ToHexStringNodeFactory.create(context, sourceSection, new RubyNode[]{null});
}

@@ -2202,7 +2180,7 @@ public ToSNode(RubyContext context, SourceSection sourceSection) {
public RubyString toS(VirtualFrame frame, Object self) {
notDesignedForCompilation();

String className = classNode.executeGetClass(frame, self).getName();
String className = classNode.executeGetClass(self).getName();

if (className == null) {
className = "Class";
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@
import com.oracle.truffle.api.dsl.NodeChild;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.source.SourceSection;

import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.core.RubyBasicObject;
@@ -31,6 +32,8 @@ public ClassNode(ClassNode prev) {
super(prev);
}

public abstract RubyClass executeGetClass(Object value);

@Specialization(guards = "isTrue")
protected RubyClass getClassTrue(boolean value) {
return getContext().getCoreLibrary().getTrueClass();
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright (c) 2015 Oracle and/or its affiliates. All rights reserved. This
* code is released under a tri EPL/GPL/LGPL license. You can use it,
* redistribute it and/or modify it under the terms of the:
*
* Eclipse Public License version 1.0
* GNU General Public License version 2
* GNU Lesser General Public License version 2.1
*/
package org.jruby.truffle.nodes.rubinius;

import org.jruby.truffle.runtime.RubyContext;

import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.source.SourceSection;

/**
* Rubinius primitives associated with the Ruby {@code Encoding} class..
*/
public abstract class EncodingPrimitiveNodes {

@RubiniusPrimitive(name = "encoding_get_object_encoding", needsSelf = false)
public static abstract class EncodingGetObjectEncodingPrimitiveNode extends RubiniusPrimitiveNode {

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

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

@Specialization
public Object encodingGetObjectEncoding(Object object) {
throw new UnsupportedOperationException("encoding_get_object_encoding");
}

}

}
Original file line number Diff line number Diff line change
@@ -25,13 +25,13 @@
public abstract class ObjectPrimitiveNodes {

@RubiniusPrimitive(name = "object_id")
public abstract static class ObjectIDNode extends RubiniusPrimitiveNode {
public abstract static class ObjectIDPrimitiveNode extends RubiniusPrimitiveNode {

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

public ObjectIDNode(ObjectIDNode prev) {
public ObjectIDPrimitiveNode(ObjectIDPrimitiveNode prev) {
super(prev);
}

@@ -98,4 +98,22 @@ protected boolean isSmallFixnum(long fixnum) {

}

@RubiniusPrimitive(name = "object_infect", needsSelf = false)
public static abstract class ObjectInfectPrimitiveNode extends RubiniusPrimitiveNode {

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

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

@Specialization
public Object objectInfect(Object object) {
throw new UnsupportedOperationException("object_infect");
}

}

}
Original file line number Diff line number Diff line change
@@ -42,12 +42,12 @@ public RubiniusPrimitiveConstructor getPrimitive(String name) {
public static RubiniusPrimitiveManager create() {
final List<NodeFactory<? extends RubyNode>> nodeFactories = new ArrayList<>();

nodeFactories.addAll(VMPrimitiveNodesFactory.getFactories());
nodeFactories.addAll(ObjectPrimitiveNodesFactory.getFactories());
nodeFactories.addAll(TimePrimitiveNodesFactory.getFactories());
nodeFactories.addAll(TypePrimitiveNodesFactory.getFactories());
nodeFactories.addAll(StringPrimitiveNodesFactory.getFactories());
nodeFactories.addAll(VMPrimitiveNodesFactory.getFactories());
nodeFactories.addAll(FixnumPrimitiveNodesFactory.getFactories());
nodeFactories.addAll(ObjectPrimitiveNodesFactory.getFactories());
nodeFactories.addAll(EncodingPrimitiveNodesFactory.getFactories());

final Map<String, RubiniusPrimitiveConstructor> primitives = new HashMap<>();

This file was deleted.

Original file line number Diff line number Diff line change
@@ -10,14 +10,18 @@
package org.jruby.truffle.nodes.rubinius;

import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.source.SourceSection;
import com.oracle.truffle.api.utilities.ConditionProfile;

import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.core.KernelNodes;
import org.jruby.truffle.nodes.core.KernelNodesFactory;
import org.jruby.truffle.nodes.objects.ClassNode;
import org.jruby.truffle.nodes.objects.ClassNodeFactory;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.core.RubyClass;
import org.jruby.truffle.runtime.core.RubyNilClass;
import org.jruby.truffle.runtime.core.RubyString;
import org.jruby.truffle.runtime.core.RubyThread;
import org.jruby.util.StringSupport;

/**
* Rubinius primitives associated with the VM.
@@ -50,4 +54,164 @@ public RubyNilClass vmGCStart() {

}

@RubiniusPrimitive(name = "vm_get_module_name", needsSelf = false)
public static abstract class VMGetModuleNamePrimitiveNode extends RubiniusPrimitiveNode {

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

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

@Specialization
public Object vmGetModuleName(Object object) {
throw new UnsupportedOperationException("vm_get_module_name");
}

}

@RubiniusPrimitive(name = "vm_object_class", needsSelf = false)
public static abstract class VMObjectClassPrimitiveNode extends RubiniusPrimitiveNode {

@Child private ClassNode classNode;

public VMObjectClassPrimitiveNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
classNode = ClassNodeFactory.create(context, sourceSection, null);
}

public VMObjectClassPrimitiveNode(VMObjectClassPrimitiveNode prev) {
super(prev);
classNode = prev.classNode;
}

@Specialization
public RubyClass vmObjectClass(Object object) {
return classNode.executeGetClass(object);
}

}

@RubiniusPrimitive(name = "vm_object_equal", needsSelf = false)
public static abstract class VMObjectEqualPrimitiveNode extends RubiniusPrimitiveNode {

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

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

@Specialization
public Object vmObjectEqual(Object a, Object b) {
throw new UnsupportedOperationException("vm_object_equal");
}

}

@RubiniusPrimitive(name = "vm_object_kind_of", needsSelf = false)
public static abstract class VMObjectKindOfPrimitiveNode extends RubiniusPrimitiveNode {

@Child private KernelNodes.IsANode isANode;

public VMObjectKindOfPrimitiveNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
isANode = KernelNodesFactory.IsANodeFactory.create(context, sourceSection, new RubyNode[] { null, null });
}

public VMObjectKindOfPrimitiveNode(VMObjectKindOfPrimitiveNode prev) {
super(prev);
isANode = prev.isANode;
}

@Specialization
public boolean vmObjectKindOf(VirtualFrame frame, Object object, RubyClass rubyClass) {
return isANode.executeIsA(frame, object, rubyClass);
}

}

@RubiniusPrimitive(name = "vm_object_respond_to", needsSelf = false)
public static abstract class VMObjectRespondToPrimitiveNode extends RubiniusPrimitiveNode {

@Child private KernelNodes.RespondToNode respondToNode;

public VMObjectRespondToPrimitiveNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
respondToNode = KernelNodesFactory.RespondToNodeFactory.create(context, sourceSection, new RubyNode[] { null, null, null });
}

public VMObjectRespondToPrimitiveNode(VMObjectRespondToPrimitiveNode prev) {
super(prev);
respondToNode = prev.respondToNode;
}

@Specialization
public boolean vmObjectRespondTo(VirtualFrame frame, Object object, Object name, boolean includePrivate) {
return respondToNode.executeDoesRespondTo(frame, object, name, includePrivate);
}

}

@RubiniusPrimitive(name = "vm_object_singleton_class", needsSelf = false)
public static abstract class VMObjectSingletonClassPrimitiveNode extends RubiniusPrimitiveNode {

@Child private KernelNodes.SingletonClassMethodNode singletonClassNode;

public VMObjectSingletonClassPrimitiveNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
singletonClassNode = KernelNodesFactory.SingletonClassMethodNodeFactory.create(context, sourceSection, new RubyNode[] { null });
}

public VMObjectSingletonClassPrimitiveNode(VMObjectSingletonClassPrimitiveNode prev) {
super(prev);
singletonClassNode = prev.singletonClassNode;
}

@Specialization
public Object vmObjectClass(VirtualFrame frame, Object object) {
return singletonClassNode.singletonClass(frame, object);
}

}

@RubiniusPrimitive(name = "vm_set_module_name", needsSelf = false)
public static abstract class VMSetModuleNamePrimitiveNode extends RubiniusPrimitiveNode {

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

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

@Specialization
public Object vmSetModuleName(Object object) {
throw new UnsupportedOperationException("vm_set_module_name");
}

}

@RubiniusPrimitive(name = "vm_singleton_class_object", needsSelf = false)
public static abstract class VMObjectSingletonClassObjectPrimitiveNode extends RubiniusPrimitiveNode {

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

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

@Specialization
public Object vmSingletonClassObject(Object object) {
throw new UnsupportedOperationException("vm_singleton_class_object");
}

}

}