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:
-
`.to-int64(self): Carbon::Int64`
-
`.to-uint64(self): Carbon::UInt64`
-
`.to-int32(self): Carbon::Int32`
-
`.to-uint32(self): Carbon::UInt32`
-
`.to-int16(self): Carbon::Int16`
-
`.to-uint16(self): Carbon::UInt16`
-
`.to-int8(self): Carbon::Int8`
-
`.to-uint8(self): Carbon::UInt8`
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