Previous: , Up: Types   [Contents][Index]


20.6.4 typeof

The typeof language construction provides information about some Poke type. It has the form:

typeof (entity)

where entity is either a value or a type specifier. It returns a Pk_Type value describing either the specified type, or the type of the specified value.

The Pk_Type struct provides the following fields for all kind of types:

uint<32> code

This is a numerical code that identifies the kind of the described type.

Valid codes are PK_TYPE_UNKNOWN, PK_TYPE_INTEGRAL, PK_TYPE_OFFSET, PK_TYPE_STRING, PK_TYPE_ARRAY, PK_TYPE_STRUCT, PK_TYPE_FUNCTION and PK_TYPE_ANY.

string name

If the described type is named, then this field contains the name. Otherwise it is the empty string.

(poke) type myint = int
(poke) typeof (1 as myint)
Pk_Type {
  code=1,
  name="myint",
  [...]
}
int<32> complete_p

If the size of the described type can be determined at compile time, then this field is 1, 0 otherwise.

The following fields are provided in Pk_Type only for integral, offset and integral struct types:

int<32> signed_p

If the described type is signed, this field is 1, 0 otherwise.

uint<64> size

The number of bits of values of the described integral type, or the number of bits of the integral value of the described integral struct type, or the number of bits of the magnitude of the described offset type.

This would be 23UL for an int<23> type, and 32UL for an offset<int<32>,1> type.

The following fields are provided in Pk_Type only for offset types:

_unit

The unit of the described offset type, in bit units. This would be 8UL for an offset<int<32>,B> type, for example.

The following fields are provided in Pk_Type only for array types:

int<32> bounded_p

This field is 1 if the described array type is bounded by either number of elements or by size, 0 otherwise.

The following fields are provided in Pk_Type only for struct types:

int<32> union_p

This field is 1 if the described struct type is an union, 0 otherwise.

int<32> pinned_p

This field is 1 if the described struct type is pinned, 0 otherwise.

int<32> integral_p

This field is 1 if the described struct type is integral, 0 otherwise.

int<32> nfields

Number of fields defined in the described struct type. This count includes optional fields and computed fields.

int<32> nmethods

Number of methods defined in the described struct type.

string[] fnames

Array of nfields strings, with the names of the fields defined in the described struct type. Anonymous fields feature empty strings.

int<32>[] fcomputed

Array of nfields integers, which are 1 for fields that are computed, 0 for fields that are not computed.

string[] ftypes

Array of nfields strings, with the type specifiers of the types of the fields defined in the described struct type.

string[] mnames

Array of nmethods strings, with the names of the methods defined in the described struct type.

string[] mtypes

Array of nmethods strings, with the type specifiers of the types of the methods defined in the described struct type.

(any)any deintegrator

Closure that, when passed an integral value of the same signedness and width than the described integral struct, returns the struct value corresponding to that value.

(poke) type Foo = struct int<32> { int<16> a; uint<16> b; }
(poke) typeof (Foo).deintegrator (0x0eadbeef)
Foo {
  a=0x0eadH,
  b=0xbeefUH
}

The following fields are provided in Pk_Type only for struct and array types:

(int<32>,int<32>,uint<64>)any mapper

Closure that, when passed an integer predicate denoting whether to do a strict mapping, an IO space identifier, a bit-offset in the given IO space, map a value of the described type.

(any)void writer

Closure that, when passed a mapped value of the described type, writes the contents of the value to the corresponding IO space.

(any)any integrator

Closure that, when passed a value of the described type (an array type or an integral struct type) returns the integral value corresponding to the contents of the value.

(poke) type Foo = struct int<32> { int<16> a; uint<16> b; }
(poke) typeof (Foo).integrator (Foo { a = 0xab, b = 0xcd })
0x00ab00cd
(any,any)int<32> comparator

Closure that, when passed two values of the described type, returns 1 if the values are equal,0 otherwise.


Previous: The isa Operator, Up: Types   [Contents][Index]