Skip to content

Commit

Permalink
[Truffle] Add main.define_method from Rubinius.
Browse files Browse the repository at this point in the history
* Import other methods of main whcih can be defined easily in Ruby.
  • Loading branch information
eregon committed Jan 12, 2015
1 parent 6428162 commit bde8eec
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 49 deletions.
43 changes: 0 additions & 43 deletions core/src/main/java/org/jruby/truffle/nodes/core/MainNodes.java
Expand Up @@ -17,35 +17,10 @@
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.core.RubyClass;
import org.jruby.truffle.runtime.core.RubyModule;
import org.jruby.truffle.runtime.core.RubyNilClass;
import org.jruby.truffle.runtime.core.RubyString;

@CoreClass(name = "main")
public abstract class MainNodes {

@CoreMethod(names = "include", argumentsAsArray = true, needsSelf = false, required = 1, visibility = Visibility.PRIVATE)
public abstract static class IncludeNode extends CoreMethodNode {

@Child private ModuleNodes.IncludeNode includeNode;

public IncludeNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
includeNode = ModuleNodesFactory.IncludeNodeFactory.create(context, sourceSection, new RubyNode[]{null, null});
}

public IncludeNode(IncludeNode prev) {
super(prev);
includeNode = prev.includeNode;
}

@Specialization
public RubyNilClass include(VirtualFrame frame, Object[] args) {
notDesignedForCompilation();
final RubyClass object = getContext().getCoreLibrary().getObjectClass();
return includeNode.executeInclude(frame, object, args);
}
}

@CoreMethod(names = "public", argumentsAsArray = true, needsSelf = false, visibility = Visibility.PRIVATE)
public abstract static class PublicNode extends CoreMethodNode {

Expand Down Expand Up @@ -92,22 +67,4 @@ public RubyModule doPrivate(VirtualFrame frame, Object[] args) {
}
}

@CoreMethod(names = {"to_s", "inspect"}, needsSelf = false)
public abstract static class ToSNode extends CoreMethodNode {

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

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

@Specialization
public RubyString toS() {
return getContext().makeString("main");
}

}

}
Expand Up @@ -842,8 +842,6 @@ public IncludeNode(IncludeNode prev) {
appendFeaturesNode = prev.appendFeaturesNode;
}

public abstract RubyNilClass executeInclude(VirtualFrame frame, RubyModule module, Object[] args);

@Specialization
public RubyNilClass include(VirtualFrame frame, RubyModule module, Object[] args) {
notDesignedForCompilation();
Expand Down
1 change: 1 addition & 0 deletions core/src/main/ruby/jruby/truffle/core.rb
Expand Up @@ -56,5 +56,6 @@
require_relative 'core/rubinius/kernel/common/complex'
require_relative 'core/rubinius/kernel/common/fixnum'
require_relative 'core/rubinius/kernel/common/regexp'
require_relative 'core/rubinius/kernel/common/main'

require_relative 'core/shims'
@@ -0,0 +1,48 @@
# Copyright (c) 2007-2014, Evan Phoenix and contributors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
# * Neither the name of Rubinius nor the names of its contributors
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

class << self
def include(*mods)
Rubinius.privately do
Object.include(*mods)
end
end

# Truffle: Do not define #public, #private in Ruby since they need
# to set the top-level frame visibility when called with no argument.

def define_method(*args, &block)
Rubinius.privately do
Object.define_method(*args, &block)
end
end

def to_s
"main"
end

alias_method :inspect, :to_s
end
4 changes: 0 additions & 4 deletions core/src/main/ruby/jruby/truffle/core/shims.rb
Expand Up @@ -66,7 +66,3 @@ def self.last_match(n = nil)
end
end
end

def define_method(name, &block)
Kernel.define_method(name, &block)
end

0 comments on commit bde8eec

Please sign in to comment.