Class: CastOff::Compiler::SimpleIR::ConstWrapper

Inherits:
TypeContainer show all
Defined in:
lib/cast_off/compile/ir/operand.rb

Constant Summary

Constants inherited from TypeContainer

TypeContainer::FixnumWrapper, TypeContainer::FloatWrapper

Instance Attribute Summary collapse

Attributes inherited from TypeContainer

#state, #types

Instance Method Summary collapse

Methods inherited from TypeContainer

#box, #boxed?, #boxed_form, #can_unbox?, #declare, #declare_class, #dynamic?, #is_also, #is_also?, #is_annotated, #is_class_exact, #is_dynamic, #is_just?, #is_negative_cond_value, #is_not, #is_static, #not_initialized, #reset, #static?, #to_debug_string, #to_s, #unboxed?, #undefined?, #union

Methods included from Util

#bug, #dlog, #todo, #vlog

Constructor Details

#initialize(flag, *ids, translator) ⇒ ConstWrapper

Returns a new instance of ConstWrapper.


411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
# File 'lib/cast_off/compile/ir/operand.rb', line 411

def initialize(flag, *ids, translator)
  super()
  @chain = ids
  @flag = flag
  @path = "#{@flag ? '::' : nil}#{@chain.join("::")}"
  @translator = translator
  @name = @translator.allocate_name("const_#{@path}")
  @translator.declare_constant(@name)
  conf = @translator.configuration
  @cache_constant_p = @prefetch_constant_p = conf.prefetch_constant? && conf.has_binding?
  if prefetch?
    begin
      val = conf.evaluate_by_passed_binding(@path)
      c = ClassWrapper.new(val, false)
    rescue
      @prefetch_constant_p = false
      c = nil
    end
  else
    c = nil
  end
  if c && @translator.get_c_classname(c)
    is_static([c])
  else
    is_dynamic()
  end
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.


409
410
411
# File 'lib/cast_off/compile/ir/operand.rb', line 409

def path
  @path
end

Instance Method Details

#==(v) ⇒ Object


474
475
476
# File 'lib/cast_off/compile/ir/operand.rb', line 474

def ==(v)
  eql?(v)
end

#cache?Boolean

Returns:

  • (Boolean)

449
450
451
# File 'lib/cast_off/compile/ir/operand.rb', line 449

def cache?
  @cache_constant_p
end

#class_exact?Boolean

Returns:

  • (Boolean)

457
458
459
# File 'lib/cast_off/compile/ir/operand.rb', line 457

def class_exact?
  false
end

#eql?(v) ⇒ Boolean

Returns:

  • (Boolean)

469
470
471
472
# File 'lib/cast_off/compile/ir/operand.rb', line 469

def eql?(v)
  return false unless v.is_a?(ConstWrapper)
  @path == v.path
end

#get_constant_chainObject


439
440
441
442
443
444
445
446
447
# File 'lib/cast_off/compile/ir/operand.rb', line 439

def get_constant_chain
  ret = []
  ret << "  cast_off_tmp = #{@flag ? 'rb_cObject' : 'Qnil'};"
  @chain.each do |id|
    ret << "  cast_off_tmp = cast_off_get_constant(cast_off_tmp, #{@translator.allocate_id(id)});"
  end
  ret << "  #{@name} = cast_off_tmp;"
  ret.join("\n")
end

#hashObject


478
479
480
# File 'lib/cast_off/compile/ir/operand.rb', line 478

def hash
  @path.to_s.hash
end

#prefetch?Boolean

Returns:

  • (Boolean)

453
454
455
# File 'lib/cast_off/compile/ir/operand.rb', line 453

def prefetch?
  @prefetch_constant_p
end

#sourceObject


465
466
467
# File 'lib/cast_off/compile/ir/operand.rb', line 465

def source
  @path
end

#to_nameObject


461
462
463
# File 'lib/cast_off/compile/ir/operand.rb', line 461

def to_name
  @name
end