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.



218
219
220
221
# File 'lib/ytljit/vm_type.rb', line 218

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

Instance Attribute Details

#asm_typeObject

Returns the value of attribute asm_type.



223
224
225
# File 'lib/ytljit/vm_type.rb', line 223

def asm_type
  @asm_type
end

#ruby_typeObject

Returns the value of attribute ruby_type.



224
225
226
# File 'lib/ytljit/vm_type.rb', line 224

def ruby_type
  @ruby_type
end

Class Method Details

.from_object(obj) ⇒ Object



205
206
207
# File 'lib/ytljit/vm_type.rb', line 205

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

.from_ruby_class(rcls) ⇒ Object



209
210
211
212
213
214
215
216
# File 'lib/ytljit/vm_type.rb', line 209

def self.from_ruby_class(rcls)
  tobj =  @@base_type_tab[rcls]
  if tobj == nil then
    DefaultType0.new
  else
    tobj.instance
  end
end


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
199
200
201
202
203
# File 'lib/ytljit/vm_type.rb', line 169

def self.related_ruby_class(klass, base)
  baseslf = base.new(klass)
  boxslf = RubyTypeBoxed.new(klass)
  unboxslf = RubyTypeUnboxed.new(klass)

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

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

    mixinname = curcls.name + "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

  [boxslf, unboxslf]
end

.type_tabObject



165
166
167
# File 'lib/ytljit/vm_type.rb', line 165

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