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: 281df5c6939f
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 2e4e39af0db3
Choose a head ref
  • 2 commits
  • 5 files changed
  • 1 contributor

Commits on Oct 8, 2015

  1. Copy the full SHA
    9febd8c View commit details
  2. Copy the full SHA
    2e4e39a View commit details
5 changes: 5 additions & 0 deletions spec/ruby/language/alias_spec.rb
Original file line number Diff line number Diff line change
@@ -157,4 +157,9 @@ def test_with_check(*args)
end
end.should raise_error(TypeError)
end

it "on top level defines the alias on Object" do
# because it defines on the default definee / current module
ruby_exe("def foo; end; alias bla foo; print method(:bla).owner", escape: true).should == "Object"
end
end
Original file line number Diff line number Diff line change
@@ -9,43 +9,37 @@
*/
package org.jruby.truffle.nodes.methods;

import com.oracle.truffle.api.dsl.NodeChild;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.nodes.RubyGuards;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.objects.SingletonClassNode;
import org.jruby.truffle.nodes.objects.SingletonClassNodeGen;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.layouts.Layouts;

@NodeChild(value="module", type=RubyNode.class)
public abstract class AliasNode extends RubyNode {
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.object.DynamicObject;
import com.oracle.truffle.api.source.SourceSection;

public class AliasNode extends RubyNode {

@Child private SingletonClassNode singletonClassNode;
@Child private RubyNode defaultDefinee;

final String newName;
final String oldName;

public AliasNode(RubyContext context, SourceSection sourceSection, String newName, String oldName) {
public AliasNode(RubyContext context, SourceSection sourceSection, RubyNode defaultDefinee, String newName, String oldName) {
super(context, sourceSection);
this.singletonClassNode = SingletonClassNodeGen.create(context, sourceSection, null);
this.defaultDefinee = defaultDefinee;
this.newName = newName;
this.oldName = oldName;
}

@Specialization(guards = "isRubyModule(module)")
public Object alias(DynamicObject module) {
@Override
public Object execute(VirtualFrame frame) {
final Object moduleObject = defaultDefinee.execute(frame);
assert RubyGuards.isRubyModule(moduleObject);
final DynamicObject module = (DynamicObject) moduleObject;

Layouts.MODULE.getFields(module).alias(getContext(), this, newName, oldName);
return module;
}

// TODO (eregon, 10 May 2015): we should only have the module case as the child should be the default definee
@Specialization(guards = "!isRubyModule(object)")
public Object alias(Object object) {
Layouts.MODULE.getFields(singletonClassNode.executeSingletonClass(object)).alias(getContext(), this, newName, oldName);
return object;
}

}
Original file line number Diff line number Diff line change
@@ -24,9 +24,9 @@ public class GetDefaultDefineeNode extends RubyNode {

@Child private SingletonClassNode singletonClassNode;

public GetDefaultDefineeNode(RubyContext context, SourceSection section) {
super(context, section);
this.singletonClassNode = SingletonClassNodeGen.create(context, section, null);
public GetDefaultDefineeNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
this.singletonClassNode = SingletonClassNodeGen.create(context, sourceSection, null);
}

@Override
Original file line number Diff line number Diff line change
@@ -63,6 +63,7 @@
import org.jruby.truffle.nodes.literal.StringLiteralNode;
import org.jruby.truffle.nodes.locals.*;
import org.jruby.truffle.nodes.methods.*;
import org.jruby.truffle.nodes.methods.AliasNode;
import org.jruby.truffle.nodes.methods.UndefNode;
import org.jruby.truffle.nodes.objects.*;
import org.jruby.truffle.nodes.objects.SelfNode;
@@ -133,7 +134,7 @@ public RubyNode visitAliasNode(org.jruby.ast.AliasNode node) {
final org.jruby.ast.LiteralNode oldName = (org.jruby.ast.LiteralNode) node.getOldName();
final org.jruby.ast.LiteralNode newName = (org.jruby.ast.LiteralNode) node.getNewName();

final RubyNode ret = AliasNodeGen.create(context, sourceSection, newName.getName(), oldName.getName(), new SelfNode(context, sourceSection));
final RubyNode ret = new AliasNode(context, sourceSection, new GetDefaultDefineeNode(context, sourceSection), newName.getName(), oldName.getName());
return addNewlineIfNeeded(node, ret);
}

Original file line number Diff line number Diff line change
@@ -17,7 +17,6 @@
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.RubyRootNode;
import org.jruby.truffle.nodes.control.SequenceNode;
import org.jruby.truffle.nodes.methods.AliasNodeGen;
import org.jruby.truffle.nodes.methods.CatchReturnPlaceholderNode;
import org.jruby.truffle.nodes.methods.GetDefaultDefineeNode;
import org.jruby.truffle.nodes.methods.MethodDefinitionNode;
@@ -97,14 +96,4 @@ public RubyNode visitDefnNode(org.jruby.ast.DefnNode node) {
return translateMethodDefinition(sourceSection, classNode, methodName, node.getArgsNode(), node.getBodyNode(), false);
}

@Override
public RubyNode visitAliasNode(org.jruby.ast.AliasNode node) {
final SourceSection sourceSection = translate(node.getPosition());

final org.jruby.ast.LiteralNode oldName = (org.jruby.ast.LiteralNode) node.getOldName();
final org.jruby.ast.LiteralNode newName = (org.jruby.ast.LiteralNode) node.getNewName();

return AliasNodeGen.create(context, sourceSection, newName.getName(), oldName.getName(), new SelfNode(context, sourceSection));
}

}