home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 January / macformat-020.iso / Shareware City / Developers / SIOD 3.0 / siod.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-01  |  7.0 KB  |  253 lines  |  [TEXT/ttxt]

  1. /* Scheme In One Defun, but in C this time.
  2.  
  3.  *                   COPYRIGHT (c) 1988-1994 BY                             *
  4.  *        PARADIGM ASSOCIATES INCORPORATED, CAMBRIDGE, MASSACHUSETTS.       *
  5.  *        See the source file SLIB.C for more information.                  *
  6.  
  7. */
  8.  
  9. struct obj
  10. {short gc_mark;
  11.  short type;
  12.  union {struct {struct obj * car;
  13.         struct obj * cdr;} cons;
  14.     struct {double data;} flonum;
  15.     struct {char *pname;
  16.         struct obj * vcell;} symbol;
  17.     struct {char *name;
  18.         struct obj * (*f)(void);} subr0;
  19.       struct {char *name;
  20.          struct obj * (*f)(struct obj *);} subr1;
  21.      struct {char *name;
  22.          struct obj * (*f)(struct obj *, struct obj *);} subr2;
  23.      struct {char *name;
  24.          struct obj * (*f)(struct obj *, struct obj *, struct obj *);
  25.            } subr3;
  26.      struct {char *name;
  27.          struct obj * (*f)(struct obj **, struct obj **);} subrm;
  28.     struct {char *name;
  29.         struct obj * (*f)(void *,...);} subr;
  30.     struct {struct obj *env;
  31.         struct obj *code;} closure;
  32.     struct {long dim;
  33.         long *data;} long_array;
  34.     struct {long dim;
  35.         double *data;} double_array;
  36.     struct {long dim;
  37.         char *data;} string;
  38.     struct {long dim;
  39.         struct obj **data;} lisp_array;
  40.     struct {FILE *f;
  41.         char *name;} c_file;}
  42.  storage_as;};
  43.  
  44. #define CAR(x) ((*x).storage_as.cons.car)
  45. #define CDR(x) ((*x).storage_as.cons.cdr)
  46. #define PNAME(x) ((*x).storage_as.symbol.pname)
  47. #define VCELL(x) ((*x).storage_as.symbol.vcell)
  48. #define SUBR0(x) (*((*x).storage_as.subr0.f))
  49. #define SUBR1(x) (*((*x).storage_as.subr1.f))
  50. #define SUBR2(x) (*((*x).storage_as.subr2.f))
  51. #define SUBR3(x) (*((*x).storage_as.subr3.f))
  52. #define SUBRM(x) (*((*x).storage_as.subrm.f))
  53. #define SUBRF(x) (*((*x).storage_as.subr.f))
  54. #define FLONM(x) ((*x).storage_as.flonum.data)
  55.  
  56. #define NIL ((struct obj *) 0)
  57. #define EQ(x,y) ((x) == (y))
  58. #define NEQ(x,y) ((x) != (y))
  59. #define NULLP(x) EQ(x,NIL)
  60. #define NNULLP(x) NEQ(x,NIL)
  61.  
  62. #define TYPE(x) (((x) == NIL) ? 0 : ((*(x)).type))
  63.  
  64. #define TYPEP(x,y) (TYPE(x) == (y))
  65. #define NTYPEP(x,y) (TYPE(x) != (y))
  66.  
  67. #define tc_nil    0
  68. #define tc_cons   1
  69. #define tc_flonum 2
  70. #define tc_symbol 3
  71. #define tc_subr_0 4
  72. #define tc_subr_1 5
  73. #define tc_subr_2 6
  74. #define tc_subr_3 7
  75. #define tc_lsubr  8
  76. #define tc_fsubr  9
  77. #define tc_msubr  10
  78. #define tc_closure 11
  79. #define tc_free_cell 12
  80. #define tc_string       13
  81. #define tc_double_array 14
  82. #define tc_long_array   15
  83. #define tc_lisp_array   16
  84. #define tc_c_file       17
  85. #define tc_user_1 50
  86. #define tc_user_2 51
  87. #define tc_user_3 52
  88. #define tc_user_4 53
  89. #define tc_user_5 54
  90.  
  91. #define tc_sys_1 91
  92. #define tc_sys_2 92
  93. #define tc_sys_3 93
  94. #define tc_sys_4 94
  95. #define tc_sys_5 95
  96.  
  97.  
  98. #define FO_fetch 127
  99. #define FO_store 126
  100. #define FO_list  125
  101. #define FO_listd 124
  102.  
  103. #define tc_table_dim 100
  104.  
  105. typedef struct obj* LISP;
  106. typedef LISP (*SUBR_FUNC)(void); 
  107.  
  108. #define CONSP(x)   TYPEP(x,tc_cons)
  109. #define FLONUMP(x) TYPEP(x,tc_flonum)
  110. #define SYMBOLP(x) TYPEP(x,tc_symbol)
  111.  
  112. #define NCONSP(x)   NTYPEP(x,tc_cons)
  113. #define NFLONUMP(x) NTYPEP(x,tc_flonum)
  114. #define NSYMBOLP(x) NTYPEP(x,tc_symbol)
  115.  
  116. #define TKBUFFERN 256
  117.  
  118. struct gen_readio
  119. {int (*getc_fcn)(char *);
  120.  void (*ungetc_fcn)(int, char *);
  121.  char *cb_argument;};
  122.  
  123. #define GETC_FCN(x) (*((*x).getc_fcn))((*x).cb_argument)
  124. #define UNGETC_FCN(c,x) (*((*x).ungetc_fcn))(c,(*x).cb_argument)
  125.  
  126. struct repl_hooks
  127. {void (*repl_puts)(char *);
  128.  LISP (*repl_read)(void);
  129.  LISP (*repl_eval)(LISP);
  130.  void (*repl_print)(LISP);};
  131.  
  132. void process_cla(int argc,char **argv,int warnflag);
  133. void print_welcome(void);
  134. void print_hs_1(void);
  135. void print_hs_2(void);
  136. long no_interrupt(long n);
  137. LISP get_eof_val(void);
  138. long repl_driver(long want_sigint,long want_init,struct repl_hooks *);
  139. void set_repl_hooks(void (*puts_f)(char *),
  140.             LISP (*read_f)(void),
  141.             LISP (*eval_f)(LISP),
  142.             void (*print_f)(LISP));
  143. long repl(struct repl_hooks *);
  144. LISP err(char *message, LISP x);
  145. LISP errswitch(void);
  146. char *get_c_string(LISP x);
  147. long get_c_long(LISP x);
  148. LISP lerr(LISP message, LISP x);
  149.  
  150. LISP newcell(long type);
  151. LISP cons(LISP x,LISP y);
  152. LISP consp(LISP x);
  153. LISP car(LISP x);
  154. LISP cdr(LISP x);
  155. LISP setcar(LISP cell, LISP value);
  156. LISP setcdr(LISP cell, LISP value);
  157. LISP flocons(double x);
  158. LISP numberp(LISP x);
  159. LISP plus(LISP x,LISP y);
  160. LISP ltimes(LISP x,LISP y);
  161. LISP difference(LISP x,LISP y);
  162. LISP quotient(LISP x,LISP y);
  163. LISP greaterp(LISP x,LISP y);
  164. LISP lessp(LISP x,LISP y);
  165. LISP eq(LISP x,LISP y);
  166. LISP eql(LISP x,LISP y);
  167. LISP symcons(char *pname,LISP vcell);
  168. LISP symbolp(LISP x);
  169. LISP symbol_boundp(LISP x,LISP env);
  170. LISP symbol_value(LISP x,LISP env);
  171. LISP cintern(char *name);
  172. LISP rintern(char *name);
  173. LISP subrcons(long type, char *name, SUBR_FUNC f);
  174. LISP closure(LISP env,LISP code);
  175. void gc_protect(LISP *location);
  176. void gc_protect_n(LISP *location,long n);
  177. void gc_protect_sym(LISP *location,char *st);
  178.  
  179. void init_storage(void);
  180.  
  181. void init_subr(char *name, long type, SUBR_FUNC fcn);
  182. void init_subr_0(char *name, LISP (*fcn)(void));
  183. void init_subr_1(char *name, LISP (*fcn)(LISP));
  184. void init_subr_2(char *name, LISP (*fcn)(LISP,LISP));
  185. void init_subr_3(char *name, LISP (*fcn)(LISP,LISP,LISP));
  186. void init_lsubr(char *name, LISP (*fcn)(LISP));
  187. void init_fsubr(char *name, LISP (*fcn)(LISP,LISP));
  188. void init_msubr(char *name, LISP (*fcn)(LISP *,LISP *));
  189.  
  190. LISP assq(LISP x,LISP alist);
  191. LISP delq(LISP elem,LISP l);
  192. void set_gc_hooks(long type,
  193.           LISP (*rel)(LISP),
  194.           LISP (*mark)(LISP),
  195.           void (*scan)(LISP),
  196.           void (*free)(LISP),
  197.           long *kind);
  198. LISP gc_relocate(LISP x);
  199. LISP user_gc(LISP args);
  200. LISP gc_status(LISP args);
  201. void set_eval_hooks(long type,LISP (*fcn)(LISP, LISP *, LISP *));
  202. LISP leval(LISP x,LISP env);
  203. LISP symbolconc(LISP args);
  204. void set_print_hooks(long type,void (*fcn)(LISP, FILE *));
  205. LISP lprin1f(LISP exp,FILE *f);
  206. LISP lprint(LISP exp);
  207. LISP lread(void);
  208. LISP lreadtk(long j);
  209. LISP lreadf(FILE *f);
  210. void set_read_hooks(char *all_set,char *end_set,
  211.             LISP (*fcn1)(int, struct gen_readio *),
  212.             LISP (*fcn2)(char *,long, int *));
  213. LISP apropos(LISP);
  214. LISP vload(char *fname,long cflag);
  215. LISP load(LISP fname,LISP cflag);
  216. LISP save_forms(LISP fname,LISP forms,LISP how);
  217. LISP quit(void);
  218. LISP nullp(LISP x);
  219. LISP strcons(long length,char *data);
  220. LISP read_from_string(LISP x);
  221. LISP aref1(LISP a,LISP i);
  222. LISP aset1(LISP a,LISP i,LISP v);
  223. LISP cons_array(LISP dim,LISP kind);
  224. LISP string_append(LISP args);
  225. LISP string_length(LISP string);
  226. LISP string_search(LISP,LISP);
  227. LISP substring(LISP,LISP,LISP);
  228. LISP string_trim(LISP);
  229. LISP string_trim_left(LISP);
  230. LISP string_trim_right(LISP);
  231. LISP string_upcase(LISP);
  232. LISP string_downcase(LISP);
  233. void init_subrs(void);
  234. LISP copy_list(LISP);
  235. long c_sxhash(LISP,long);
  236. LISP sxhash(LISP,LISP);
  237. LISP href(LISP,LISP);
  238. LISP hset(LISP,LISP,LISP);
  239. LISP fast_print(LISP,LISP);
  240. LISP fast_read(LISP);
  241. LISP equal(LISP,LISP);
  242. LISP assoc(LISP x,LISP alist);
  243. LISP make_list(LISP x,LISP v);
  244. void set_fatal_exit_hook(void (*fcn)(void));
  245. LISP parse_number(LISP x);
  246. LISP intern(LISP x);
  247. void init_trace(void);
  248. long repl_c_string(char *,long want_sigint,long want_init,long want_print);
  249. char *siod_version(void);
  250. LISP nreverse(LISP);
  251. LISP number2string(LISP,LISP);
  252. LISP string2number(LISP,LISP);
  253.