pebblisp/src/object.h

92 lines
2.0 KiB
C
Raw Normal View History

2020-05-05 13:42:28 -04:00
#ifndef OBJECT_H
#define OBJECT_H
#define MAX_TOK_LEN 4 // 11
#define MAX_TOK_CNT 128 // 128
#define MAX_ENV_ELM 15 // 50
enum errorCode {
BAD_LIST_OF_SYMBOL_STRINGS,
TYPE_LIST_NOT_CAUGHT,
NULL_ENV,
BUILT_IN_NOT_FOUND,
2020-05-05 19:21:54 -04:00
NULL_PARSE,
NULL_LAMBDA_LIST,
LAMBDA_ARGS_NOT_LIST,
DID_NOT_FIND_SYMBOL,
UNEXPECTED_FORM
2020-05-05 13:42:28 -04:00
};
2020-05-05 19:21:54 -04:00
#ifdef STANDALONE
static const char *errorText[] = {
"BAD_LIST_OF_SYMBOL_STRINGS",
"TYPE_LIST_NOT_CAUGHT",
"NULL_ENV",
"BUILT_IN_NOT_FOUND",
"NULL_PARSE",
"NULL_LAMBDA_LIST",
"LAMBDA_ARGS_NOT_LIST",
"DID_NOT_FIND_SYMBOL",
"UNEXPECTED_FORM"
2020-05-05 19:21:54 -04:00
};
#endif
2020-05-05 13:42:28 -04:00
typedef enum Type {
TYPE_NUMBER,
TYPE_BOOL,
TYPE_LIST,
TYPE_FUNC,
TYPE_SYMBOL,
TYPE_LAMBDA,
TYPE_ERROR // Currently unused
} Type;
typedef struct Object Object;
struct Lambda;
struct Object {
Type type;
Object *forward;
union {
int number;
Object *list;
char name[MAX_TOK_LEN];
Object (*func)(Object, Object);
struct Lambda *lambda; // Maybe better as not a pointer?
2020-05-05 13:42:28 -04:00
enum errorCode err;
};
};
// Maybe better as pointers?
2020-05-05 13:42:28 -04:00
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);
2020-05-05 13:42:28 -04:00
int isEmpty(const Object *obj);
2020-05-05 13:42:28 -04:00
Object *tail(const Object *listObj);
void addToList(Object *dest, Object src);
void deleteList(const Object *dest);
int listLength(const Object *listObj);
Object *itemAt(const Object *listObj, int n);
void copyList(Object *dest, const Object *src);
2020-05-05 19:21:54 -04:00
void cleanObject(Object *target);
void allocObject(Object **spot, const Object src);
2020-05-05 19:21:54 -04:00
Object newObject(Type type);
2020-05-05 13:42:28 -04:00
Object listObject();
Object lambdaObject();
Object symbolObject();
Object boolObject(int b);
Object numberObject(int num);
2020-05-05 19:21:54 -04:00
Object errorObject(enum errorCode err);
Object constructLambda(const Object *params, const Object *body);
2020-05-05 13:42:28 -04:00
#endif