Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into non-indy-jit
Browse files Browse the repository at this point in the history
  • Loading branch information
headius committed Oct 10, 2014
2 parents 0bf25c8 + 3765605 commit ec13ebf
Show file tree
Hide file tree
Showing 20 changed files with 122 additions and 130 deletions.
Expand Up @@ -22,7 +22,7 @@

Visibility visibility() default Visibility.PUBLIC;

boolean isModuleMethod() default false;
boolean isModuleFunction() default false;

boolean needsSelf() default true;

Expand Down
Expand Up @@ -143,12 +143,19 @@ private static void addMethod(RubyClass rubyObjectClass, MethodDetails methodDet

final Visibility visibility = anno.visibility();

final RubyRootNode rootNode = makeGenericMethod(context, methodDetails);
if (anno.isModuleFunction() && visibility != Visibility.PUBLIC) {
System.err.println("WARNING: visibility ignored when isModuleFunction in " + methodDetails.getIndicativeName());
}

// Do not use needsSelf=true in module functions, it is either the module/class or the instance.
final boolean needsSelf = !anno.isModuleFunction() && anno.needsSelf();

final RubyRootNode rootNode = makeGenericMethod(context, methodDetails, needsSelf);

final RubyMethod method = new RubyMethod(rootNode.getSharedMethodInfo(), canonicalName, module, visibility, false,
Truffle.getRuntime().createCallTarget(rootNode), null);

if (anno.isModuleMethod()) {
if (anno.isModuleFunction()) {
module.addMethod(null, method.withNewVisibility(Visibility.PRIVATE));
module.getSingletonClass(null).addMethod(null, method.withNewVisibility(Visibility.PUBLIC));
} else {
Expand All @@ -160,13 +167,13 @@ private static void addMethod(RubyClass rubyObjectClass, MethodDetails methodDet

module.addMethod(null, withAlias);

if (anno.isModuleMethod()) {
if (anno.isModuleFunction()) {
module.getSingletonClass(null).addMethod(null, withAlias.withNewVisibility(Visibility.PUBLIC));
}
}
}

private static RubyRootNode makeGenericMethod(RubyContext context, MethodDetails methodDetails) {
private static RubyRootNode makeGenericMethod(RubyContext context, MethodDetails methodDetails, boolean needsSelf) {
final CoreSourceSection sourceSection = new CoreSourceSection(methodDetails.getClassAnnotation().name(), methodDetails.getMethodAnnotation().names()[0]);

final SharedMethodInfo sharedMethodInfo = new SharedMethodInfo(sourceSection, methodDetails.getIndicativeName(), false, null);
Expand All @@ -175,7 +182,7 @@ private static RubyRootNode makeGenericMethod(RubyContext context, MethodDetails

final List<RubyNode> argumentsNodes = new ArrayList<>();

if (methodDetails.getMethodAnnotation().needsSelf()) {
if (needsSelf) {
RubyNode readSelfNode = new SelfNode(context, sourceSection);

if (methodDetails.getMethodAnnotation().lowerFixnumSelf()) {
Expand Down
9 changes: 4 additions & 5 deletions core/src/main/java/org/jruby/truffle/nodes/core/DirNodes.java
Expand Up @@ -14,7 +14,6 @@
import java.nio.file.attribute.*;

import com.oracle.truffle.api.CompilerDirectives.SlowPath;
import com.oracle.truffle.api.*;
import com.oracle.truffle.api.source.*;
import com.oracle.truffle.api.dsl.*;
import com.oracle.truffle.api.frame.*;
Expand All @@ -25,7 +24,7 @@
@CoreClass(name = "Dir")
public abstract class DirNodes {

@CoreMethod(names = "[]", isModuleMethod = true, needsSelf = false, minArgs = 1, maxArgs = 1)
@CoreMethod(names = "[]", isModuleFunction = true, minArgs = 1, maxArgs = 1)
public abstract static class GlobNode extends CoreMethodNode {

public GlobNode(RubyContext context, SourceSection sourceSection) {
Expand Down Expand Up @@ -97,7 +96,7 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO

}

@CoreMethod(names = "chdir", isModuleMethod = true, needsSelf = false, needsBlock = true, minArgs = 1, maxArgs = 1)
@CoreMethod(names = "chdir", isModuleFunction = true, needsBlock = true, minArgs = 1, maxArgs = 1)
public abstract static class ChdirNode extends YieldingCoreMethodNode {

public ChdirNode(RubyContext context, SourceSection sourceSection) {
Expand Down Expand Up @@ -130,7 +129,7 @@ public Object chdir(VirtualFrame frame, RubyString path, RubyProc block) {

}

@CoreMethod(names = {"exist?", "exists?"}, isModuleMethod = true, needsSelf = false, maxArgs = 1)
@CoreMethod(names = {"exist?", "exists?"}, isModuleFunction = true, maxArgs = 1)
public abstract static class ExistsNode extends CoreMethodNode {

public ExistsNode(RubyContext context, SourceSection sourceSection) {
Expand All @@ -150,7 +149,7 @@ public boolean exists(RubyString path) {

}

@CoreMethod(names = "pwd", isModuleMethod = true, needsSelf = false, maxArgs = 0)
@CoreMethod(names = "pwd", isModuleFunction = true, maxArgs = 0)
public abstract static class PwdNode extends CoreMethodNode {

public PwdNode(RubyContext context, SourceSection sourceSection) {
Expand Down
Expand Up @@ -39,7 +39,7 @@ public boolean equal(RubyEncoding a, RubyEncoding b) {

}

@CoreMethod(names = "default_external", isModuleMethod = true, needsSelf = false, maxArgs = 0)
@CoreMethod(names = "default_external", isModuleFunction = true, maxArgs = 0)
public abstract static class DefaultExternalNode extends CoreMethodNode {

public DefaultExternalNode(RubyContext context, SourceSection sourceSection) {
Expand All @@ -65,7 +65,7 @@ public RubyEncoding defaultExternal() {

}

@CoreMethod(names = "default_internal", isModuleMethod = true, needsSelf = false, maxArgs = 0)
@CoreMethod(names = "default_internal", isModuleFunction = true, maxArgs = 0)
public abstract static class DefaultInternalNode extends CoreMethodNode {

public DefaultInternalNode(RubyContext context, SourceSection sourceSection) {
Expand All @@ -91,7 +91,7 @@ public RubyEncoding defaultInternal() {

}

@CoreMethod(names = "find", isModuleMethod = true, needsSelf = false, maxArgs = 1, minArgs = 1)
@CoreMethod(names = "find", isModuleFunction = true, maxArgs = 1, minArgs = 1)
public abstract static class FindNode extends CoreMethodNode {

public FindNode(RubyContext context, SourceSection sourceSection) {
Expand Down
Expand Up @@ -9,7 +9,6 @@
*/
package org.jruby.truffle.nodes.core;

import com.oracle.truffle.api.*;
import com.oracle.truffle.api.source.*;
import com.oracle.truffle.api.dsl.*;
import org.jruby.truffle.runtime.*;
Expand Down Expand Up @@ -63,7 +62,7 @@ public NilPlaceholder initialize(RubyFiber fiber, RubyProc block) {

}

@CoreMethod(names = "yield", isModuleMethod = true, needsSelf = false, isSplatted = true)
@CoreMethod(names = "yield", isModuleFunction = true, isSplatted = true)
public abstract static class YieldNode extends CoreMethodNode {

public YieldNode(RubyContext context, SourceSection sourceSection) {
Expand Down
24 changes: 11 additions & 13 deletions core/src/main/java/org/jruby/truffle/nodes/core/FileNodes.java
Expand Up @@ -11,7 +11,6 @@

import java.io.*;

import com.oracle.truffle.api.*;
import com.oracle.truffle.api.source.*;
import com.oracle.truffle.api.dsl.*;
import com.oracle.truffle.api.frame.*;
Expand All @@ -22,8 +21,7 @@

@CoreClass(name = "File")
public abstract class FileNodes {

@CoreMethod(names = "absolute_path", isModuleMethod = true, needsSelf = false, minArgs = 1, maxArgs = 1)
@CoreMethod(names = "absolute_path", isModuleFunction = true, minArgs = 1, maxArgs = 1)
public abstract static class AbsolutePathNode extends CoreMethodNode {

public AbsolutePathNode(RubyContext context, SourceSection sourceSection) {
Expand Down Expand Up @@ -64,7 +62,7 @@ public NilPlaceholder close(RubyFile file) {

}

@CoreMethod(names = "delete", needsSelf = false, isModuleMethod = true, minArgs = 1, maxArgs = 1)
@CoreMethod(names = "delete", isModuleFunction = true, minArgs = 1, maxArgs = 1)
public abstract static class DeleteNode extends CoreMethodNode {

public DeleteNode(RubyContext context, SourceSection sourceSection) {
Expand All @@ -86,7 +84,7 @@ public int delete(RubyString file) {

}

@CoreMethod(names = "directory?", isModuleMethod = true, needsSelf = false, maxArgs = 1)
@CoreMethod(names = "directory?", isModuleFunction = true, maxArgs = 1)
public abstract static class DirectoryNode extends CoreMethodNode {

public DirectoryNode(RubyContext context, SourceSection sourceSection) {
Expand All @@ -106,7 +104,7 @@ public boolean directory(RubyString path) {

}

@CoreMethod(names = "dirname", isModuleMethod = true, needsSelf = false, minArgs = 1, maxArgs = 1)
@CoreMethod(names = "dirname", isModuleFunction = true, minArgs = 1, maxArgs = 1)
public abstract static class DirnameNode extends CoreMethodNode {

public DirnameNode(RubyContext context, SourceSection sourceSection) {
Expand Down Expand Up @@ -174,7 +172,7 @@ public NilPlaceholder eachLine(VirtualFrame frame, RubyFile file, RubyProc block

}

@CoreMethod(names = {"exist?", "exists?"}, isModuleMethod = true, needsSelf = false, minArgs = 1, maxArgs = 1)
@CoreMethod(names = {"exist?", "exists?"}, isModuleFunction = true, minArgs = 1, maxArgs = 1)
public abstract static class ExistsNode extends CoreMethodNode {

public ExistsNode(RubyContext context, SourceSection sourceSection) {
Expand All @@ -194,7 +192,7 @@ public boolean exists(RubyString path) {

}

@CoreMethod(names = "executable?", isModuleMethod = true, needsSelf = false, minArgs = 1, maxArgs = 1)
@CoreMethod(names = "executable?", isModuleFunction = true, minArgs = 1, maxArgs = 1)
public abstract static class ExecutableNode extends CoreMethodNode {

public ExecutableNode(RubyContext context, SourceSection sourceSection) {
Expand All @@ -214,7 +212,7 @@ public boolean executable(RubyString path) {

}

@CoreMethod(names = "expand_path", isModuleMethod = true, needsSelf = false, minArgs = 1, maxArgs = 2)
@CoreMethod(names = "expand_path", isModuleFunction = true, minArgs = 1, maxArgs = 2)
public abstract static class ExpandPathNode extends CoreMethodNode {

public ExpandPathNode(RubyContext context, SourceSection sourceSection) {
Expand All @@ -239,7 +237,7 @@ public RubyString expandPath(RubyString path, RubyString dir) {

}

@CoreMethod(names = "file?", isModuleMethod = true, needsSelf = false, minArgs = 1, maxArgs = 1)
@CoreMethod(names = "file?", isModuleFunction = true, minArgs = 1, maxArgs = 1)
public abstract static class FileNode extends CoreMethodNode {

public FileNode(RubyContext context, SourceSection sourceSection) {
Expand All @@ -259,7 +257,7 @@ public boolean file(RubyString path) {

}

@CoreMethod(names = "join", isModuleMethod = true, needsSelf = false, isSplatted = true)
@CoreMethod(names = "join", isModuleFunction = true, isSplatted = true)
public abstract static class JoinNode extends CoreMethodNode {

public JoinNode(RubyContext context, SourceSection sourceSection) {
Expand Down Expand Up @@ -297,7 +295,7 @@ public static void join(StringBuilder builder, Object[] parts) {
}
}

@CoreMethod(names = "open", isModuleMethod = true, needsSelf = false, needsBlock = true, minArgs = 2, maxArgs = 2)
@CoreMethod(names = "open", isModuleFunction = true, needsBlock = true, minArgs = 2, maxArgs = 2)
public abstract static class OpenNode extends YieldingCoreMethodNode {

public OpenNode(RubyContext context, SourceSection sourceSection) {
Expand Down Expand Up @@ -394,7 +392,7 @@ public RubyString read(RubyFile file) {

}

@CoreMethod(names = "size?", minArgs = 1, maxArgs = 1, needsSelf = false, isModuleMethod = true)
@CoreMethod(names = "size?", minArgs = 1, maxArgs = 1, isModuleFunction = true)
public abstract static class SizeNode extends CoreMethodNode {

public SizeNode(RubyContext context, SourceSection sourceSection) {
Expand Down
Expand Up @@ -90,7 +90,7 @@ public boolean equal(RubyHash a, RubySymbol b) {

}

@CoreMethod(names = "[]", isModuleMethod = true, needsSelf = false, isSplatted = true)
@CoreMethod(names = "[]", isModuleFunction = true, isSplatted = true)
public abstract static class ConstructNode extends HashCoreMethodNode {

private final BranchProfile singleObject = new BranchProfile();
Expand Down
8 changes: 1 addition & 7 deletions core/src/main/java/org/jruby/truffle/nodes/core/IONodes.java
Expand Up @@ -9,15 +9,9 @@
*/
package org.jruby.truffle.nodes.core;

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.Truffle;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.nodes.NodeUtil;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.runtime.NilPlaceholder;
import org.jruby.truffle.runtime.RubyCallStack;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.backtrace.Backtrace;
import org.jruby.truffle.runtime.core.RubyArray;
import org.jruby.truffle.runtime.core.RubyString;

Expand All @@ -28,7 +22,7 @@
@CoreClass(name = "IO")
public abstract class IONodes {

@CoreMethod(names = "readlines", isModuleMethod = true, needsSelf = false, minArgs = 1, maxArgs = 1)
@CoreMethod(names = "readlines", isModuleFunction = true, minArgs = 1, maxArgs = 1)
public abstract static class ReadLinesNode extends CoreMethodNode {

public ReadLinesNode(RubyContext context, SourceSection sourceSection) {
Expand Down

0 comments on commit ec13ebf

Please sign in to comment.