1: /* Courier.h 4.1 83/07/03 */ 2: 3: #include <stdio.h> 4: 5: #define NIL 0 6: #define MAXSTR 200 7: #define streq(s, t) (strcmp(s, t) == 0) 8: #define New(t) ((t *) calloc(1, sizeof(t))) 9: 10: /* 11: * Cons cell for lisp operations. 12: */ 13: struct cons { 14: struct cons *c_cdr; 15: struct cons *c_car; 16: }; 17: typedef struct cons *list; 18: #define car(x) ((x)->c_car) 19: #define cdr(x) ((x)->c_cdr) 20: 21: /* 22: * Object classes. 23: */ 24: enum class { 25: O_TYPE = 1, 26: O_CONSTANT, 27: O_SYMBOL 28: }; 29: 30: /* 31: * Type constructors. 32: */ 33: enum constr { 34: C_PREDEF = 1, 35: C_ENUMERATION, 36: C_ARRAY, 37: C_SEQUENCE, 38: C_RECORD, 39: C_CHOICE, 40: C_PROCEDURE, 41: C_ERROR 42: }; 43: 44: /* 45: * Object structure, for types, numbers, and strings. 46: */ 47: struct object { 48: enum class o_class; 49: union { 50: struct type *u_type; 51: char *u_name; 52: int u_value; 53: } o_union; 54: }; 55: #define o_type o_union.u_type 56: #define o_name o_union.u_name 57: #define o_value o_union.u_value 58: 59: #define class_of(x) (((struct object *) x)->o_class) 60: #define name_of(x) (((struct object *) x)->o_name) 61: #define value_of(x) (((struct object *) x)->o_value) 62: 63: /* 64: * Type structure. 65: * 66: * Formats of various lists are as follows. 67: * . indicates a cons operation. 68: * ... indicates a list of elements of the preceding form. 69: * 70: * enumeration: 71: * ((name . value) ...) 72: * record, error, procedure arguments, procedure results: 73: * (((name ...) . type) ...) 74: * choice: 75: * ((((name . value) ...) . type) ...) 76: */ 77: struct type { 78: enum constr type_constr; /* constructor */ 79: char *type_pfname; /* name of pack function */ 80: char *type_ufname; /* name of unpack function */ 81: union { 82: list u_list; /* enumeration, record, error */ 83: struct { 84: struct object *u_size, *u_basetype; 85: } u_array; /* array, sequence */ 86: struct { 87: struct object *u_designator; 88: list u_candidates; 89: } u_choice; /* choice */ 90: struct { 91: list u_args, u_results, u_errors; 92: } u_procedure; /* procedure */ 93: } type_u; 94: }; 95: /* 96: * These definitions allow access from an object pointer 97: * known to be a type. 98: */ 99: #define t_constr o_type->type_constr 100: #define t_pfname o_type->type_pfname 101: #define t_ufname o_type->type_ufname 102: #define t_list o_type->type_u.u_list 103: #define t_size o_type->type_u.u_array.u_size 104: #define t_basetype o_type->type_u.u_array.u_basetype 105: #define t_designator o_type->type_u.u_choice.u_designator 106: #define t_candidates o_type->type_u.u_choice.u_candidates 107: #define t_args o_type->type_u.u_procedure.u_args 108: #define t_results o_type->type_u.u_procedure.u_results 109: #define t_errors o_type->type_u.u_procedure.u_errors 110: 111: /* 112: * This macro is to cope with the fact that C passes arrays 113: * by reference but all other constructed types by value. 114: */ 115: #define refstr(t) (basetype(t)->t_constr == C_ARRAY ? "" : "&") 116: 117: /* 118: * Predefined types. 119: */ 120: extern struct object 121: *Boolean_type, 122: *Cardinal_type, *LongCardinal_type, 123: *Integer_type, *LongInteger_type, 124: *String_type, 125: *Unspecified_type, *LongUnspecified_type; 126: 127: extern struct object 128: *Undefined_constant; 129: 130: extern struct object *make(), *lookup(), *basetype(); 131: extern struct object *construct_type1(), *construct_type2(); 132: extern struct object *construct_choice(), *construct_procedure(); 133: extern list Values, Types; 134: extern list cons(), nconc(); 135: extern FILE *hf, *cf1, *cf2, *uf, *sf; 136: extern int explicit, print_level; 137: extern char *program_name; 138: extern char *copy(), *gensym(); 139: extern char *obj_rep(), *pack_function(), *unpack_function();