#ifndef MC_H1#define MC_H23extern "C" {45typedef struct list {6struct list *next; /* pointer to next item in list */7char *name; /* name of list item */8} LIST;910#ifdef _OPENMP11/* Move initialization to matc.c::mtc_init() for thread safety */12extern LIST *listheaders;13#pragma omp threadprivate(listheaders)14#else15extern LIST listheaders[];16#endif /* _OPENMP */1718#define ALLOCATIONS 019#define CONSTANTS 120#define VARIABLES 221#define COMMANDS 322#define FUNCTIONS 42324#define MAX_HEADERS 42526#define ALLOC_HEAD listheaders[ALLOCATIONS].next27#define CONST_HEAD listheaders[CONSTANTS].next28#define VAR_HEAD listheaders[VARIABLES].next29#define COM_HEAD listheaders[COMMANDS].next30#define FUNC_HEAD listheaders[FUNCTIONS].next3132#define NEXT(lst) (lst)->next33#define NAME(lst) (lst)->name3435/*******************************************************************36MEMORY HANDLING37********************************************************************/3839/*40memory allocation and deallocation routines41*/42#define ALLOCMEM(size) mem_alloc(size)43#define FREEMEM(ptr) mem_free(ptr)4445/*46we use a lot of string copying.47*/48#define STRCOPY(str) strcpy((char *)ALLOCMEM(strlen(str)+1),(str))4950typedef struct alloc_list {51struct alloc_list *next;52char *mem;53} ALLOC_LIST;5455#define ALLOC_LST(mem) (ALLOC_LIST *)((char *)mem-sizeof(ALLOC_LIST))56#define ALLOC_SIZE(size) (size+sizeof(ALLOC_LIST))57#define ALLOC_PTR(lst) (char *)((char *)lst+sizeof(ALLOC_LIST))5859/*******************************************************************60VARIABLES61*******************************************************************/6263/*64* MATC matrix is internally represented by this structure.65*/66typedef struct MATRIX67{68int type, /* TYPE_DOUBLE or TYPE_STRING */69refcount, /* reference count */70nrow, ncol; /* number of rows and columns */71double *data; /* pointer to double array */72} MATRIX;737475/*76* list of VARIABLES77*/7879typedef struct variable80{81struct variable *next; /* pointer to next item in list */82char *name; /* name of the item */83int changed;84MATRIX *me;85} VARIABLE;8687/*88shortcuts for accessing structure MATRIX89*/90#define MATR(ptr) (ptr)->me->data91#define TYPE(ptr) (ptr)->me->type92#define NROW(ptr) (ptr)->me->nrow93#define NCOL(ptr) (ptr)->me->ncol94#define REFCNT(ptr) (ptr)->me->refcount95#define M(ptr,i,j) (ptr)->me->data[(i) * NCOL(ptr) + (j)]9697#define VARIABLESIZE sizeof(VARIABLE)98#define MATRIXSIZE sizeof(MATRIX)99#define MATSIZE(ptr) NROW(ptr)*NCOL(ptr)*sizeof(double)100101#define TYPE_DOUBLE 0102#define TYPE_COMPLEX 1 /* this is not */103#define TYPE_STRING 2104105/*******************************************************************106INTERNAL COMMANDS AND USER FUNCTIONS107*******************************************************************/108109typedef struct command110{111struct command *next; /* pointer to next item in list */112char *name; /* name of the item */113int flags, /* CMDFLAG_PW & CMDFLAG_CE */114minp, maxp; /* min. and max. no. of parameters */115VARIABLE *(*sub)(); /* function to execute */116char *help; /* help string... */117} COMMAND;118119#define COMSIZE sizeof(COMMAND)120121#define CMDFLAG_PW 1 /* element by element operation */122#define CMDFLAG_CE 2 /* command can be executed when123preprocessing if constant124arguments. */125126/*******************************************************************127USER DEFINED FUNCTIONS128*******************************************************************/129130typedef struct function131{132struct function *next; /* pointer to next function in list */133char *name, /* name of the function */134**parnames, /* function parameter names (if any) */135**exports, /* functions exported variables */136**imports, /* functions imported variables */137*help; /* functions help text */138int parcount; /* defined number of parameters */139struct clause *body; /* function body */140} FUNCTION;141142#define FUNCSIZE sizeof(FUNCTION)143144}145146#endif // MC_H147148149