Module: Carbon::Core::Integer::Sign Private

Included in:
Carbon::Core::Integer
Defined in:
lib/carbon/core/integer/sign.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Defines signage functions. This can be used to determine if an integer is signed or unsigned. This defines the following functions on all integers except boolean:

  • .signed?(): Carbon::Boolean
  • .signed?(self): Carbon::Boolean
  • .unsigned?(): Carbon::Boolean
  • .unsigned?(self): Carbon::Boolean

Instance Method Summary collapse

Instance Method Details

#define_sign_function(int, sign, args) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Defines a sign function. If the integer is the same sign as the given sign, the defined function returns true; otherwise, it returns false.

Parameters:

  • int (Core::Int)

    The (receiver) value.

  • sign (::Symbol)

    The sign function to define.

  • args (<Concrete::Type>)

    The arguments that the function takes. These are ignored.



40
41
42
43
44
45
46
47
48
# File 'lib/carbon/core/integer/sign.rb', line 40

def define_sign_function(int, sign, args)
  function_name = int.name.call("#{sign}?", args)
  Core.define(function: function_name) do |function|
    function[:return] = Carbon::Boolean
    function[:definition].add("entry").build do |b|
      int.sign == sign ? b.ret(1) : b.ret(0)
    end
  end
end

#define_sign_functions(int) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Defines the sign functions on the given integer. This produces the four variants of the sign functions: signed vs. unsigned, and no vs. one parameter.

Parameters:



24
25
26
27
28
29
30
# File 'lib/carbon/core/integer/sign.rb', line 24

def define_sign_functions(int)
  params = [[], [int.name]]
  signs = [:signed, :unsigned]
  params.product(signs).each do |(param, sign)|
    define_sign_function(int, sign, param)
  end
end