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.



229
230
231
232
# File 'lib/ytljit/vm_type.rb', line 229

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

Instance Attribute Details

#asm_typeObject

Returns the value of attribute asm_type.



234
235
236
# File 'lib/ytljit/vm_type.rb', line 234

def asm_type
  @asm_type
end

#ruby_typeObject



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

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



214
215
216
# File 'lib/ytljit/vm_type.rb', line 214

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

.from_ruby_class(rcls) ⇒ Object



218
219
220
221
222
223
224
225
226
227
# File 'lib/ytljit/vm_type.rb', line 218

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


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
204
205
206
207
208
209
210
211
212
# File 'lib/ytljit/vm_type.rb', line 173

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/, "")
    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

  [baseslf, boxslf, unboxslf]
end

.type_tabObject



169
170
171
# File 'lib/ytljit/vm_type.rb', line 169

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