API

group error

Public function definitions and types for Yc’s error handling.

Typedefs

typedef bool (*y_ErrorHandler)(y_Error e, y_Status *ret)

A function to call when an error happens.

Param e:

The error to handle.

Param ret:

A pointer to return the new status.

Return:

True if the error was handled, false otherwise.

Pre:

ret must not be NULL.

Functions

bool y_err_ignore_noEnvVar(y_Error e, y_Status *ret)

A y_ErrorHandler for ignoring y_ERROR_NO_ENV_VAR.

Parameters:
  • e – The error to handle.

  • ret – A pointer to return the new status.

Returns:

True if the error was handled, false otherwise.

Pre:

ret must not be NULL.

bool y_err_ignore_elemExists(y_Error e, y_Status *ret)

A y_ErrorHandler for ignoring y_ERROR_ELEM_EXISTS.

Parameters:
  • e – The error to handle.

  • ret – A pointer to return the new status.

Returns:

True if the error was handled, false otherwise.

Pre:

ret must not be NULL.

bool y_err_ignore_fileExists(y_Error e, y_Status *ret)

A y_ErrorHandler for ignoring y_ERROR_FILE_EXISTS.

Parameters:
  • e – The error to handle.

  • ret – A pointer to return the new status.

Returns:

True if the error was handled, false otherwise.

Pre:

ret must not be NULL.

bool y_err_ignore_doesNotExist(y_Error e, y_Status *ret)

A y_ErrorHandler for ignoring y_ERROR_DOES_NOT_EXIST.

Parameters:
  • e – The error to handle.

  • ret – A pointer to return the new status.

Returns:

True if the error was handled, false otherwise.

Pre:

ret must not be NULL.

bool y_err_ignore_eof(y_Error e, y_Status *ret)

A y_ErrorHandler for ignoring y_ERROR_EOF.

Parameters:
  • e – The error to handle.

  • ret – A pointer to return the new status.

Returns:

True if the error was handled, false otherwise.

Pre:

ret must not be NULL.

group types

Public function definitions and types for Yc’s runtime type info.

Defines

y_TYPE_GEN_TYPE_STR(i)

A macro to generate a string for other macros.

Parameters:
  • i – The name of the thing to generate a name string for.

Returns:

A string corresponding to the name of i.

y_TYPE_GEN_ENUM_ITEM(i)

A macro meant to be used as a vararg to the y_TYPE_GEN_ENUM macro.

Generates an enum item from an enum item name.

Parameters:
  • i – The name of the enum item to generate.

Returns:

Material to be used in the y_TYPE_GEN_ENUM varargs.

y_TYPE_GEN_STRUCT_MEMBER(n, t, s)

A macro meant to be used as a vararg to the y_TYPE_GEN_STRUCT macro.

Generates a struct member.

Parameters:
  • n – The name of the member.

  • t – The type name of the member.

  • s – The parent struct of the member.

Returns:

Material to be used in the y_TYPE_GEN_STRUCT varargs.

y_TYPE_GEN_UNION_MEMBER(n, t)

A macro meant to be used as a vararg to the y_TYPE_GEN_UNION macro.

Generates a union member.

Parameters:
  • n – The name of the member.

  • t – The type name of the member.

Returns:

Material to be used in the y_TYPE_GEN_UNION varargs.

y_TYPE_GEN_PRIM(t)

A macro to generate type info for a primitive type.

Parameters:
  • t – The type name.

y_TYPE_GEN_POINTER(t, tp, dt)

A macro to generate type info for a pointer type.

Parameters:
  • t – The type name.

  • tp – The type the pointer points to.

  • dt – The destructor, if any.

y_TYPE_GEN_ENUM(t, ...)

A macro to generate type info for an enum type.

Parameters:
  • t – The type name.

y_TYPE_GEN_UNION(t, dt, cp, z, ...)

A macro to generate type info for a union type.

Parameters:
  • t – The type name.

  • dt – The destructor, if any.

  • cp – The copier function, if any.

  • z – The zero function, if any.

y_TYPE_GEN_STRUCT(t, dt, cp, z, ...)

A macro to generate type info for a struct type.

Parameters:
  • t – The type name.

  • dt – The destructor, if any.

  • cp – The copier function, if any.

  • z – The zero function, if any.

Typedefs

typedef const struct y_Type *(*y_TypeAnyFunc)(void)

A function type that will return a type’s type.

This is the function required to make a type obey the Any interface.

Return:

The type of the item the function is attached to.

Enums

enum y_TypeType

A enum listing the categories of types.

Values:

enumerator y_TYPE_PRIMITIVE

A primitive type (integers or floats).

enumerator y_TYPE_POINTER

Pointer types.

enumerator y_TYPE_STRUCT

Struct types.

enumerator y_TYPE_ENUM

Enum types.

enumerator y_TYPE_UNION

Union types.

struct y_TypeMember
#include <types.h>

Struct defining data for struct and union members.

struct y_TypeEnumItem
#include <types.h>

Struct defining data for enum items.

union y_TypeData
#include <types.h>

A union of data for types beyond the common data.

Public Members

