module Carbon::Core::Pointer::Cast

Performs casting for pointers. This converts them into an integer for use in the program. This defines the following functions on the pointer type:

Public Instance Methods

define_cast_function(int) click to toggle source

Defines a cast function for a given integer type.

@param int [Core::Int] The integer to cast the pointer to. @return [void]

# File lib/carbon/core/pointer/cast.rb, line 35
def define_cast_function(int)
  function_name = PTYPE.call(int.cast, [PTYPE])
  Core.define(function: function_name) do |function|
    function[:return] = int.name
    define_cast_definition(int, function[:definition])
  end
end
define_cast_functions() click to toggle source

Defines all of the cast functions for all of the integer types.

@see define_cast_function @return [void]

# File lib/carbon/core/pointer/cast.rb, line 24
def define_cast_functions
  Ints.each do |int|
    next if int.size == 1
    define_cast_function(int)
  end
end

Private Instance Methods

define_cast_definition(int, definition) click to toggle source
# File lib/carbon/core/pointer/cast.rb, line 45
def define_cast_definition(int, definition)
  entry = definition.add("entry").build
  this = definition.params[0]
  this.name = "self"

  entry.ret(entry.ptr2int(this, int.name).as(int.name))
end