Skip to content

Commit

Permalink
[Truffle] - Implementing Module#private_constant method
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasallan committed Apr 11, 2014
1 parent 2966b95 commit ba4cf5b
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 1 deletion.
Expand Up @@ -648,7 +648,11 @@ public PrivateConstantNode(PrivateConstantNode prev) {
@Specialization
public RubyModule privateConstant(RubyModule module, Object[] args) {
final Node callNode = (Node) args[args.length - 1];
getContext().getRuntime().getWarnings().warn(IRubyWarnings.ID.TRUFFLE, callNode.getSourceSection().getSource().getName(), callNode.getSourceSection().getStartLine(), "private_constant does nothing at the moment");
for (Object ob : args) {
if (ob instanceof RubySymbol){
module.setConstantPrivate((RubySymbol) ob);
}
}
return module;
}
}
Expand Down
29 changes: 29 additions & 0 deletions core/src/main/java/org/jruby/truffle/runtime/core/RubyModule.java
Expand Up @@ -251,6 +251,35 @@ public Object lookupConstant(String constantName) {
return lookupParent.lookupConstant(constantName);
}

public RubyConstant lookupRubyConstant(String constantName) {
Object value;
value = getConstants().get(constantName);

if (value instanceof RubyConstant) {
return ((RubyConstant) value);
}

if (parentModule != null) {
value = parentModule.lookupRubyConstant(constantName);
}

if (value instanceof RubyConstant) {
return ((RubyConstant) value);
}

return lookupParent.lookupRubyConstant(constantName);
}

public void setConstantPrivate(RubySymbol constant) {
RubyConstant rubyConstant = lookupRubyConstant(constant.toString());

if (rubyConstant != null) {
rubyConstant.isPrivate = true;
} else {
// raises an exception
}
}

@Override
public Object lookupClassVariable(String variableName) {
// Look in this module
Expand Down
Expand Up @@ -53,6 +53,16 @@ public Object lookupConstant(String constantName) {
return second.lookupConstant(constantName);
}

public RubyModule.RubyConstant lookupRubyConstant(String constantName) {
final Object firstResult = first.lookupConstant(constantName);

if (firstResult instanceof RubyModule.RubyConstant) {
return ((RubyModule.RubyConstant) firstResult);
}

return second.lookupRubyConstant(constantName);
}

@Override
public Object lookupClassVariable(String classVariable) {
final Object firstResult = first.lookupClassVariable(classVariable);
Expand Down
Expand Up @@ -12,6 +12,7 @@
import java.util.*;

import com.oracle.truffle.api.*;
import org.jruby.truffle.runtime.core.RubyModule;
import org.jruby.truffle.runtime.methods.*;

/**
Expand All @@ -34,4 +35,6 @@ public interface LookupNode {

void getMethods(Map<String, RubyMethod> methods);

RubyModule.RubyConstant lookupRubyConstant(String constantName);

}
Expand Up @@ -13,6 +13,7 @@

import com.oracle.truffle.api.*;
import com.oracle.truffle.api.utilities.*;
import org.jruby.truffle.runtime.core.RubyModule;
import org.jruby.truffle.runtime.methods.*;

/**
Expand Down Expand Up @@ -52,5 +53,6 @@ public Set<String> getClassVariables() {

public void getMethods(Map<String, RubyMethod> methods) {
}
public RubyModule.RubyConstant lookupRubyConstant(String name) { return null; }

}

0 comments on commit ba4cf5b

Please sign in to comment.