module Carbon::Core::Pointer::Access
Methods that perform accesses on pointers. This is essentially dereferencing and indexing. This defines the following functions:
-
`Carbon::Pointer<T>.value(self): T`
-
`Carbon::Pointer<T>.value=(self, value: T): T`
-
`Carbon::Pointer<T>.[]<I: Carbon::Numeric>(self, index: I): T`
-
`Carbon::Pointer<T>.[]=<I: Carbon::Numeric>(self, index: I, value: T): T`
@api private
Public Instance Methods
Define all of the access functions. This iterates over all of the integers, defining the array get/set functions in terms of each integer type. It then defines the value get/set functions.
@return [void]
# File lib/carbon/core/pointer/access.rb, line 23 def define_access_functions Ints.each do |int| next if int.size == 1 define_array_get_function(int) define_array_set_function(int) end define_value_get_function define_value_set_function end
Defines the array get function. This function (named `[]`) gets the value at a given distance away from the pointer.
@param int [Core::Int] The integer type for the index. @return [void]
# File lib/carbon/core/pointer/access.rb, line 77 def define_array_get_function(int) function_name = PTYPE.call(:[], [PTYPE, int.name]) Core.define(function: function_name) do |function| function[:return] = PTYPEGEN define_array_get_definition(int, function[:definition]) end end
Defines the array set function. This function (named `[]=`) sets the value a given distance away from the pointer.
@param int [Core::Int] The integer type for the index. @return [void]
# File lib/carbon/core/pointer/access.rb, line 64 def define_array_set_function(int) function_name = PTYPE.call(:[]=, [PTYPE, int.name, PTYPEGEN]) Core.define(function: function_name) do |function| function[:return] = PTYPEGEN define_array_set_definition(int, function[:definition]) end end
Defines the value get function. This function (named `value`) gets the value at the pointer. This is the same as calling the array get function with an index of zero (0).
@return [void]
# File lib/carbon/core/pointer/access.rb, line 51 def define_value_get_function function_name = PTYPE.call(:value, [PTYPE]) Core.define(function: function_name) do |function| function[:return] = PTYPEGEN define_value_get_definition(function[:definition]) end end
Defines the value set function. This function (named `value=`) sets the value at the pointer. This is the same as calling the array set function with an index of zero (0).
@return [void]
# File lib/carbon/core/pointer/access.rb, line 38 def define_value_set_function function_name = PTYPE.call(:value=, [PTYPE, PTYPEGEN]) Core.define(function: function_name) do |function| function[:return] = PTYPEGEN define_value_set_definition(function[:definition]) end end
Private Instance Methods
# File lib/carbon/core/pointer/access.rb, line 97 def define_array_get_definition(_int, definition) entry = definition.add("entry").build this, index = definition.params this.name, index.name = %w(self index) gep = entry.gep(this, index).as(Carbon::Type("Carbon::UInt64")) load = entry.load(gep).as(PTYPEGEN) entry.ret(load) end
# File lib/carbon/core/pointer/access.rb, line 87 def define_array_set_definition(_int, definition) entry = definition.add("entry").build this, index, value = definition.params this.name, index.name, value.name = %w(self index value) gep = entry.gep(this, index).as(Carbon::Type("Carbon::UInt64")) entry.store(gep, value) entry.ret(value) end
# File lib/carbon/core/pointer/access.rb, line 116 def define_value_get_definition(definition) entry = definition.add("entry").build this = definition.params[0] this.name = "self" entry.ret(entry.load(this).as(PTYPEGEN)) end
# File lib/carbon/core/pointer/access.rb, line 107 def define_value_set_definition(definition) entry = definition.add("entry").build this, value = definition.params this.name, value.name = %w(self value) entry.store(this, value) entry.ret(value) end