#ifndef OBJECT_H #define OBJECT_H #define MAX_TOK_LEN 10 // 11 #define MAX_TOK_CNT 128 // 128 #define MAX_ENV_ELM 25 // 50 #define FOR_POINTER_IN_LIST(_list) \ for(Object *_element = _list->list; \ _element != NULL;\ _element = _element->forward) #define POINTER _element #define FOR_POINTERS_IN_LISTS(_list1, _list2) \ for(Object *_element = _list1->list, *_element2 = _list2->list; \ _element != NULL && _element2 != NULL; \ _element = _element->forward, _element2 = _element2->forward) #define P1 POINTER #define P2 _element2 enum errorCode { MISMATCHED_PARENS, BAD_LIST_OF_SYMBOL_STRINGS, TYPE_LIST_NOT_CAUGHT, NULL_ENV, EMPTY_ENV, BUILT_IN_NOT_FOUND, NULL_PARSE, NULL_LAMBDA_LIST, NULL_MAP_ARGS, LAMBDA_ARGS_NOT_LIST, DID_NOT_FIND_SYMBOL, BAD_TYPE, UNEXPECTED_FORM, LISTS_NOT_SAME_SIZE, SYMBOLS_CANT_START_WITH_DIGITS, UNSUPPORTED_NUMBER_TYPE }; //#ifdef STANDALONE static const char *errorText[] = { "MISMATCHED_PARENS", "BAD_LIST_OF_SYMBOL_STRINGS", "TYPE_LIST_NOT_CAUGHT", "NULL_ENV", "EMPTY_ENV", "BUILT_IN_NOT_FOUND", "NULL_PARSE", "NULL_LAMBDA_LIST", "NULL_MAP_ARGS", "LAMBDA_ARGS_NOT_LIST", "DID_NOT_FIND_SYMBOL", "BAD_TYPE", "UNEXPECTED_FORM", "LISTS_NOT_SAME_SIZE", "SYMBOLS_CANT_START_WITH_DIGITS", "UNSUPPORTED_NUMBER_TYPE" }; //#endif #define MALLOC_FLAG 64 typedef enum Type { TYPE_NUMBER, TYPE_BOOL, TYPE_LIST, TYPE_FUNC, TYPE_SYMBOL, TYPE_LAMBDA, TYPE_STRING, TYPE_ERROR } Type; typedef struct Object Object; struct Lambda; struct Environment; struct Slice; struct Object { Type type; Object *forward; union { int number; Object *list; char name[MAX_TOK_LEN]; char *string; Object (*func)(Object, Object, struct Environment *); struct Lambda *lambda; // Maybe better as not a pointer? enum errorCode err; }; }; // Maybe better as pointers? struct Lambda { Object params; Object body; }; char* stringObj(char *dest, const Object *obj); void printList(const Object *list); void printObj(const Object *obj); void debugObj(const Object *obj); void printErr(const Object *obj); int getType(const Object *obj); int isEmpty(const Object *obj); Object *tail(const Object *listObj); void insertIntoList(Object *dest, int ind, const Object src); void replaceListing(Object *list, int i, const Object src); void nf_addToList(Object *dest, Object src); void deleteList(Object *dest); int listLength(const Object *listObj); Object *itemAt(const Object *listObj, int n); void copyList(Object *dest, const Object *src); void cleanObject(Object *target); void printAndClean(Object *target); void allocObject(Object **spot, const Object src); void appendList(Object *dest, const Object *src); Object newObject(Type type); Object listObject(); Object startList(const Object start); Object cloneList(const Object src); Object cloneObject(const Object src); Object lambdaObject(); Object symbolObject(); Object objFromSlice(const char *string, int len); Object boolObject(int b); Object numberObject(int num); Object errorObject(enum errorCode err); Object constructLambda(const Object *params, const Object *body); Object copyString(Object obj); // Object version of listLength() Object len(Object obj1, Object, struct Environment *); #endif