Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[Truffle] First pass at Module#autoload?.
  • Loading branch information
nirvdrum committed Feb 18, 2015
1 parent 9e10dbb commit 17e56c7
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
5 changes: 0 additions & 5 deletions spec/truffle/tags/core/module/autoload_tags.txt
@@ -1,18 +1,13 @@
fails:Module#autoload? returns the name of the file that will be autoloaded
fails:Module#autoload? returns nil if no file has been registered for a constant
fails:Module#autoload registers a file to load the first time the named constant is accessed
fails:Module#autoload loads the registered constant when it is opened as a class
fails:Module#autoload loads the registered constant when it is opened as a module
fails:Module#autoload does not load the file if the file is manually required
fails:Module#autoload ignores the autoload request if the file is already loaded
fails:Module#autoload retains the autoload even if the request to require fails
fails:Module#autoload does not remove the constant from the constant table if load fails
fails:Module#autoload does not remove the constant from the constant table if the loaded files does not define it
fails:Module#autoload loads the file when opening a module that is the autoloaded constant
fails:Module#autoload looks up the constant when in a meta class scope
fails:Module#autoload does NOT raise a NameError when the autoload file did not define the constant and a module is opened with the same name
fails:Module#autoload calls #to_path on non-string filenames
fails:Module#autoload shares the autoload request across dup'ed copies of modules
fails:Module#autoload calls #to_path on non-String filename arguments
fails:Module#autoload (concurrently) blocks a second thread while a first is doing the autoload
fails:Module#autoload (concurrently) blocks others threads while doing an autoload
Expand Up @@ -441,6 +441,38 @@ private RubyNilClass autoload(RubyModule module, String name, RubyString filenam
}
}

@CoreMethod(names = "autoload?", required = 1)
public abstract static class AutoloadQueryNode extends CoreMethodNode {

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

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

@Specialization
public Object autoloadQuery(RubyModule module, RubySymbol name) {
return autoloadQuery(module, name.toString());
}

@Specialization
public Object autoloadQuery(RubyModule module, RubyString name) {
return autoloadQuery(module, name.toString());
}

private Object autoloadQuery(RubyModule module, String name) {
final RubyConstant constant = ModuleOperations.lookupConstant(getContext(), LexicalScope.NONE, module, name);

if ((constant == null) || ! constant.isAutoload()) {
return getContext().getCoreLibrary().getNilObject();
}

return constant.getValue();
}
}

@CoreMethod(names = {"class_eval","module_eval"}, optional = 3, needsBlock = true)
public abstract static class ClassEvalNode extends CoreMethodNode {

Expand Down

0 comments on commit 17e56c7

Please sign in to comment.