Procedures

struct UNIT_Procedure

A container of instructions representing a function that will eventually be compiled by UNIT.

UNIT_Context *context

The context being used by this procedure.

const char *name

The name of the procedure.

UNIT_Status UNIT_Procedure_Init(UNIT_Procedure *procedure, UNIT_Context *context, const char *name)

Initialize a procedure. On success, UNIT_Procedure_Clear() must be called later to free memory allocated by this function.

Parameters:
  • procedure – A pointer to a procedure. Memory at this location will be overwritten.

  • context – The context that will be used when interacting with the procedure. This must be valid for the lifetime of the procedure.

  • name – A string indicating the name of the procedure. This string must be valid for the lifetime of the procedure.

Returns:

Indicator whether the call was successful. See UNIT_FAILED.

Example
 1UNIT_Context context;
 2/* Initialize the context ... */
 3
 4UNIT_Procedure procedure;
 5if (UNIT_FAILED(UNIT_Procedure_Init(&procedure, &context, "main"))) {
 6    /* Clear the context ... */
 7    return -1;
 8}
 9
10// Must call UNIT_Procedure_Clear() later.
UNIT_Procedure *UNIT_Procedure_New(UNIT_Context *context, const char *name)

Create a new procedure. On success, UNIT_Procedure_Free() must be called later to free memory allocated by this function.

Parameters:
  • context – The context that will be used when interacting with the procedure. This must be valid for the lifetime of the procedure.

  • name – A string indicating the name of the procedure. This string must be valid for the lifetime of the procedure.

Returns:

A heap-allocated pointer to the procedure, or NULL if an allocation failed. If non-NULL, must be deallocated using UNIT_Procedure_Free().

Example
 1UNIT_Context context;
 2/* Initialize the context ... */
 3
 4UNIT_Procedure *procedure = UNIT_Procedure_New(&context, "main");
 5if (procedure == NULL) {
 6    /* Clear the context ... */
 7    return -1;
 8}
 9
10// Must call UNIT_Procedure_Free() later.
void UNIT_Procedure_Clear(UNIT_Procedure *procedure)

Free memory allocated by UNIT_Procedure_Init().

Parameters:
  • procedure – The procedure to clear.

Example
1UNIT_Procedure procedure;
2if (UNIT_FAILED(UNIT_Procedure_Init(&procedure, /* ... */))) {
3   /* ... */
4}
5
6/* ... */
7
8UNIT_Procedure_Clear(&procedure);
void UNIT_Procedure_Free(UNIT_Procedure *procedure)

Free memory allocated by UNIT_Procedure_New()

Parameters:
  • procedure – The procedure to free.

Example
1UNIT_Procedure *procedure = UNIT_Procedure_New(/* ... */);
2if (procedure == NULL) {
3   /* ... */
4}
5
6/* ... */
7
8UNIT_Procedure_Free(procedure);