class Object

Public Instance Methods

check_cg_array_type(array, type = RLTK::CG::Type, blame = 'el_types', strict = false) click to toggle source

This helper function checks to make sure that an array of objects are all sub-classses of {RLTK::CG::Type Type} or instances of a sub-class of Type. If a class is present in the array parameter it is expected to be a singleton class and will be instantiated via the instance method.

@param [Array<Type, Class>] array Array of objects to type check for code generation type. @param [Type] type Class the objects should be an instance (or sub-class) of. @param [String] blame Variable name to blame for failed type checks. @param [Boolean] strict Strict or non-strict checking. Uses ‘instance_of?` and `is_a?` respectively.

@raise [ArgumentError] An error is raise if a class is passed in array that

hasn't included the Singleton class, if the class passed in parameter
*type* isn't a sub-class of {RLTK::CG::Type Type}, or if the type check
fails.

@return [Array<Type>] An array containing the objects in array with any singleton classes replaced by their instances.

# File lib/rltk/cg/type.rb, line 529
def check_cg_array_type(array, type = RLTK::CG::Type, blame = 'el_types', strict = false)
        array.map do |o|
                if o.is_a?(Class)
                        type_ok = if strict then o == type else o.subclass_of?(type) end

                        if type_ok
                                if o.includes_module?(Singleton)
                                        o.instance
                                else
                                        raise ArgumentError, "The #{o.name} class (passed in parameter #{blame}) must be instantiated directly."
                                end
                        else
                                raise ArgumentError, "The #{o.name} class (passed in parameter #{blame}) does not inherit from the #{type.name} class."
                        end

                else
                        type_ok = if strict then o.instance_of(type) else o.is_a?(type) end

                        if type_ok
                                o
                        else
                                raise ArgumentError, "Parameter #{blame} must contain instances of the #{type.name} class."
                        end
                end
        end
end
check_cg_type(o, type = RLTK::CG::Type, blame = 'type', strict = false) click to toggle source

This helper function checks to make sure that an object is a sub-class of {RLTK::CG::Type Type} or an instance of a sub-class of Type. If a class is passed in the o parameter it is expected to be a singleton class and will be instantiated via the instance method.

@param [Type, Class] o Object to type check for code generation type. @param [Type] type Class the object should be an instance (or sub-class) of. @param [String] blame Variable name to blame for failed type checks. @param [Boolean] strict Strict or non-strict checking. Uses ‘instance_of?` and `is_a?` respectively.

@raise [ArgumentError] An error is raise if a class is passed in parameter o

that hasn't included the Singleton class, if the class passed in parameter
*type* isn't a sub-class of {RLTK::CG::Type Type}, or if the type check
fails.

@return [Type] The object o or an instance of the class passed in parameter o.

# File lib/rltk/cg/type.rb, line 495
def check_cg_type(o, type = RLTK::CG::Type, blame = 'type', strict = false)
        if o.is_a?(Class)
                type_ok = if strict then o == type else o.subclass_of?(type) end

                if type_ok
                        if o.includes_module?(Singleton)
                                o.instance
                        else
                                raise ArgumentError, "The #{o.name} class (passed as parameter #{blame}) must be instantiated directly."
                        end
                else
                        raise ArgumentError, "The #{o.name} class (passed as parameter #{blame} does not inherit from the #{type.name} class."
                end
        else
                check_type(o, type, blame, strict)
        end
end
make_ptr_to_elements(size_or_values, &block) click to toggle source

A helper function for creating constant array, vector, and struct types. This method should never be used by library users.

@param [Array<RLTK::CG::Value>, Integer] size_or_values Number of values or array of values. @param [Proc] block Block evaluated if size is specified.

@return [FFI::MemoryPointer] An array of pointers to LLVM Values.

# File lib/rltk/cg/value.rb, line 1260
def make_ptr_to_elements(size_or_values, &block)
        values =
        case size_or_values
        when Integer
                raise ArgumentError, 'Block not given.' if not block_given?

                ::Array.new(size_or_values, &block)
        else
                size_or_values
        end

        FFI::MemoryPointer.new(:pointer, values.size).write_array_of_pointer(values)
end