module Carbon::Core::Integer::Zero

Defines zero functions. These can be used to determine if an integer is (or isn't) zero. This defines all of these functions on all integers except booleans:

@api private

Public Instance Methods

define_nonzero_function(int) click to toggle source

Defines the nonzero function. The function returns `true` if the value isn't equal to zero.

@param int [Core::Int] The (receiver) value. @return [void]

# File lib/carbon/core/integer/zero.rb, line 38
def define_nonzero_function(int)
  function_name = int.name.call("nonzero?", [int.name])
  Core.define(function: function_name) do |function|
    function[:return] = Carbon::Boolean
    function[:definition].add("entry").build do |b|
      this = function[:definition].params[0]
      this.name = "self"
      b.ret(b.icmp(:ne, this, 0).as(Carbon::Boolean))
    end
  end
end
define_zero_function(int) click to toggle source

Defines the zero function. The function returns `true` if the value is equal to zero.

@param int [Core::Int] The (receiver) value. @return [void]

# File lib/carbon/core/integer/zero.rb, line 21
def define_zero_function(int)
  function_name = int.name.call("zero?", [int.name])
  Core.define(function: function_name) do |function|
    function[:return] = Carbon::Boolean
    function[:definition].add("entry").build do |b|
      this = function[:definition].params[0]
      this.name = "self"
      b.ret(b.icmp(:eq, this, 0).as(Carbon::Boolean))
    end
  end
end