C Types

Idio supports the use of the fourteen C base types and typedefs thereof and a pointer type:

Idio

C

C/char

char

C/schar

signed char

C/uchar

unsigned char

C/short

short

C/ushort

unsigned short

C/int

int

C/uint

unsigned int

C/long

long

C/ulong

unsigned long

C/longlong

long long

C/ulonglong

unsigned long long

C/float

float

C/double

double

C/longdouble

long double

C/pointer

void *

Equality tests of C/longdouble are, at best, untested.

The C/pointer type is used to carry references to C allocated memory. They will usually be tagged such that the GC will free the referenced memory when it collects the value.

There is a special form of C/pointer with a C Structure Identifier tag which allows for the implicit use of accessors and printers of that value. Most of the allocated C structs in libc are so tagged.

C Type Predicates

function C/char? o

test if o is a C/char

Param o:

object to test

Return:

#t if o is a C/char, #f otherwise

function C/schar? o

test if o is a C/schar

Param o:

object to test

Return:

#t if o is a C/schar, #f otherwise

function C/uchar? o

test if o is a C/uchar

Param o:

object to test

Return:

#t if o is a C/uchar, #f otherwise

function C/short? o

test if o is a C/short

Param o:

object to test

Return:

#t if o is a C/short, #f otherwise

function C/ushort? o

test if o is a C/ushort

Param o:

object to test

Return:

#t if o is a C/ushort, #f otherwise

function C/int? o

test if o is a C/int

Param o:

object to test

Return:

#t if o is a C/int, #f otherwise

function C/uint? o

test if o is a C/uint

Param o:

object to test

Return:

#t if o is a C/uint, #f otherwise

function C/long? o

test if o is a C/long

Param o:

object to test

Return:

#t if o is a C/long, #f otherwise

function C/ulong? o

test if o is a C/ulong

Param o:

object to test

Return:

#t if o is a C/ulong, #f otherwise

function C/longlong? o

test if o is a C/longlong

Param o:

object to test

Return:

#t if o is a C/longlong, #f otherwise

function C/ulonglong? o

test if o is a C/ulonglong

Param o:

object to test

Return:

#t if o is a C/ulonglong, #f otherwise

function C/float? o

test if o is a C/float

Param o:

object to test

Return:

#t if o is a C/float, #f otherwise

function C/double? o

test if o is a C/double

Param o:

object to test

Return:

#t if o is a C/double, #f otherwise

function C/longdouble? o

test if o is a C/longdouble

Param o:

object to test

Return:

#t if o is a C/longdouble, #f otherwise

function C/pointer? o

test if o is a C/pointer

Param o:

object to test

Return:

#t if o is a C/pointer, #f otherwise

function C/type? o

test if o is any C type

Param o:

object to test

Return:

#t if o is any C type, #f otherwise

function C/number? o

test if o is any C numeric type

Param o:

object to test

Return:

#t if o is any C numeric type, #f otherwise

function C/integral? o

test if o is any C integral numeric type

Param o:

object to test

Return:

#t if o is any C integral numeric type, #f otherwise

function C/signed? o

test if o is any C signed numeric type

Param o:

object to test

Return:

#t if o is any C signed numeric type, #f otherwise

function C/unsigned? o

test if o is any C unsigned numeric type

Param o:

object to test

Return:

#t if o is any C unsigned numeric type, #f otherwise

function C/floating? o

test if o is a C floating point type

Param o:

object to test

Return:

#t if o is a C floating point type, #f otherwise

C Type Constructors

function C/integer-> i [type]

convert Idio integer i to a C integer

If i is a fixnum then use type for a more specific C type.

An integer bignum is converted to a libc/intmax_t.

Param i:

Idio integer to convert

Type i:

fixnum or bignum

Param type:

C type to create, defaults to 'int

Type type:

symbol, optional

Return:

C integer

Rtype:

according to type

Raises:

^rt-C-conversion-error:

type defaults to 'int and can be one of: 'char 'schar 'uchar 'short 'ushort 'int 'uint 'long 'ulong 'longlong 'ulonglong or an alias thereof, eg. libc/pid_t.

i is range-checked for type

C/integer-> is limited to a C intmax_t, see C/integer->unsigned

function C/integer->unsigned i [C/unsigned type]

convert Idio integer i to a C unsigned integer

If i is a fixnum then use type for a more specific C type.

An integer bignum is converted to a libc/uintmax_t.

Param i:

Idio integer to convert

Type i:

bignum or fixnum

Param type:

C type to create, defaults to 'uint

Type type:

symbol, optional

Return:

C unsigned integer

Rtype:

according to type

Raises:

^rt-C-conversion-error:

type defaults to 'uint and can be one of: 'uchar 'ushort 'uint 'ulong 'ulonglong or an alias thereof, eg. libc/size_t.

i is range-checked for type

C/integer->unsigned is limited to a C uintmax_t

function C/number-> n type

convert Idio number n to a C number using type for the specific C type.

bignums must be a C floating type

Param n:

Idio number to convert

Type n:

fixnum or bignum

Param type:

C type to create

Type type:

symbol

Return:

C number

Rtype:

according to type

Raises:

^rt-C-conversion-error:

type can be one of: 'char 'schar 'uchar 'short 'ushort 'int 'uint 'long 'ulong 'longlong 'ulonglong 'float 'double 'longdouble or an alias thereof, eg. libc/size_t.

n is range-checked for integral types

Where type is:

Warning

If n is a bignum then type can only be a floating point type.

C Type Converters

function C/->integer i

convert C integer i to an Idio integer

Param o:

C integer to convert

Type o:

C/ integer type

Return:

Idio integer

Rtype:

integer

function C/->number i

convert C number i to an Idio number

Param o:

C number to convert

Type o:

a C/ numeric type

Return:

Idio number

Rtype:

number

supported C types are: C/char C/schar C/uchar C/short C/ushort C/int C/uint C/long C/ulong C/longlong C/ulonglong C/float C/double or an alias thereof, eg. libc/size_t.

the following types are NOT supported: C/longdouble

C Pointer Reflection

C pointers can be tagged with some C Structure Identification (CSI) information. The purpose is multi-fold where, using libc/struct-stat as an example:

  • we can store a nominal structure name, eg. libc/struct-stat

    The name is descriptive only.

  • we can store a list of the structure members, eg. libc/struct-stat’s:

    (st_dev st_ino st_nlink st_mode st_uid st_gid st_rdev st_size st_blksize st_blocks st_atim st_mtim st_ctim st_atime st_mtime st_ctime)

    Note

    The modern C struct stat does not have st_atime etc. members per se but those are #define’d to the time_t tv_sec components of the corresponding st_atim’s struct timespec thus maintaining backwards compatibility.

    Idio supports accessing both forms.

  • we can associate a getter to manipulate the C/pointer given a member name, here, libc/struct-stat-ref

    We can subsequently associate a setter with the getter – albeit there is (deliberately) no setter for a libc/struct-stat.

  • we can associate a function to print the C/pointer in a more aesthetically pleasing manner. For example, the struct timespec is stylised as a floating point number.

    Here, we associate libc/struct-stat-as-string.

function C/pointer-name p

Return the CSI name of C/pointer p

Param p:

C/pointer to query

Type p:

C/pointer

Return:

CSI name or #n

Rtype:

symbol or #n

The CSI name is descriptive only.

function C/pointer-members p

Return the CSI members of C/pointer p

Param p:

C/pointer to query

Type p:

C/pointer

Return:

CSI members or #n

Rtype:

list

Last built at 2024-05-17T06:10:42Z+0000 from 62cca4c (dev) for Idio 0.3.b.6