#ifndef _l_h_ #define _l_h_ /* l.h - Common header for a minimalistic Lisp implementation. Samuel A. Rebelsky Version 0.1 of 3 March 2007 */ #include /********************************************************************* * Design Notes * ****************/ /* On the Intel architecture (for which this is designed), we are fortunate that pointers, ints, and floats all take four eight-bit bytes. Hence, we can convert between the types easily. (We won't deal with floats in this implementation, though.) When a pair stores a symbol, we will set the car to L_SYMBOL and the cdr to the string representation of that symbol. When a pair stores a string, we will set the car to L_STRING and the cdr to the string. When a pair stores an integer, we will set the car to L_INT and the cdr to the value (not a pointer to the value). */ /********************************************************************* * Types * *********/ typedef void *pointer; /* The primary building block of Lisp programs. */ typedef struct pair { pointer car; pointer cdr; } *pair; /********************************************************************* * Constants * *************/ /* We use small numbers, unlikely to be real pointers, to indicate the * various types. */ #define L_SYMBOL ((pointer) 1) #define L_STRING ((pointer) 2) #define L_INT ((pointer) 3) #define L_MAX_CONSTANT 3 /* We will allocate the following constant symbols separately */ extern pair L_CAR; extern pair L_CDR; extern pair L_COND; extern pair L_CONS; extern pair L_DEFINE; extern pair L_EQ; extern pair L_ERROR; extern pair L_FALSE; extern pair L_LABEL; extern pair L_LAMBDA; extern pair L_NIL; extern pair L_QUOTE; extern pair L_TRUE; /********************************************************************* * Macros * **********/ #define CAR(PAIR) (((pair) PAIR)->car) #define CDR(PAIR) (((pair) PAIR)->cdr) /********************************************************************* * Procedures * **************/ /* From l_io.c */ extern void l_print(FILE *stream, pair root); extern pair l_parse(char *str); /* From l_eval.c */ extern void init_env(); extern pair l_eval(pair exp); extern int l_eq(pair left, pair right); /* From l_types.c */ extern pair make_int(int val); extern pair make_string(char *val); extern pair make_symbol(char *val); extern int is_nil(pair val); extern int is_int(pair val); extern int is_string(pair val); extern int is_symbol(pair val); extern int is_pair(pair val); /* From l_sym.c */ extern void init_sym(); extern pair insert(char *sym); /* From l_mem.c */ extern void init_mem(int size); extern pair allocate_pair(pointer left, pointer right); #endif /* _l_h_ */