y_TypeMember_array struct_members

An array for struct members.

y_TypeMember_array union_members

An array for union members.

y_TypeEnumItem_array enum_items

An array for enum items.

struct y_Type *pointer_subtype

The type that a pointer is a pointer to.

struct y_Type
#include <types.h>

The struct that defines information about types.

group opt

Common definitions for option parsing.

Typedefs

typedef struct y_opt *y_Opt

The public type of the non-public option parser.

Enums

enum y_OptType

Types of options.

Values:

enumerator y_OPT_NONE

Type for options with no arguments.

enumerator y_OPT_REQUIRED

Type for options with required arguments.

enumerator y_OPT_OPTIONAL

Type for options with optional arguments.

Functions

y_Opt y_opt_screate(void)

Creates and initializes the parser state.

Returns:

The newly-created option parser, or NULL on error.

y_Status y_opt_argv_main(y_Opt o, y_pchar **argv)

Puts a new argv into the parser state.

This is for parsing more than one argument set. The provided argv must be the one provided by the OS.

Parameters:
  • o – The y_Opt to initialize.

  • argv – The argument list that will be parsed.

Returns:

An error code, if any.

Pre:

o must not be NULL.

Pre:

argv must not be NULL.

Pre:

argv must be the argv provided by the OS.

y_Status y_opt_argv_other(y_Opt o, char **argv)

Puts a new argv into the parser state.

This is for parsing more than one argument set. The provided argv must not be the one provided by the OS.

Parameters:
  • o – The y_Opt to initialize.

  • argv – The argument list that will be parsed.

Returns:

An error code, if any.

Pre:

o must not be NULL.

Pre:

argv must not be NULL.

Pre:

argv must not be the argv provided by the OS.

void y_opt_destroy(void *options)

Frees the parser state.

Parameters:

options – The y_Opt to free.

Pre:

options must not be NULL.

int y_opt_parse(y_Opt o, const char *optstring)

Reads the next option in the argv array.

Just like getopt(), a character followed by no colons means no argument. One colon means the option has a required argument. Two colons means the option takes an optional argument.

Parameters:
  • o – The parse state.

  • optstring – A getopt()-formatted option string.

Returns:

The next option character, -1 for done, or ‘?’ for error.

Pre:

opts must not be NULL.

Pre:

optstring must not be NULL.

int y_opt_parse_long(y_Opt o, const y_OptLong *longopts, size_t *longidx)

Handles GNU-style long options in addition to getopt() options.

This works a lot like GNU’s getopt_long(). The last option in longopts must be all zeros, marking the end of the array. The longindex argument may be NULL.

Parameters:
  • o – The parse state.

  • longopts – The long options.

  • longidx – The index of the found long option in longopts.

Returns:

The next option character, -1 for done, or ‘?’ for error.

Pre:

o must not be NULL.

Pre:

longopts must not be NULL.

int y_opt_parse_long_only(y_Opt o, const y_OptLong *longopts, size_t *longidx)

Works a lot like GNU’s getopt_long_only().

Parameters:
  • o – The parse state.

  • longopts – The long options.

  • longidx – The index of the found long option in longopts.

Returns:

The next option character, -1 for done, or ‘?’ for error.

Pre:

o must not be NULL.

Pre:

longopts must not be NULL.

char *y_opt_optarg(y_Opt o)

Returns the current optarg, which is the argument given to the current option.

Parameters:

o – The parse state.

Returns:

The current optarg, or NULL, if none.

Pre:

o must not be NULL.

unsigned int y_opt_optind(y_Opt o)

Returns the current optind, which is the index of the next argument.

Parameters:

o – The parse state.

Returns:

The current optind.

Pre:

o must not be NULL.

char *y_opt_arg(y_Opt o)

Steps over non-option arguments.

Argument parsing can continue with optparse() after using this function. That would be used to parse the options for the subcommand returned by optparse_arg(). This function allows you to ignore the value of optind.

Parameters:

o – The parse state.

Returns:

The next non-option argument, or NULL for no more arguments.

Pre:

o must not be NULL.

struct y_OptLong
#include <opt.h>

Information about valid long options.

group simd

Public function definitions and types for Yc’s SIMD.

Functions

y_simd128 y_simd128l(const y_simd128 *addr)

Loads a 128-bit type from an address.

Parameters:

addr – The address to load from.

Returns:

The 128-bit SIMD data at addr.

Pre:

addr must not be NULL.

void y_simd128s(y_simd128 *addr, const y_simd128 d)

Stores 128 bits of SIMD data to memory.

Parameters:
  • addr – The address of the location the data will be stored at.

  • d – The data to store.

Pre:

addr must not be NULL.

y_simd256 y_simd256l(const y_simd256 *addr)

Loads a 256-bit type from an address.

Parameters:

addr – The address to load from.

Returns:

The 256-bit SIMD data at addr.

Pre:

addr must not be NULL.

void y_simd256s(y_simd256 *addr, const y_simd256 d)

Stores 256 bits of SIMD data to memory.

Parameters:
  • addr – The address of the location the data will be stored at.

  • d – The data to store.

Pre:

addr must not be NULL.