ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/microscheme/scheme.h
Revision: 1.6
Committed: Fri Nov 27 02:06:36 2015 UTC (8 years, 6 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.5: +7 -10 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.5 /*
2     * µscheme
3     *
4     * Copyright (C) 2015 Marc Alexander Lehmann <uscheme@schmorp.de>
5     * do as you want with this, attribution appreciated.
6     */
7 root 1.1
8     /* SCHEME.H */
9    
10     #ifndef SCHEME_H
11 root 1.2 #define SCHEME_H
12 root 1.1
13 root 1.3 #include <inttypes.h>
14 root 1.2 #include <stdio.h>
15 root 1.1
16 root 1.2 #ifdef __cplusplus
17 root 1.1 extern "C"
18     {
19 root 1.2 #endif
20 root 1.1
21     /*
22     * Default values for #define'd symbols
23     */
24 root 1.2 #ifndef STANDALONE /* If used as standalone interpreter */
25     # define STANDALONE 1
26     #endif
27    
28     #define SCHEME_EXPORT static
29    
30     #if USE_NO_FEATURES
31     # define USE_MULTIPLICITY 0
32     # define USE_MATH 0
33     # define USE_CHAR_CLASSIFIERS 0
34     # define USE_ASCII_NAMES 0
35     # define USE_PORTS 1
36     # define USE_STRING_PORTS 0
37     # define USE_ERROR_HOOK 0
38     # define USE_TRACING 0
39     # define USE_COLON_HOOK 0
40     # define USE_DL 0
41     # define USE_PLIST 0
42 root 1.5 # define USE_REAL 0
43 root 1.2 # define USE_ERROR_CHECKING 0
44     # define USE_PRINTF 0
45     #endif
46 root 1.1
47     /*
48 root 1.4 * Define: much slower, but somewhat smaller evaluation stack implemention, use more memory
49     * Undefined: faster, somewhat bigger implementation, uses less memory at runtime
50 root 1.1 */
51 root 1.4 /*#define USE_SCHEME_STACK*/
52 root 1.2
53     #ifndef USE_MULTIPLICITY
54     # define USE_MULTIPLICITY 1
55     #endif
56    
57 root 1.5 #ifndef USE_REAL
58     # define USE_REAL 1
59 root 1.2 #endif
60 root 1.1
61 root 1.2 #ifndef USE_MATH /* If math support is needed */
62     # define USE_MATH 1
63     #endif
64    
65     #ifndef USE_CHAR_CLASSIFIERS /* If char classifiers are needed */
66     # define USE_CHAR_CLASSIFIERS 1
67     #endif
68    
69     #ifndef USE_ASCII_NAMES /* If extended escaped characters are needed */
70     # define USE_ASCII_NAMES 1
71     #endif
72    
73     #ifndef USE_PORTS /* Enable ports */
74     # define USE_PORTS 1
75     #endif
76    
77     #ifndef USE_STRING_PORTS /* Enable string ports */
78     # define USE_STRING_PORTS USE_PORTS
79     #endif
80    
81     #ifndef USE_TRACING
82     # define USE_TRACING 1
83     #endif
84    
85     #ifndef USE_PLIST
86     # define USE_PLIST 0
87     #endif
88 root 1.1
89     /* To force system errors through user-defined error handling (see *error-hook*) */
90 root 1.2 #ifndef USE_ERROR_HOOK
91     # define USE_ERROR_HOOK 1
92     #endif
93    
94     #ifndef USE_COLON_HOOK /* Enable qualified qualifier */
95     # define USE_COLON_HOOK 1
96     #endif
97    
98     #ifndef USE_ERROR_CHECKING
99     # define USE_ERROR_CHECKING 1
100     #endif
101    
102     #ifndef USE_PRINTF
103     # define USE_PRINTF 1
104     #endif
105    
106 root 1.6 #ifndef USE_IGNORECASE
107     # define USE_IGNORECASE 1
108 root 1.2 #endif
109    
110 root 1.6 #ifndef SHOW_ERROR_LINE /* Show error line in file */
111     # define SHOW_ERROR_LINE 1
112 root 1.2 #endif
113    
114 root 1.6 #if !USE_REAL
115     # undef USE_MATH
116     # define USE_MATH 0
117 root 1.2 #endif
118    
119     #if USE_MULTIPLICITY
120     # define SCHEME_V sc
121     # define SCHEME_P scheme *SCHEME_V
122     # define SCHEME_P_ SCHEME_P,
123     # define SCHEME_A SCHEME_V
124     # define SCHEME_A_ SCHEME_A,
125     #else
126     # define SCHEME_V (&sc)
127     # define SCHEME_P
128     # define SCHEME_P_
129     # define SCHEME_A
130     # define SCHEME_A_
131     #endif
132 root 1.1
133 root 1.5 typedef struct scheme scheme;
134     typedef struct cell *pointer;
135 root 1.1
136 root 1.5 typedef void *(*func_alloc) (size_t);
137     typedef void (*func_dealloc) (void *);
138 root 1.1
139 root 1.5 typedef long IVALUE; /* this is not used consistently yet */
140 root 1.1
141 root 1.5 #if USE_REAL
142     typedef double RVALUE;
143 root 1.2 # define num_is_fixnum(n) (n).is_fixnum
144     # define num_set_fixnum(n,f) (n).is_fixnum = (f)
145     # define num_ivalue(n) (n).value.ivalue
146     # define num_rvalue(n) (n).value.rvalue
147     # define num_set_ivalue(n,i) (n).value.ivalue = (i)
148     # define num_set_rvalue(n,r) (n).value.rvalue = (r)
149     #else
150 root 1.5 typedef long RVALUE;
151 root 1.2 # define num_is_fixnum(n) 1
152     # define num_set_fixnum(n,f) 0
153     # define num_ivalue(n) (n).value.ivalue
154     # define num_rvalue(n) (n).value.ivalue
155     # define num_set_ivalue(n,i) (n).value.ivalue = (i)
156     # define num_set_rvalue(n,r) (n).value.ivalue = (r)
157     #endif
158 root 1.1
159     /* num, for generic arithmetic */
160 root 1.5 typedef struct num
161     {
162     union
163 root 1.1 {
164 root 1.5 IVALUE ivalue;
165     #if USE_REAL
166     RVALUE rvalue;
167     #endif
168     } value;
169     #if USE_REAL
170     char is_fixnum;
171 root 1.2 #endif
172 root 1.5 } num;
173 root 1.1
174     /* Used for documentation purposes, to signal functions in 'interface' */
175 root 1.2 #define INTERFACE static
176 root 1.1
177 root 1.5 SCHEME_EXPORT scheme *scheme_init_new ();
178     SCHEME_EXPORT int scheme_init (SCHEME_P);
179     SCHEME_EXPORT void scheme_deinit (SCHEME_P);
180     void scheme_set_input_port_file (SCHEME_P_ int fin);
181     void scheme_set_input_port_string (SCHEME_P_ char *start, char *past_the_end);
182     SCHEME_EXPORT void scheme_set_output_port_file (SCHEME_P_ int fin);
183     void scheme_set_output_port_string (SCHEME_P_ char *start, char *past_the_end);
184     SCHEME_EXPORT void scheme_load_file (SCHEME_P_ int fin);
185     SCHEME_EXPORT void scheme_load_named_file (SCHEME_P_ int fin, const char *filename);
186     SCHEME_EXPORT void scheme_load_string (SCHEME_P_ const char *cmd);
187     SCHEME_EXPORT pointer scheme_apply0 (SCHEME_P_ const char *procname);
188     SCHEME_EXPORT pointer scheme_call (SCHEME_P_ pointer func, pointer args);
189     SCHEME_EXPORT pointer scheme_eval (SCHEME_P_ pointer obj);
190     void scheme_set_external_data (SCHEME_P_ void *p);
191     SCHEME_EXPORT void scheme_define (SCHEME_P_ pointer env, pointer symbol, pointer value);
192    
193     typedef pointer (*foreign_func) (SCHEME_P_ pointer);
194    
195     pointer xcons (SCHEME_P_ pointer a, pointer b, int immutable);
196     INTERFACE pointer mk_integer (SCHEME_P_ long num);
197     INTERFACE pointer mk_real (SCHEME_P_ RVALUE num);
198     INTERFACE pointer mk_symbol (SCHEME_P_ const char *name);
199     INTERFACE pointer gensym (SCHEME_P);
200     INTERFACE pointer mk_string (SCHEME_P_ const char *str);
201     INTERFACE pointer mk_counted_string (SCHEME_P_ const char *str, uint32_t len);
202     INTERFACE pointer mk_empty_string (SCHEME_P_ uint32_t len, char fill);
203     INTERFACE pointer mk_character (SCHEME_P_ int c);
204     INTERFACE pointer mk_foreign_func (SCHEME_P_ foreign_func f);
205     INTERFACE void putstr (SCHEME_P_ const char *s);
206     INTERFACE int list_length (SCHEME_P_ pointer a);
207     INTERFACE int eqv (pointer a, pointer b);
208 root 1.1
209 root 1.2 #if !STANDALONE
210 root 1.5 typedef struct scheme_registerable
211     {
212     foreign_func f;
213     const char *name;
214     } scheme_registerable;
215 root 1.1
216 root 1.5 void scheme_register_foreign_func_list (SCHEME_P_ scheme_registerable * list, int n);
217 root 1.2 #endif /* !STANDALONE */
218 root 1.1
219 root 1.2 #ifdef __cplusplus
220 root 1.1 }
221 root 1.2 #endif
222 root 1.1
223     #endif
224    
225     /*
226     Local variables:
227     c-file-style: "k&r"
228     End:
229     */