1 /*
2  * SketchyLISP -- An interpreter for purely applicative Scheme
3  * Copyright (C) 2005,2006,2007 Nils M Holm <nmh@t3x.org>
4  * See http://www.t3x.org/sketchy/license.html for conditions of use.
5  */
6 
7 #ifdef __SKETCHYLIB__
8  #define extern
9 #endif
10 
11 #define SK_MAJOR	31
12 #define SK_RELEASE	"2007-02-18"
13 
14 /*
15  * Number of nodes and vector cells.
16  * Memory = Nodes * (2 * sizeof(int) + 1)
17  *          + Vcells * sizeof(int)
18  * (Recommended: 16-bit: 12280, >=32-bit: 131072)
19  */
20 #ifdef SMALL
21 #define	SK_DFL_NODES	12280
22 #else
23 #define	SK_DFL_NODES	131072
24 #endif
25 
26 #define SK_DFL_VCELLS	SK_DFL_NODES
27 
28 /*
29  * Neither the node pool nor the vector pool
30  * should be smaller than this.
31  */
32 #define SK_MIN_SIZE	12280
33 
34 /* Maximum length for symbols */
35 #ifdef SMALL
36 #define	SK_TEXTLEN	128
37 #else
38 #define	SK_TEXTLEN	1024
39 #endif
40 
41 /* Max. path length */
42 #define SK_MAXPATHL	256
43 
44 /* Default image */
45 #ifndef SK_DFL_IMAGE
46  #define SK_DFL_IMAGE	"/usr/local/share/sketchy/sketchy.image"
47 #endif
48 
49 /* For errors without specific source. */
50 #define SK_NOEXPR	-1
51 
52 /* End of input indicator */
53 #define SK_EOT		-1
54 
55 /* Maximum number of user-addd primitives */
56 #define SK_MAX_USER_PRIMITIVES	128
57 
58 enum {
59 	SK_TYPE_BOOLEAN,
60 	SK_TYPE_CHAR,
61 	SK_TYPE_EOF,
62 	SK_TYPE_INTEGER,
63 	SK_TYPE_PAIR,
64 	SK_TYPE_PROCEDURE,
65 	SK_TYPE_STRING,
66 	SK_TYPE_SYMBOL,
67 	SK_TYPE_SYNTAX,
68 	SK_TYPE_UNDEFINED,
69 	SK_TYPE_VOID
70 };
71 
72 /* Counter structure used for statistics. */
73 struct sk_counter {
74 	int	n,	/* ones */
75 		n1k,	/* thousands */
76 		n1m,	/* millions */
77 		n1g;	/* billions */
78 };
79 
80 /* Structure for GC statistics. */
81 struct sk_gcStats {
82 	int	nodes_used,
83 		vcells_used,
84 		nodes_max,
85 		vcells_max;
86 };
87 
88 /* Shared variables. */
89 extern int	SK_errFlag;	/* Error flag */
90 extern int	SK_statFlag;	/* Statistics flag */
91 extern int	SK_strictApply;	/* Strict (R5RS) apply flag */
92 extern int	SK_closureForm;	/* Ext. rep. of closures (0,1,2) */
93 extern int	SK_arrowMode;	/* Enable arrow comments */
94 extern int	SK_metaChar;	/* Meta command character */
95 extern int	SK_trace;	/* Function being traced */
96 extern char	*SK_errMsg;	/* Most recent error message */
97 extern char	SK_errArg[SK_TEXTLEN];	/* Additional information */
98 extern int	SK_errExpr;	/* Expression causing last error */
99 extern char	SK_errFile[SK_MAXPATHL];	/* File of last error */
100 extern int	SK_errLine;	/* Line number of last error */
101 extern int	SK_errFun;	/* Function of last error */
102 extern int	SK_errFrame;	/* Call frame of last error */
103 extern struct sk_counter
104 		SK_reductions,	/* Reduction counter */
105 		SK_allocations,	/* Allocation counter */
106 		SK_collections;	/* Garbage collection counter */
107 
108 /* Trace Handler; NULL = print trace */
109 extern int (*SK_traceHandler)(int n);
110 
111 /*
112  * Function prototypes
113  */
114 int	sk_addUserPrim(char *name, int (*handler)(int n));
115 int	sk_args(int n);
116 void	sk_bye(void);
117 int	sk_car(int n);
118 int	sk_cdr(int n);
119 int	sk_char(int n);
120 int	sk_cons(int car, int cdr);
121 void	sk_count(struct sk_counter *c, int k);
122 void	sk_display(int n);
123 void	sk_dumpImage(char *p);
124 void	sk_dumpSymbols(char *p);
125 int	sk_eof(void);
126 int	sk_error(char *msg, int n);
127 int	sk_eval(int n);
128 const int	sk_false(void);
129 char	*sk_findSource(char *p, char *buf);
130 int	sk_findSym(char *s);
131 void	sk_fini(void);
132 void	sk_gc(struct sk_gcStats *stats);
133 void	sk_gotError(void);
134 int	sk_init(int nodes, int vcells);
135 long	sk_int(int n, int *ep);
136 char	**sk_license(void);
137 int	sk_listToVector(int n);
138 int	sk_load(char *p);
139 int	sk_loadImage(char *p);
140 int	sk_mkChar(int c);
141 int	sk_mkInteger(long v);
142 int	sk_mkString(char *s, int k);
143 const int	sk_nil(void);
144 void	sk_nl(void);
145 int	sk_nthArg(int n, int i);
146 void	sk_pr(char *s);
147 void	sk_print(int n);
148 void	sk_printCallTrace(int n);
149 void	sk_printCounter(struct sk_counter *c);
150 void	sk_printError(void);
151 void	sk_printStats(void);
152 void	sk_prnum(int n, int w);
153 void	sk_protect(int n);
154 int	sk_rdch(void);
155 int	sk_read(void);
156 int	sk_readFromString(char *s);
157 void	sk_reject(int c);
158 int	sk_require(char *p);
159 void	sk_resetCounter(struct sk_counter *c);
160 void	sk_setCar(int n, int new);
161 void	sk_setCdr(int n, int new);
162 void	sk_stop(void);
163 const char	*sk_string(int n);
164 const int	sk_true(void);
165 int	sk_typeof(int n);
166 const int	sk_undefined(void);
167 void	sk_unprotect(int k);
168 const int	*sk_vector(int n);
169 int	sk_vector_len(int n);
170 const int	sk_void(void);
171 int	sk_writeToString(int n);
172