Class: CArray::JIT::CType

Inherits:
Struct
  • Object
show all
Defined in:
lib/carray/jit/c_function.rb

Overview

One parameter or return type, as the prototype spelled it.

Fiddle's parser answers what the ABI needs and no more: every pointer comes back as TYPE_VOIDP, so const double *, double * and void * are one thing to it. That is enough to call a function and not enough to write one, which is why the declarator's own text is kept beside the code Fiddle assigned it.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#array ⇒ Object

Returns the value of attribute array



15
16
17
# File 'lib/carray/jit/c_function.rb', line 15

def array
  @array
end

#computation ⇒ Object

Returns the value of attribute computation



15
16
17
# File 'lib/carray/jit/c_function.rb', line 15

def computation
  @computation
end

#const ⇒ Object

Returns the value of attribute const



15
16
17
# File 'lib/carray/jit/c_function.rb', line 15

def const
  @const
end

#element ⇒ Object

Returns the value of attribute element



15
16
17
# File 'lib/carray/jit/c_function.rb', line 15

def element
  @element
end

#fiddle ⇒ Object

Returns the value of attribute fiddle



15
16
17
# File 'lib/carray/jit/c_function.rb', line 15

def fiddle
  @fiddle
end

#pointer ⇒ Object

Returns the value of attribute pointer



15
16
17
# File 'lib/carray/jit/c_function.rb', line 15

def pointer
  @pointer
end

#text ⇒ Object

Returns the value of attribute text



15
16
17
# File 'lib/carray/jit/c_function.rb', line 15

def text
  @text
end

Instance Method Details

#complex? ⇒ Boolean

A C99 complex passed or returned by value. Fiddle cannot carry one, so a call from Ruby goes through a shim; a call from a kernel is C calling C and needs nothing.



32
33
34
# File 'lib/carray/jit/c_function.rb', line 32

def complex?
  !pointer && CDeclaration::COMPLEX_CODES.value?(fiddle)
end

#complex_build ⇒ Object

CMPLX for a double complex, CMPLXF for a float one.



37
38
39
# File 'lib/carray/jit/c_function.rb', line 37

def complex_build
  fiddle == :float_complex ? "CMPLXF" : "CMPLX"
end

#declare(name) ⇒ Object

A declarator with the name in it, which for an array is not simply the type followed by the name.



53
54
55
56
# File 'lib/carray/jit/c_function.rb', line 53

def declare (name)
  return "#{text} #{name}" unless array
  "#{text.sub(/\s*\[.*\]\z/, "")} #{name}[#{array if sized?}]"
end

#indexable? ⇒ Boolean

A pointer to numbers, which a body may index. void * is not one: it points at nothing in particular, so it stays a slot.



25
26
27
# File 'lib/carray/jit/c_function.rb', line 25

def indexable?
  pointer && !element.nil?
end

#opaque? ⇒ Boolean

True for a type that may be written into a signature but holds no value a kernel or a body can compute with.



19
20
21
# File 'lib/carray/jit/c_function.rb', line 19

def opaque?
  computation.nil?
end

#sized? ⇒ Boolean

C's own declarator puts an array's length where a reader can see it, so const double coef[3] and const double *coef are different declarations of the same ABI. The length is kept rather than folded away: a subscript into a parameter has no extent behind it unless the declaration carried one, and this compiler's subscripts have always had one.



47
48
49
# File 'lib/carray/jit/c_function.rb', line 47

def sized?
  array.is_a?(Integer)
end

#to_s ⇒ String



59
60
61
# File 'lib/carray/jit/c_function.rb', line 59

def to_s
  text
end