Class: JIT::BoolConstant

Inherits:
Bool show all
Defined in:
lib/libjit/constant.rb

Instance Attribute Summary

Attributes inherited from Value

#jit_t

Instance Method Summary (collapse)

Methods inherited from Bool

#and, #not, #or, #xor

Methods inherited from Primitive

#%, #&, #*, #**, #+, #-, #-@, #/, #<, #<<, #<=, #>, #>=, #>>, #^, #eq, #ne, #|, #~

Methods inherited from Value

#address, #addressable?, #cast, create, #function, #set_addressable, #store, #to_bool, #to_not_bool, #type, wrap

Constructor Details

- (BoolConstant) initialize(function, val, *type)

A new instance of BoolConstant



90
91
92
93
94
95
96
97
98
# File 'lib/libjit/constant.rb', line 90

def initialize(function, val, *type)
  @function = function
  type ||= Type.create(:bool)
  @type = Type.create *type
  
  val = 1 if val == true
  val = 0 if val == false
  @jit_t = LibJIT.jit_value_create_nint_constant(@function.jit_t, @type.jit_t, val)
end

Instance Method Details

- (Boolean) to_b

The boolean represented by this constant.

Returns:

  • (Boolean)

    the boolean represented by this constant.



108
109
110
# File 'lib/libjit/constant.rb', line 108

def to_b
  to_i != 0
end

- (Integer) to_i

Gets the integer represented by this constant as a Ruby object.

Returns:

  • (Integer)

    the integer represented by this constant.



103
104
105
# File 'lib/libjit/constant.rb', line 103

def to_i
  @i ||= LibJIT.jit_value_get_nint_constant jit_t
end