Class: YTLJit::RubyType::BaseType

Inherits:
Object
  • Object
show all
Defined in:
lib/ytljit/vm_type.rb

Direct Known Subclasses

DefaultType0, RubyTypeBoxed, RubyTypeUnboxed

Constant Summary collapse

@@base_type_tab =
{}
@@boxed_type_tab =
{}
@@unboxed_type_tab =
{}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rtype) ⇒ BaseType

Returns a new instance of BaseType.



247
248
249
250
# File 'lib/ytljit/vm_type.rb', line 247

def initialize(rtype)
  @asm_type = AsmType::MACHINE_WORD
  @ruby_type = rtype
end

Instance Attribute Details

#asm_typeObject

Returns the value of attribute asm_type.



252
253
254
# File 'lib/ytljit/vm_type.rb', line 252

def asm_type
  @asm_type
end

#ruby_typeObject



254
255
256
257
258
259
260
# File 'lib/ytljit/vm_type.rb', line 254

def ruby_type
  if @ruby_type.is_a?(ClassClassWrapper) then
    @ruby_type.value
  else
    @ruby_type
  end
end

Class Method Details

.from_object(obj) ⇒ Object



232
233
234
# File 'lib/ytljit/vm_type.rb', line 232

def self.from_object(obj)
  from_ruby_class(obj.class)
end

.from_ruby_class(rcls) ⇒ Object



236
237
238
239
240
241
242
243
244
245
# File 'lib/ytljit/vm_type.rb', line 236

def self.from_ruby_class(rcls)
  tobj =  @@base_type_tab[rcls]
  if tobj == nil then
    RubyType::define_wraped_class(rcls, RubyTypeBoxed)
    tobj =  @@base_type_tab[rcls]
    tobj.instance
  else
    tobj.instance
  end
end


190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
# File 'lib/ytljit/vm_type.rb', line 190

def self.related_ruby_class(klass, base)
  if @@base_type_tab[klass] then
    return [@@base_type_tab[klass], 
            @@boxed_type_tab[klass], 
            @@unboxed_type_tab[klass]]
  end
  baseslf = base.new(klass)
  boxslf = RubyTypeBoxed.new(klass)
  unboxslf = RubyTypeUnboxed.new(klass)

  klass.ancestors.reverse.each do |curcls|
    box_unbox = base.name.gsub(/.*::Ruby/, "")
    curclsn = curcls.name.gsub(/:/, '')
    mixinname = curclsn + box_unbox + "CodeGen"
    begin
      mixin = VM::TypeCodeGen.const_get(mixinname)
      baseslf.extend mixin
    rescue NameError
    end

    mixinname = curclsn + "TypeBoxedCodeGen"
    begin
      mixin = VM::TypeCodeGen.const_get(mixinname)
      boxslf.extend mixin
    rescue NameError
    end

    mixinname = curclsn + "TypeUnboxedCodeGen"
    begin
      mixin = VM::TypeCodeGen.const_get(mixinname)
      unboxslf.extend mixin
    rescue NameError
    end
  end

  @@base_type_tab[klass] = baseslf
  @@boxed_type_tab[klass] = boxslf
  @@unboxed_type_tab[klass] = unboxslf

  [baseslf, boxslf, unboxslf]
end

.type_tabObject



186
187
188
# File 'lib/ytljit/vm_type.rb', line 186

def self.type_tab
  [@@base_type_tab, @@boxed_type_tab, @@unboxed_type_tab]
end

Instance Method Details

#abnormal?Boolean

Returns:

  • (Boolean)


266
267
268
# File 'lib/ytljit/vm_type.rb', line 266

def abnormal?
  @@base_type_tab[ruby_type].boxed != boxed
end

#ruby_type_rawObject



262
263
264
# File 'lib/ytljit/vm_type.rb', line 262

def ruby_type_raw
  @ruby_type
end