Class: Rubycc::Type::FloatType

Inherits:
Data
  • Object
show all
Defined in:
lib/rubycc/type.rb

Overview

A floating type: float (4 bytes, IEEE754 single precision) or double (8 bytes, IEEE754 double precision). A single shared instance stands for each (Type::Float, Type::Double); being a Data, identity and value comparison coincide, so two doubles name the very same type. long double normalizes to double at parse time (same width here), so no separate instance exists. #arithmetic? is true — a floating type mixes with the integer types under the usual arithmetic conversions — while #integer? is false and #float? true, which is how the generator tells a floating operand apart to emit the f-prefixed IR (:fadd, :flt, ...) and the integer/float conversions (:itof / :ftoi / :ftof).

Value representation (see Backend::X86_64): a float value lives in its virtual-register slot's low 4 bytes as an IEEE754 single-precision bit pattern, a double in the whole 8-byte slot as a double-precision one; a float's spare bits 32..63 follow the same indeterminate rule a narrow integer's do.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



234
235
236
# File 'lib/rubycc/type.rb', line 234

def name
  @name
end

#sizeObject (readonly)

Returns the value of attribute size

Returns:

  • (Object)

    the current value of size



234
235
236
# File 'lib/rubycc/type.rb', line 234

def size
  @size
end

Instance Method Details

#alignmentObject

A floating type is aligned to its own width: float 4, double 8.



280
281
282
# File 'lib/rubycc/type.rb', line 280

def alignment
  size
end

#arithmetic?Boolean

Returns:

  • (Boolean)


255
256
257
# File 'lib/rubycc/type.rb', line 255

def arithmetic?
  true
end

#array?Boolean

Returns:

  • (Boolean)


267
268
269
# File 'lib/rubycc/type.rb', line 267

def array?
  false
end

#bool?Boolean

Returns:

  • (Boolean)


263
264
265
# File 'lib/rubycc/type.rb', line 263

def bool?
  false
end

#char?Boolean

Returns:

  • (Boolean)


243
244
245
# File 'lib/rubycc/type.rb', line 243

def char?
  false
end

#float?Boolean

Returns:

  • (Boolean)


259
260
261
# File 'lib/rubycc/type.rb', line 259

def float?
  true
end

#function?Boolean

Returns:

  • (Boolean)


275
276
277
# File 'lib/rubycc/type.rb', line 275

def function?
  false
end

#int?Boolean

Returns:

  • (Boolean)


239
240
241
# File 'lib/rubycc/type.rb', line 239

def int?
  false
end

#integer?Boolean

Returns:

  • (Boolean)


251
252
253
# File 'lib/rubycc/type.rb', line 251

def integer?
  false
end

#pointer?Boolean

Returns:

  • (Boolean)


235
236
237
# File 'lib/rubycc/type.rb', line 235

def pointer?
  false
end

#struct?Boolean

Returns:

  • (Boolean)


271
272
273
# File 'lib/rubycc/type.rb', line 271

def struct?
  false
end

#to_sObject



284
285
286
# File 'lib/rubycc/type.rb', line 284

def to_s
  name
end

#void?Boolean

Returns:

  • (Boolean)


247
248
249
# File 'lib/rubycc/type.rb', line 247

def void?
  false
end