#ifndef SW_DATA_TYPES #define SW_DATA_TYPES /* The different types of the language. */ typedef enum SwTypes { SW_TYPE_BOOL=1, SW_TYPE_INT, SW_TYPE_FLOAT, SW_TYPE_STRING, SW_TYPE_LIST, SW_TYPE_DICT /*, SW_TYPE_PROC, SW_TYPE_FUNC*/ } SwTypes; /* Variables/functions/procedures. Simple variables are considered value-based since what they reference is a basic type. When an identifier points to another identifier then it is a reference. Finally, when an identifier is a procedure or function then it is considered to link to a context. */ typedef struct SwIdentifier { char *name; /* name of identifier, null if no name */ SwTypes type; enum { SW_ID_TYPE_TYPE=1, /* one of the basic types: int, float, etc */ SW_ID_TYPE_REFERENCE,/* a SwIdentifier */ SW_ID_TYPE_CONTEXT /* a SwContext */ } value_type; void *value; /* cast when more is known about the type */ } SwIdentifier; /* Different contexts. Note: contexts can be nested. When we ask for the value of an identifier we search the locals, then the id, then we recursively move up to this context's parent and continue the search in this manner. */ typedef struct SwContext { struct SwContext *parent;/* the parent/calling context. If we are dealing with the logical parent context then this context will have that type. Otherwise, we consider the calling context to be the virtual contextual parent and it will change according to where this context is used from. */ struct SwContext *child; /* necessary? */ enum { SW_CONTEXT_LOGICAL=1,/* based on appearance in the code, functions have logical context because they act like containers around procedures, forcing the procedure's context to be logical. */ SW_CONTEXT_VIRTUAL /* based on where this context is used/called, procedures have virtual context. */ } parent_type; SwIdentifier *self; /* the identifier representing the context we are in. */ SwIdentifier *locals[]; /* an array of pointers to local variables */ int natural_locals_count;/* the number of local variables excluding those passed in as arguments to this context. */ int ref_count; /* the number of references in the context. */ /* ... */ } SwContext; #endif