Class: CastOff::Compiler::SimpleIR::Literal

Inherits:
TypeContainer show all
Includes:
Util
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 included from Util

#bug, #dlog, #todo, #vlog

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, #unboxed?, #undefined?, #union

Constructor Details

#initialize(val, translator) ⇒ Literal

Returns a new instance of Literal.



488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
# File 'lib/cast_off/compile/ir/operand.rb', line 488

def initialize(val, translator)
  super()
  case val
  when NilClass
    @val = "Qnil"
    type = NilClass
    @literal_value = nil
  when Fixnum, Symbol, Bignum, Float, String, Regexp, Array, Range, TrueClass, FalseClass, Class
    @val = translator.allocate_object(val)
    type = val.class
    @literal_value = val
  else
    bug("unexpected object #{val}")
  end
  is_static([type])
end

Instance Attribute Details

#literal_valueObject (readonly)

Returns the value of attribute literal_value.



486
487
488
# File 'lib/cast_off/compile/ir/operand.rb', line 486

def literal_value
  @literal_value
end

#valObject (readonly)

Returns the value of attribute val.



486
487
488
# File 'lib/cast_off/compile/ir/operand.rb', line 486

def val
  @val
end

Instance Method Details

#==(v) ⇒ Object



532
533
534
# File 'lib/cast_off/compile/ir/operand.rb', line 532

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

#class_exact?Boolean

Returns:

  • (Boolean)


515
516
517
# File 'lib/cast_off/compile/ir/operand.rb', line 515

def class_exact?
  true
end

#eql?(v) ⇒ Boolean

Returns:

  • (Boolean)


527
528
529
530
# File 'lib/cast_off/compile/ir/operand.rb', line 527

def eql?(v)
  return false unless v.is_a?(Literal)
  @literal_value == v.literal_value
end

#hashObject



536
537
538
# File 'lib/cast_off/compile/ir/operand.rb', line 536

def hash()
  @literal_value.hash()
end

#sourceObject



523
524
525
# File 'lib/cast_off/compile/ir/operand.rb', line 523

def source
  @literal_value.inspect
end

#to_nameObject



519
520
521
# File 'lib/cast_off/compile/ir/operand.rb', line 519

def to_name
  @val
end

#to_sObject



505
506
507
508
509
510
511
512
513
# File 'lib/cast_off/compile/ir/operand.rb', line 505

def to_s()
  case declare_class()
  when :double, :long
    return "#{@literal_value}"
  when :VALUE
    return to_name()
  end
  bug()
end