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: 15b169b57f68
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 3037dce4e818
Choose a head ref
  • 3 commits
  • 3 files changed
  • 1 contributor

Commits on Nov 10, 2014

  1. Copy the full SHA
    ecd9420 View commit details
  2. Copy the full SHA
    0738040 View commit details
  3. Copy the full SHA
    3037dce View commit details
Original file line number Diff line number Diff line change
@@ -53,7 +53,7 @@ public Object execute(VirtualFrame frame) {

final RubyModule module = (RubyModule) receiverObject;

module.setModuleConstant(this, name, rhsValue);
module.setConstant(this, name, rhsValue);

return rhsValue;
}
75 changes: 62 additions & 13 deletions core/src/main/java/org/jruby/truffle/nodes/core/KernelNodes.java
Original file line number Diff line number Diff line change
@@ -400,7 +400,48 @@ public RubyClass getClass(RubyBasicObject self) {

}

@CoreMethod(names = {"dup", "clone"})
@CoreMethod(names = "clone")
public abstract static class CloneNode extends CoreMethodNode {

@Child protected DispatchHeadNode initializeCloneNode;

public CloneNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
// Calls private initialize_clone on the new copy.
initializeCloneNode = new DispatchHeadNode(context, true, Dispatch.MissingBehavior.CALL_METHOD_MISSING);
}

public CloneNode(CloneNode prev) {
super(prev);
initializeCloneNode = prev.initializeCloneNode;
}

@Specialization
public Object clone(VirtualFrame frame, RubyModule self) {
notDesignedForCompilation();

final RubyBasicObject newObject = self.getLogicalClass().newInstance(this);
clone(frame, self, newObject);
return newObject;
}

@Specialization
public Object clone(VirtualFrame frame, RubyBasicObject self) {
notDesignedForCompilation();

final RubyBasicObject newObject = new RubyBasicObject(self.getLogicalClass());
clone(frame, self, newObject);
return newObject;
}

private void clone(VirtualFrame frame, RubyBasicObject self, RubyBasicObject newObject) {
newObject.setInstanceVariables(self.getFields());
initializeCloneNode.call(frame, newObject, "initialize_clone", null, self);
}

}

@CoreMethod(names = "dup")
public abstract static class DupNode extends CoreMethodNode {

@Child protected DispatchHeadNode initializeDupNode;
@@ -421,19 +462,22 @@ public Object dup(VirtualFrame frame, RubyModule self) {
notDesignedForCompilation();

final RubyBasicObject newObject = self.getLogicalClass().newInstance(this);
newObject.setInstanceVariables(self.getFields());
initializeDupNode.call(frame, newObject, "initialize_dup", null, self);
dup(frame, self, newObject);
return newObject;
}

@Specialization
public Object dup(VirtualFrame frame, RubyObject self) {
public Object dup(VirtualFrame frame, RubyBasicObject self) {
notDesignedForCompilation();

final RubyObject newObject = new RubyObject(self.getLogicalClass());
final RubyBasicObject newObject = new RubyObject(self.getLogicalClass());
dup(frame, self, newObject);
return newObject;
}

private void dup(VirtualFrame frame, RubyBasicObject self, RubyBasicObject newObject) {
newObject.setInstanceVariables(self.getFields());
initializeDupNode.call(frame, newObject, "initialize_dup", null, self);
return newObject;
}

}
@@ -786,31 +830,36 @@ public InitializeCopyNode(InitializeCopyNode prev) {
}

@Specialization
public Object initializeCopy(RubyObject self, RubyObject other) {
public Object initializeCopy(RubyBasicObject self, RubyBasicObject other) {
notDesignedForCompilation();

return getContext().getCoreLibrary().getNilObject();
if (self.getLogicalClass() != other.getLogicalClass()) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().typeError("initialize_copy should take same class object", this));
}

return self;
}

}

@CoreMethod(names = "initialize_dup", visibility = Visibility.PRIVATE, required = 1)
public abstract static class InitializeDupNode extends CoreMethodNode {
@CoreMethod(names = {"initialize_dup", "initialize_clone"}, visibility = Visibility.PRIVATE, required = 1)
public abstract static class InitializeDupCloneNode extends CoreMethodNode {

@Child protected DispatchHeadNode initializeCopyNode;

public InitializeDupNode(RubyContext context, SourceSection sourceSection) {
public InitializeDupCloneNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
initializeCopyNode = DispatchHeadNode.onSelf(context);
}

public InitializeDupNode(InitializeDupNode prev) {
public InitializeDupCloneNode(InitializeDupCloneNode prev) {
super(prev);
initializeCopyNode = prev.initializeCopyNode;
}

@Specialization
public Object initializeDup(VirtualFrame frame, RubyObject self, RubyObject other) {
public Object initializeDup(VirtualFrame frame, RubyBasicObject self, RubyBasicObject other) {
notDesignedForCompilation();
return initializeCopyNode.call(frame, self, "initialize_copy", null, other);
}
Original file line number Diff line number Diff line change
@@ -232,14 +232,6 @@ public void removeClassVariable(RubyNode currentNode, String variableName) {
classVariables.remove(variableName);
}

public void setModuleConstant(RubyNode currentNode, String constantName, Object value) {
RubyNode.notDesignedForCompilation();

checkFrozen(currentNode);

setConstant(currentNode, constantName, value);
}

public void addMethod(RubyNode currentNode, RubyMethod method) {
RubyNode.notDesignedForCompilation();