Skip to content

Commit bde8eec

Browse files
committed
[Truffle] Add main.define_method from Rubinius.
* Import other methods of main whcih can be defined easily in Ruby.
1 parent 6428162 commit bde8eec

File tree

5 files changed

+49
-49
lines changed

5 files changed

+49
-49
lines changed

core/src/main/java/org/jruby/truffle/nodes/core/MainNodes.java

-43
Original file line numberDiff line numberDiff line change
@@ -17,35 +17,10 @@
1717
import org.jruby.truffle.runtime.RubyContext;
1818
import org.jruby.truffle.runtime.core.RubyClass;
1919
import org.jruby.truffle.runtime.core.RubyModule;
20-
import org.jruby.truffle.runtime.core.RubyNilClass;
21-
import org.jruby.truffle.runtime.core.RubyString;
2220

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

26-
@CoreMethod(names = "include", argumentsAsArray = true, needsSelf = false, required = 1, visibility = Visibility.PRIVATE)
27-
public abstract static class IncludeNode extends CoreMethodNode {
28-
29-
@Child private ModuleNodes.IncludeNode includeNode;
30-
31-
public IncludeNode(RubyContext context, SourceSection sourceSection) {
32-
super(context, sourceSection);
33-
includeNode = ModuleNodesFactory.IncludeNodeFactory.create(context, sourceSection, new RubyNode[]{null, null});
34-
}
35-
36-
public IncludeNode(IncludeNode prev) {
37-
super(prev);
38-
includeNode = prev.includeNode;
39-
}
40-
41-
@Specialization
42-
public RubyNilClass include(VirtualFrame frame, Object[] args) {
43-
notDesignedForCompilation();
44-
final RubyClass object = getContext().getCoreLibrary().getObjectClass();
45-
return includeNode.executeInclude(frame, object, args);
46-
}
47-
}
48-
4924
@CoreMethod(names = "public", argumentsAsArray = true, needsSelf = false, visibility = Visibility.PRIVATE)
5025
public abstract static class PublicNode extends CoreMethodNode {
5126

@@ -92,22 +67,4 @@ public RubyModule doPrivate(VirtualFrame frame, Object[] args) {
9267
}
9368
}
9469

95-
@CoreMethod(names = {"to_s", "inspect"}, needsSelf = false)
96-
public abstract static class ToSNode extends CoreMethodNode {
97-
98-
public ToSNode(RubyContext context, SourceSection sourceSection) {
99-
super(context, sourceSection);
100-
}
101-
102-
public ToSNode(ToSNode prev) {
103-
super(prev);
104-
}
105-
106-
@Specialization
107-
public RubyString toS() {
108-
return getContext().makeString("main");
109-
}
110-
111-
}
112-
11370
}

core/src/main/java/org/jruby/truffle/nodes/core/ModuleNodes.java

-2
Original file line numberDiff line numberDiff line change
@@ -842,8 +842,6 @@ public IncludeNode(IncludeNode prev) {
842842
appendFeaturesNode = prev.appendFeaturesNode;
843843
}
844844

845-
public abstract RubyNilClass executeInclude(VirtualFrame frame, RubyModule module, Object[] args);
846-
847845
@Specialization
848846
public RubyNilClass include(VirtualFrame frame, RubyModule module, Object[] args) {
849847
notDesignedForCompilation();

core/src/main/ruby/jruby/truffle/core.rb

+1
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,6 @@
5656
require_relative 'core/rubinius/kernel/common/complex'
5757
require_relative 'core/rubinius/kernel/common/fixnum'
5858
require_relative 'core/rubinius/kernel/common/regexp'
59+
require_relative 'core/rubinius/kernel/common/main'
5960

6061
require_relative 'core/shims'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Copyright (c) 2007-2014, Evan Phoenix and contributors
2+
# All rights reserved.
3+
#
4+
# Redistribution and use in source and binary forms, with or without
5+
# modification, are permitted provided that the following conditions are met:
6+
#
7+
# * Redistributions of source code must retain the above copyright notice, this
8+
# list of conditions and the following disclaimer.
9+
# * Redistributions in binary form must reproduce the above copyright notice
10+
# this list of conditions and the following disclaimer in the documentation
11+
# and/or other materials provided with the distribution.
12+
# * Neither the name of Rubinius nor the names of its contributors
13+
# may be used to endorse or promote products derived from this software
14+
# without specific prior written permission.
15+
#
16+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
20+
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21+
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22+
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23+
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24+
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+
27+
class << self
28+
def include(*mods)
29+
Rubinius.privately do
30+
Object.include(*mods)
31+
end
32+
end
33+
34+
# Truffle: Do not define #public, #private in Ruby since they need
35+
# to set the top-level frame visibility when called with no argument.
36+
37+
def define_method(*args, &block)
38+
Rubinius.privately do
39+
Object.define_method(*args, &block)
40+
end
41+
end
42+
43+
def to_s
44+
"main"
45+
end
46+
47+
alias_method :inspect, :to_s
48+
end

core/src/main/ruby/jruby/truffle/core/shims.rb

-4
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,3 @@ def self.last_match(n = nil)
6666
end
6767
end
6868
end
69-
70-
def define_method(name, &block)
71-
Kernel.define_method(name, &block)
72-
end

0 commit comments

Comments
 (0)