Class: RLTK::CG::GenericValue
- Includes:
- BindingClass
- Defined in:
- lib/rltk/cg/generic_value.rb
Overview
GenericValue objects are used to pass parameters into ExecutionEngines as well as retreive an evaluated function’s result. They may contain values of several different types:
* Integer
* Float
* Boolean
Instance Attribute Summary collapse
-
#type ⇒ Type
readonly
LLVM type of this GenericValue.
Attributes included from BindingClass
Instance Method Summary collapse
-
#dispose ⇒ void
Frees the resources used by LLVM for this value.
-
#initialize(ruby_val, type = nil, signed = true) ⇒ GenericValue
constructor
Creates a new GenericValue from a given Ruby value.
- #to_b ⇒ Boolean
- #to_f(type = RLTK::CG::FloatType) ⇒ Float
- #to_i(signed = true) ⇒ Integer
-
#to_ptr_value ⇒ FFI::Pointer
GenericValue as a pointer.
Methods included from BindingClass
Constructor Details
#initialize(ruby_val, type = nil, signed = true) ⇒ GenericValue
Creates a new GenericValue from a given Ruby value.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/rltk/cg/generic_value.rb', line 38 def initialize(ruby_val, type = nil, signed = true) @ptr, @type = case ruby_val when FFI::Pointer [ruby_val, nil] when ::Integer type = if type then check_cg_type(type, IntType) else NativeIntType.instance end [Bindings.create_generic_value_of_int(type, ruby_val, signed.to_i), type] when ::Float type = if type then check_cg_type(type, RealType) else FloatType.instance end [Bindings.create_generic_value_of_float(type, ruby_val), type] when TrueClass [Bindings.create_generic_value_of_int(Int1Type, 1, 0), Int1Type] when FalseClass [Bindings.create_generic_value_of_int(Int1Type, 0, 0), Int1Type] end end |
Instance Attribute Details
#type ⇒ Type (readonly)
Returns LLVM type of this GenericValue.
31 32 33 |
# File 'lib/rltk/cg/generic_value.rb', line 31 def type @type end |
Instance Method Details
#dispose ⇒ void
This method returns an undefined value.
Frees the resources used by LLVM for this value.
65 66 67 68 69 70 |
# File 'lib/rltk/cg/generic_value.rb', line 65 def dispose if @ptr Bindings.dispose_generic_value(@ptr) @ptr = nil end end |
#to_b ⇒ Boolean
89 90 91 |
# File 'lib/rltk/cg/generic_value.rb', line 89 def to_b self.to_i(false).to_bool end |
#to_f(type = RLTK::CG::FloatType) ⇒ Float
84 85 86 |
# File 'lib/rltk/cg/generic_value.rb', line 84 def to_f(type = RLTK::CG::FloatType) Bindings.generic_value_to_float(@type || check_cg_type(type, RLTK::CG::NumberType), @ptr) end |
#to_i(signed = true) ⇒ Integer
75 76 77 78 79 |
# File 'lib/rltk/cg/generic_value.rb', line 75 def to_i(signed = true) val = Bindings.generic_value_to_int(@ptr, signed.to_i) if signed and val >= 2**63 then val - 2**64 else val end end |
#to_ptr_value ⇒ FFI::Pointer
Returns GenericValue as a pointer.
94 95 96 |
# File 'lib/rltk/cg/generic_value.rb', line 94 def to_ptr_value Bindings.generic_value_to_pointer(@ptr) end |