Skip to content

Commit

Permalink
[Truffle] :: looks up constants slightly differently.
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisseaton committed Sep 30, 2014
1 parent 48f53df commit d3df63c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 13 deletions.
20 changes: 14 additions & 6 deletions core/src/main/java/org/jruby/truffle/nodes/ReadConstantNode.java
Expand Up @@ -19,28 +19,36 @@
import org.jruby.truffle.runtime.*;
import org.jruby.truffle.runtime.control.*;
import org.jruby.truffle.runtime.core.RubyBasicObject;
import org.jruby.truffle.runtime.core.RubyModule;

public class ReadConstantNode extends RubyNode {

protected final String name;
@Child protected BoxingNode receiver;

private final boolean isLiteral;
private final String name;
@Child protected RubyNode receiver;
@Child protected DispatchHeadNode dispatch;

public ReadConstantNode(RubyContext context, SourceSection sourceSection, String name, RubyNode receiver) {
public ReadConstantNode(RubyContext context, SourceSection sourceSection, boolean isLiteral, String name, RubyNode receiver) {
super(context, sourceSection);
this.isLiteral = isLiteral;
this.name = name;
this.receiver = new BoxingNode(context, sourceSection, receiver);
this.receiver = receiver;
dispatch = new DispatchHeadNode(context, Dispatch.MissingBehavior.CALL_CONST_MISSING);
}

@Override
public Object execute(VirtualFrame frame) {
final Object receiverObject = receiver.execute(frame);

if (isLiteral && !(receiverObject instanceof RubyModule)) {
throw new RaiseException(getContext().getCoreLibrary().typeErrorIsNotA(receiverObject.toString(), "class/module", this));
}

return dispatch.dispatch(
frame,
NilPlaceholder.INSTANCE,
RubyArguments.getSelf(frame.getArguments()),
receiver.executeRubyBasicObject(frame),
receiverObject,
name,
null,
new Object[]{},
Expand Down
Expand Up @@ -633,7 +633,7 @@ public RubyNode visitClassVarNode(org.jruby.ast.ClassVarNode node) {
public RubyNode visitColon2Node(org.jruby.ast.Colon2Node node) {
final RubyNode lhs = node.getLeftNode().accept(this);

return new ReadConstantNode(context, translate(node.getPosition()), node.getName(), lhs);
return new ReadConstantNode(context, translate(node.getPosition()), true, node.getName(), lhs);
}

@Override
Expand All @@ -642,9 +642,9 @@ public RubyNode visitColon3Node(org.jruby.ast.Colon3Node node) {

final SourceSection sourceSection = translate(node.getPosition());

final ObjectLiteralNode root = new ObjectLiteralNode(context, sourceSection, context.getCoreLibrary().getMainObject());
final ObjectLiteralNode root = new ObjectLiteralNode(context, sourceSection, context.getCoreLibrary().getObjectClass());

return new ReadConstantNode(context, sourceSection, node.getName(), root);
return new ReadConstantNode(context, sourceSection, false, node.getName(), root);
}

@Override
Expand All @@ -660,7 +660,7 @@ public RubyNode visitConstDeclNode(org.jruby.ast.ConstDeclNode node) {
public RubyNode visitConstNode(org.jruby.ast.ConstNode node) {
final SourceSection sourceSection = translate(node.getPosition());

return new ReadConstantNode(context, sourceSection, node.getName(), new SelfNode(context, sourceSection));
return new ReadConstantNode(context, sourceSection, false, node.getName(), new SelfNode(context, sourceSection));
}

@Override
Expand Down
Expand Up @@ -82,7 +82,7 @@ public RubyNode visitConstNode(org.jruby.ast.ConstNode node) {

final SelfNode selfNode = new SelfNode(context, sourceSection);

return new ReadConstantNode(context, sourceSection, node.getName(), selfNode);
return new ReadConstantNode(context, sourceSection, false, node.getName(), selfNode);
}

@Override
Expand Down
3 changes: 1 addition & 2 deletions spec/truffle/tags/language/constants_tags.txt
@@ -1,4 +1,3 @@
fails:Literal (A::X) constant resolution raises a TypeError if a non-class or non-module qualifier is given
fails:Literal (A::X) constant resolution with statically assigned constants does not search the singleton class of the class or module
fails:Literal (A::X) constant resolution with dynamically assigned constants does not search the singleton class of the class or module
fails:Constant resolution within methods sends #const_missing to the original class or module scope
Expand Down Expand Up @@ -29,6 +28,6 @@ fails:Literal (A::X) constant resolution with statically assigned constants sear
fails:Literal (A::X) constant resolution with statically assigned constants searches the superclass chain
fails:Constant resolution within methods with statically assigned constants does not search the lexical scope of qualifying modules
fails:Constant resolution within methods with dynamically assigned constants does not search the lexical scope of qualifying modules
fails:Constant resolution within methods with statically assigned constants searches Object as a lexical scope only if Object is explicitly opened
fails:Module#public_constant marked constants in a module is defined? with A::B form
fails:Module#public_constant marked constants in a class is defined? with A::B form
fails:Literal (A::X) constant resolution with statically assigned constants searches Object if a toplevel qualifier (::X) is given

0 comments on commit d3df63c

Please sign in to comment.