forked from rubinius/rubinius
/
rubinius.rb
198 lines (157 loc) · 4.33 KB
/
rubinius.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
module Rubinius
Terminal = STDIN.tty?
AtExit = []
def self.open_class_under(name, sup, mod)
unless mod.kind_of? Module
raise TypeError, "'#{mod.inspect}' is not a class/module"
end
tbl = mod.constants_table
if !tbl.key?(name)
# Create the class
sup = Object unless sup
obj = Class.new sup, name, mod
else
obj = tbl[name]
if obj.kind_of? Autoload
obj = obj.call
end
if obj.kind_of? Class
if sup and obj.superclass != sup
raise TypeError, "Superclass mismatch: #{obj.superclass} != #{sup}"
end
else
raise TypeError, "#{name} is not a class"
end
end
return obj
end
def self.open_class(name, sup, scope)
if scope
under = scope.module
else
under = Object
end
open_class_under name, sup, under
end
def self.open_module_under(name, mod)
unless mod.kind_of? Module
raise TypeError, "'#{mod.inspect}' is not a class/module"
end
tbl = mod.constants_table
if !tbl.key?(name)
# Create the module
obj = Module.new
obj.set_name_if_necessary name, mod
mod.const_set name, obj
else
obj = tbl[name]
if obj.kind_of? Autoload
obj = obj.call
end
unless obj.kind_of? Module
raise TypeError, "#{name} is not a class"
end
end
return obj
end
def self.open_module(name, scope)
if scope
under = scope.module
else
under = Object
end
open_module_under name, under
end
def self.add_defn_method(name, executable, static_scope, vis)
executable.serial = 1
executable.scope = static_scope if executable.respond_to? :scope=
mod = static_scope.for_method_definition
if mod.kind_of? MetaClass
if mod.attached_instance.kind_of? Numeric
# Such a weird protocol. If :singleton_method_added exists, allow this.
# le sigh.
unless mod.attached_instance.respond_to? :singleton_method_added
raise TypeError, "Unable to define singleton methods on Numerics"
end
end
end
add_method name, executable, mod, vis
end
def self.add_method(name, executable, mod, vis)
vis ||= :public
if vis == :module or name == :initialize or name == :initialize_copy
visibility = :private
else
visibility = vis
end
if entry = mod.method_table.lookup(name)
Rubinius.deoptimize_inliners entry.method if entry.method
end
mod.method_table.store name, executable, visibility
Rubinius::VM.reset_method_cache(name)
mod.module_function name if vis == :module
mod.method_added name if mod.respond_to? :method_added
return executable
end
def self.add_reader(name, mod, vis)
normalized = Type.coerce_to_symbol(name)
add_method normalized, AccessVariable.get_ivar(normalized), mod, vis
end
def self.add_writer(name, mod, vis)
normalized = Type.coerce_to_symbol(name)
writer_name = "#{normalized}=".to_sym
add_method writer_name, AccessVariable.set_ivar(normalized), mod, vis
end
def self.received_signal(sig)
Signal.run_handler(sig)
end
def self.jit(meth)
cm = meth.executable
return unless cm.respond_to? :make_machine_method
if mm = cm.make_machine_method
unless mm.activate
if $DEBUG
puts
puts meth.executable.decode
puts
end
end
elsif $DEBUG
puts "AOT: unable to compile #{meth}"
end
return mm
end
def self.jit_soon(meth)
cm = meth.executable
cm.jit_soon
end
def self.version
extra = ""
if jit = Rubinius::JIT
extra << "J"
if jit.include? :inline_generic
extra << "I"
end
end
str = "rubinius #{VERSION} (#{RUBY_VERSION} #{BUILD_REV[0..7]} #{RUBY_RELEASE_DATE}"
unless extra.empty?
str << " #{extra}"
end
str << ") [#{RUBY_PLATFORM}]"
return str
end
def self.unrecognized_defined(file, line)
message = "#{file}:#{line}: defined? passed an unrecognized expression"
raise Exception, message
end
def self.jump_error(name)
raise LocalJumpError, "invalid context for '#{name}'"
end
# Support for __END__ and DATA
def self.set_data(str)
require 'stringio'
Object.const_set :DATA, StringIO.new(str)
end
end
# A wierd place for it, but it works.
RUBY_DESCRIPTION = Rubinius.version