1 /* newlisp.h - header file for newLISP
3 Copyright (C) 2008 Lutz Mueller
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 starting with version 9.1.9 MINGW is the default flavor for WIN_32
22 and the MINGW label as been eliminated
26 #define strtoll strtol
27 #define strtoull strtoul
30 #if defined(SOLARIS) || defined(TRU64)
31 #define MY_RAND_MAX 2147483647
33 #define MY_RAND_MAX RAND_MAX
37 This is for 64bit large file support (LFS),
42 #define _LARGEFILE64_SOURCE 1
44 #define _FILE_OFFSET_BITS 64
57 /* some Linux do UTF-8 but do not have wcsftime()
58 buggy in some GCC, i.e. MinGW and Solaris
89 #include <sys/timeb.h>
90 #include <sys/types.h>
103 #define vasprintf my_vasprintf
108 #define vasprintf my_vasprintf
113 #define vasprintf my_vasprintf
114 #define setenv my_setenv
117 #define MY_RAND_MAX 2147483647
121 #define LITTLE_ENDIAN
124 #define LINE_FEED "\r\n"
125 #define isSocketStream(A) ((A)->_flag == 0xFFFF)
126 #define getSocket(A) ((A)->_file)
127 #define vasprintf my_vasprintf
128 #define setenv my_setenv
130 #define srandom srand
131 #define ioctl ioctlsocket
132 #define off_t off64_t
133 #define lseek lseek64
134 #define ftell ftello64
142 #define realpath win32_realpath
144 /* WIN_32 UTF16 support for file paths */
146 #define USE_WIN_UTF16PATH
147 #define rename rename_utf16
148 #define open open_utf16
149 #define mkdir mkdir_utf16
150 #define rmdir rmdir_utf16
151 #define unlink unlink_utf16
152 #define chdir chdir_utf16
153 #define opendir opendir_utf16
157 #define dirent _wdirent
158 #define readdir _wreaddir
159 #define closedir _wclosedir
160 #endif /* SUPPORT_UTF8 */
166 #define LINE_FEED "\n"
175 #define UTF8_MAX_BYTES 6
177 #define UINT unsigned long
179 #define INT16 short int
181 #define MAX_LONG 0x7FFFFFFF
183 #define MAX_LONG 0x7FFFFFFFFFFFFFFFLL
189 #define UINT64 unsigned long
191 #define INT64 long long int
192 #define UINT64 unsigned long long int
196 #define UINT64 unsigned long
199 #define pushEnvironment(A) (*(envStack + envStackIdx++) = (UINT)(A))
200 #define popEnvironment() (*(envStack + --envStackIdx))
202 #define pushResult(A) (*(resultStack + resultStackIdx++) = (UINT)(A))
203 #define popResult() ((CELL *)*(resultStack + --resultStackIdx))
205 #define freeMemory free
207 #define INT32_MIN_AS_INT64 (((long long int)0xFFFFFFFF << 32) | 0x80000000)
208 #define MY_INT64_MAX (((long long int)0x7FFFFFFF << 32) | 0xFFFFFFFF)
212 #define MAX_STRING 2048
214 #define MAX_SYMBOL 255
216 #define MAX_READ_LEN 0x4000
217 #define MAX_PRINT_LEN 0x4000
218 #define MAX_LOAD_BUFFER 0x4000
219 #define MAX_FILE_BUFFER 0x4000
220 #define MAX_BLOCK 1023
221 #define MAX_URL_LEN 256
223 #define MAX_REGEX_EXP 16
228 #define TKN_CHARACTER 1
231 #define TKN_DECIMAL 4
235 #define TKN_CONTEXT 8
236 #define TKN_LEFT_PAR '('
237 #define TKN_RIGHT_PAR ')'
238 #define TKN_QUOTE '\''
240 /* symbol flags types and masks */
241 #define PRINT_TYPE_MASK 0x0F
242 #define SYMBOL_PROTECTED 0x10
243 #define SYMBOL_GLOBAL 0x20
244 #define SYMBOL_BUILTIN 0x40
245 #define SYMBOL_PRIMITIVE 0x80
248 #define RAW_TYPE_MASK 0x0FFF
249 #define COMPARE_TYPE_MASK 0x000F
250 #define ENVELOPE_TYPE_MASK 0x0010
251 #define LIST_TYPE_MASK 0x0020
252 #define SYMBOL_TYPE_MASK 0x0040
253 #define NUMBER_TYPE_MASK 0x0080
254 #define EVAL_SELF_TYPE_MASK 0x0100
255 #define INT64_MASK 0x0200
258 #define CELL_NIL (0 | EVAL_SELF_TYPE_MASK)
259 #define CELL_TRUE (1 | EVAL_SELF_TYPE_MASK)
260 #define CELL_INT 2 /* any INT */
261 #define CELL_LONG (2 | EVAL_SELF_TYPE_MASK | NUMBER_TYPE_MASK)
262 #define CELL_INT64 (2 | EVAL_SELF_TYPE_MASK | NUMBER_TYPE_MASK | INT64_MASK)
263 #define CELL_FLOAT (3 | EVAL_SELF_TYPE_MASK | NUMBER_TYPE_MASK)
264 #define CELL_STRING (4 | EVAL_SELF_TYPE_MASK)
265 #define CELL_SYMBOL (5 | SYMBOL_TYPE_MASK)
266 #define CELL_CONTEXT 6
267 #define CELL_PRIMITIVE (7 | EVAL_SELF_TYPE_MASK)
268 #define CELL_IMPORT_CDECL (8 | EVAL_SELF_TYPE_MASK)
269 #define CELL_IMPORT_DLL (9 | EVAL_SELF_TYPE_MASK)
270 #define CELL_QUOTE (10 | ENVELOPE_TYPE_MASK)
271 #define CELL_EXPRESSION (11 | ENVELOPE_TYPE_MASK | LIST_TYPE_MASK)
272 #define CELL_LAMBDA (12 | ENVELOPE_TYPE_MASK | LIST_TYPE_MASK | EVAL_SELF_TYPE_MASK)
273 #define CELL_MACRO (13 | ENVELOPE_TYPE_MASK | LIST_TYPE_MASK | EVAL_SELF_TYPE_MASK)
274 #define CELL_ARRAY (14 | ENVELOPE_TYPE_MASK | EVAL_SELF_TYPE_MASK)
275 #define CELL_DYN_SYMBOL (15 | SYMBOL_TYPE_MASK)
276 #define CELL_FREE 0xFF
278 #define isEnvelope(A) ((A) & ENVELOPE_TYPE_MASK)
279 #define isList(A) ((A) & LIST_TYPE_MASK)
280 #define isArray(A) ((A) == CELL_ARRAY)
281 #define isString(A) ((A) == CELL_STRING)
282 #define isNumber(A) ((A) & NUMBER_TYPE_MASK)
283 #define isSymbol(A) ((A) & SYMBOL_TYPE_MASK)
284 #define isSelfEval(A) ((A) & EVAL_SELF_TYPE_MASK)
285 #define isProtected(A) ((A) & SYMBOL_PROTECTED)
286 #define isGlobal(A) ((A) & SYMBOL_GLOBAL)
287 #define isDigit(A) isdigit((int)(A))
289 #define isNil(A) ((A)->type == CELL_NIL || ((A)->type == CELL_SYMBOL && (A)->contents == (UINT)nilSymbol))
290 #define isTrue(A) ((A)->type == CELL_TRUE || ((A)->type == CELL_SYMBOL && (A)->contents == (UINT)trueSymbol))
291 #define isEmpty(A) ((A)->type == CELL_EXPRESSION && (A)->contents == (UINT)nilCell)
293 #define symbolType(A) ((CELL*)(A)->contents)->type
295 /* redefine some functions */
297 #define stuffInteger64 stuffInteger
301 /* RED BLACK binary balanced tree: nl-symbol.c */
304 #define NIL_SYM &sentinel
305 #define LOOKUP_ONLY 0 /* symbol lookup only, if not found return NULL */
306 #define FORCE_CREATION 1 /* if symbol does not exist, create it */
310 #define TRACE_TRUE 0x0001
311 #define TRACE_IN_ENTRY 0x0002
312 #define TRACE_IN_EXIT 0x0004
313 #define TRACE_IN_DEBUG 0x0008
314 #define TRACE_DEBUG_PENDING 0x0010
315 #define TRACE_DEBUG_EVAL 0x0020
316 #define TRACE_DEBUG_STEP 0x0040
317 #define TRACE_DEBUG_NEXT 0x0080
318 #define TRACE_SIGINT 0x1000
319 #define TRACE_TIMER 0x2000
320 #define TRACE_SIGNAL 0x4000
324 #define ERR_NOT_ENOUGH_MEMORY 1
325 #define ERR_OUT_OF_ENV_STACK 2
326 #define ERR_OUT_OF_CALL_STACK 3
327 #define ERR_ACCESSING_FILE 4
328 #define ERR_EXPRESSION 5
329 #define ERR_MISSING_PAR 6
330 #define ERR_STRING_TOO_LONG 7
331 #define ERR_MISSING_ARGUMENT 8
332 #define ERR_NUMBER_OR_STRING_EXPECTED 9
333 #define ERR_NUMBER_EXPECTED 10
334 #define ERR_STRING_EXPECTED 11
335 #define ERR_SYMBOL_EXPECTED 12
336 #define ERR_CONTEXT_EXPECTED 13
337 #define ERR_SYMBOL_OR_CONTEXT_EXPECTED 14
338 #define ERR_LIST_EXPECTED 15
339 #define ERR_LIST_OR_ARRAY_EXPECTED 16
340 #define ERR_LIST_OR_SYMBOL_EXPECTED 17
341 #define ERR_LIST_OR_STRING_EXPECTED 18
342 #define ERR_LIST_OR_NUMBER_EXPECTED 19
343 #define ERR_ARRAY_EXPECTED 20
344 #define ERR_ARRAY_LIST_OR_STRING_EXPECTED 21
345 #define ERR_LAMBDA_EXPECTED 22
346 #define ERR_MACRO_EXPECTED 23
347 #define ERR_INVALID_FUNCTION 24
348 #define ERR_INVALID_LAMBDA 25
349 #define ERR_INVALID_MACRO 26
350 #define ERR_INVALID_LET 27
351 #define ERR_SAVING_FILE 28
353 #define ERR_NOT_MATRIX 30
354 #define ERR_WRONG_DIMENSIONS 31
355 #define ERR_SINGULAR 32
356 #define ERR_REGULAR_EXPRESSION 33
357 #define ERR_THROW_WO_CATCH 34
358 #define ERR_IMPORT_LIB_NOT_FOUND 35
359 #define ERR_IMPORT_FUNC_NOT_FOUND 36
360 #define ERR_SYMBOL_PROTECTED 37
361 #define ERR_NUMBER_OUT_OF_RANGE 38
363 #define ERR_MISSING_TEXT_END 40
364 #define ERR_FORMAT_NUM_ARGS 41
365 #define ERR_FORMAT_STRING 42
366 #define ERR_FORMAT_DATA_TYPE 43
367 #define ERR_INVALID_PARAMETER 44
368 #define ERR_INVALID_PARAMETER_0 45
369 #define ERR_INVALID_PARAMETER_NAN 46
370 #define ERR_ILLEGAL_TYPE 47
371 #define ERR_NOT_IN_MAIN 48
372 #define ERR_NOT_CURRENT_CONTEXT 49
373 #define ERR_TARGET_NO_MAIN 50
374 #define ERR_LIST_INDEX_OUTOF_BOUNDS 51
375 #define ERR_ARRAY_INDEX_OUTOF_BOUNDS 52
376 #define ERR_STRING_INDEX_OUTOF_BOUNDS 53
377 #define ERR_NESTING_TOO_DEEP 54
378 #define ERR_SYNTAX_WRONG 55
379 #define ERR_USER_ERROR 56
380 #define ERR_USER_RESET 57
381 #define ERR_SIGINT 58
382 #define ERR_NOT_REENTRANT 59
383 #define MAX_ERROR_NUMBER 59
389 #define OUT_CONSOLE 2
392 /* HTTP in nl-web.c */
393 #define HTTP_GET_URL 0
394 #define HTTP_GET_HEAD 1
395 #define HTTP_PUT_URL 2
396 #define HTTP_PUT_APPEND_URL 3
397 #define HTTP_POST_URL 4
398 #define HTTP_DELETE_URL 5
400 /* additional regex option */
401 #define REPLACE_ONCE 0x8000
403 extern int vasprintf (char **, const char *, va_list);
405 /* ---------------------------- standard types ------------------------- */
416 typedef struct tagSYMBOL
422 struct tagSYMBOL
* context
;
423 struct tagSYMBOL
* parent
;
424 struct tagSYMBOL
* left
;
425 struct tagSYMBOL
* right
;
439 CELL
* (*function
)(CELL
*);
440 short int prettyPrint
;
443 /* --------------------------- globals -------------------------------- */
445 extern char startupDir
[];
446 extern FILE * IOchannel
;
447 extern int MAX_CPU_STACK
;
448 extern long MAX_CELL_COUNT
;
451 extern char ostype
[];
452 extern size_t cellCount
;
453 extern size_t symbolCount
;
454 extern int recursionCount
;
455 extern UINT printDevice
;
456 extern UINT
* resultStack
;
457 extern UINT
* envStack
;
458 extern int resultStackIdx
;
459 extern int envStackIdx
;
460 extern CELL
* trueCell
;
461 extern CELL
* nilCell
;
462 extern STREAM strStream
;
463 extern SYMBOL
* nilSymbol
;
464 extern SYMBOL
* trueSymbol
;
465 extern SYMBOL
* startSymbol
;
466 extern SYMBOL
* questionSymbol
;
467 extern SYMBOL
* atSymbol
;
468 extern SYMBOL
* mainContext
;
469 extern SYMBOL
* currentContext
;
470 extern SYMBOL
* errorEvent
;
471 extern SYMBOL sentinel
;
472 extern int commandLineFlag
;
473 extern int traceFlag
;
475 extern char * errorMessage
[];
476 extern jmp_buf errorJump
;
477 extern int pushResultFlag
;
478 extern int prettyPrintFlags
;
479 #define PRETTYPRINT_DOUBLE 1
480 #define PRETTYPRINT_STRING 2
481 extern char lc_decimal_point
;