1 /* newlisp.h - header file for newLISP
2 
3     Copyright (C) 2015 Lutz Mueller
4 
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.
9 
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.
14 
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/>.
17 
18 */
19 
20 #ifndef NEWLISP_H
21 #define NEWLISP_H
22 
23 /* Take out bigger, less used code portions.  By default these capabilities
24    are enabled on all shipped binaries. Out-comment definitions to suppress.
25    Other capabilities like READLINE, SUPPORT_UTF8 can be en/disabled in
26    makefiles.
27    Undefining DEBUGGER does not affected simple tracing with (trace <device-no>)
28 */
29 
30 #define XML_SUPPORT
31 #define BIGINT
32 #define KMEANS
33 #define DEBUGGER
34 
35 
36 /* config.h is only needed when doing auto configuration with ./configure-alt */
37 #ifdef NEWCONFIG
38 #include "config.h"
39 #else
40 #define NEWLISPDIR "/usr/local/share/newlisp"
41 #endif
42 
43 /* force ISO_C90 restrictions */
44 #if defined(CYGWIN) || defined(OS2) || defined(SOLARIS) || defined(AIX) || defined(SUNOS)
45 /* not sure how this plays with introducing C99 based inttypes.h header file in 10.6.3 */
46 #define ISO_C90
47 #endif
48 
49 #ifdef LINUX
50 #define OSTYPE "Linux"
51 #endif
52 
53 #ifdef ANDROID
54 #define NO_SEMAPHORE
55 #endif
56 
57 #ifdef _BSD
58 #define OSTYPE "BSD"
59 #endif
60 
61 #ifdef KFREEBSD
62 #define OSTYPE "GNU/kFreeBSD"
63 #endif
64 
65 #ifdef MAC_OSX
66 #ifdef EMSCRIPTEN
67 #define OSTYPE "JS"
68 #else
69 #define OSTYPE "OSX"
70 #endif
71 #endif
72 
73 #ifdef SOLARIS
74 #define OSTYPE "Solaris"
75 #endif
76 
77 #ifdef SUNOS
78 #define SOLARIS
79 #define SPARC
80 #define OSTYPE "SunOS"
81 #endif
82 
83 #ifdef TRU64
84 #define OSTYPE "Tru64Unix"
85 #endif
86 
87 #ifdef AIX
88 #define OSTYPE "AIX"
89 #endif
90 
91 
92 #ifdef WINDOWS
93 #define OSTYPE "Windows"
94 #ifdef NEWLISP64
95 #define WIN_64
96 #else
97 #define WIN_32
98 #endif
99 #endif
100 
101 #ifdef CYGWIN
102 #define OSTYPE "Cygwin"
103 #endif
104 
105 #ifdef OS2
106 #define OSTYPE "OS/2"
107 #endif
108 
109 /* include -DFFI in your makefile on the compile line
110    and -lffi on the link line */
111 #ifdef FFI
112 
113 #if defined(MAC_OSX)
114 #include <ffi/ffi.h>
115 #endif
116 
117 #if defined(WINDOWS)
118 #include "win-ffi.h"
119 #endif
120 
121 #if defined(LINUX) || defined(_BSD) || defined(KFREEBSD) || defined(CYGWIN)
122 #include <ffi.h>
123 #endif
124 
125 #define LIBFFI " libffi"
126 #else /* not FFI */
127 #define LIBFFI ""
128 
129 #endif /* FFI */
130 
131 #ifdef TRU64
132 #define strtoll strtol
133 #define strtoull strtoul
134 #endif
135 
136 #if defined(SOLARIS) || defined(TRU64) || defined(AIX)
137 #define MY_RAND_MAX 2147483647
138 #else
139 #define MY_RAND_MAX RAND_MAX
140 #endif
141 
142 #ifdef LIBRARY
143 #define NO_FORK
144 #define NO_SPAWN
145 #define NO_DEBUG
146 #define NO_TIMER
147 #endif
148 
149 #ifdef EMSCRIPTEN
150 #define NO_DEBUG
151 #define NO_NET_FUNCTIONS
152 #define NO_WEB_FUNCTIONS
153 #endif
154 
155 
156 /*
157 This is for 64bit large file support (LFS),
158 */
159 #define LFS
160 #ifdef LFS
161 #if defined(SOLARIS) || defined(TRU64) || defined(AIX)
162 #define _LARGEFILE64_SOURCE 1
163 #endif
164 #define _FILE_OFFSET_BITS 64
165 #endif
166 
167 #ifdef WINDOWS
168 /* NOTE:
169  * Windows XP [0x0501] end of support on 2014/04/08
170  * WIndows Vista [0x0600] support ends on 2017/04/11
171  */
172 #ifndef _WIN32_WINNT
173 #define _WIN32_WINNT 0x0600
174 #endif
175 #endif
176 
177 #include <signal.h>
178 #include <errno.h>
179 #include <stdio.h>
180 #include <stdlib.h>
181 #include <locale.h>
182 #include <setjmp.h>
183 #include <stdarg.h>
184 #include <dirent.h>
185 #include <limits.h>
186 
187 /* some Linux do UTF-8 but do not have wcsftime()
188    buggy in some GCC, i.e. MinGW and Solaris
189 */
190 
191 #ifdef SUPPORT_UTF8
192 #ifdef LINUX
193 #include <wchar.h>
194 #define WCSFTIME
195 #endif
196 #ifdef WINDOWS
197 #include <wchar.h>
198 #endif
199 #ifdef CYGWIN
200 #include <wchar.h>
201 #define WCSFTIME
202 #endif
203 #endif
204 
205 #ifdef WINDOWS
206 #include <windef.h>
207 #include <winbase.h>
208 #else
209 #include <termios.h>
210 #include <sys/wait.h>
211 #endif
212 
213 #include <unistd.h>
214 #include <sys/time.h>
215 #include <math.h>
216 #include <float.h>
217 #include <string.h>
218 #include <ctype.h>
219 #include <fcntl.h>
220 #include <stdarg.h>
221 #include <time.h>
222 #include <sys/stat.h>
223 #include <sys/types.h>
224 
225 #if defined(LINUX) || defined(WINDOWS) || defined(OS2)
226 #include <malloc.h>
227 #endif
228 
229 #if defined(MAC_OSX) || defined(SOLARIS) || defined(TRU64) || defined(AIX)
230 #include <alloca.h>
231 #endif
232 
233 #ifdef OS2
234 #define vasprintf my_vasprintf
235 #define MY_VASPRINTF
236 #define NO_SPAWN
237 #define NO_FORK
238 #define NO_SHARE
239 #define NO_PACKET
240 #endif
241 
242 #if defined(SOLARIS) || defined(TRU64) || defined(AIX)
243 #define vasprintf my_vasprintf
244 #define MY_VASPRINTF
245 #endif
246 
247 #if defined(SOLARIS) && defined(SPARC)
248 #define setenv my_setenv
249 #define MY_SETENV
250 #endif
251 
252 #ifdef WINDOWS
253 
254 /* not needed on later MinGW, linker will complain if necessary  */
255 #define MY_VASPRINTF
256 #define vasprintf my_vasprintf
257 
258 #define MY_SETENV
259 #define NO_SPAWN
260 #define NO_FORK
261 #define NO_NET_PACKET
262 #define NO_NET_PING
263 
264 #define LITTLE_ENDIAN
265 #define LINE_FEED "\r\n"
266 #define LINE_FEED_LEN 2
267 #define getSocket(A) ((A)->_file)
268 #define setenv my_setenv
269 #define random rand
270 #define srandom srand
271 #define ioctl ioctlsocket
272 #define off_t off64_t
273 #define lseek lseek64
274 #define ftell ftello64
275 #define getpid GetCurrentProcessId
276 
277 #ifndef SUPPORT_UTF8
278 #define mkdir  _mkdir
279 #define rmdir  _rmdir
280 #define lstat stat
281 #endif
282 
283 #define realpath win_realpath
284 
285 /* WINDOWS UTF16 support for file paths */
286 #ifdef SUPPORT_UTF8
287 #define USE_WIN_UTF16PATH
288 #define rename rename_utf16
289 #define open open_utf16
290 #define mkdir mkdir_utf16
291 #define rmdir rmdir_utf16
292 #define unlink unlink_utf16
293 #define chdir chdir_utf16
294 #define opendir opendir_utf16
295 #define DIR _WDIR
296 #define lstat _wstat
297 #define dirent _wdirent
298 #define readdir _wreaddir
299 #define closedir _wclosedir
300 #endif /* SUPPORT_UTF8 */
301 
302 #endif /* WINDOWS */
303 
304 #ifndef WINDOWS
305 #define LINE_FEED "\n"
306 #define LINE_FEED_LEN 1
307 #define NANOSLEEP
308 #endif
309 
310 #ifndef O_BINARY
311 #define O_BINARY 0
312 #endif
313 
314 #define UTF8_MAX_BYTES 6
315 
316 #include <stdint.h>
317 #include <inttypes.h>
318 
319 #define UINT   uintptr_t  /* either 32-bit on ILP32 or 64-bit on LP64,LLP64 */
320 #define INT    intptr_t   /* replaces 'long' which stayed 32-bit on Windows LLP64 */
321 
322 #define INT16  int16_t
323 #define INT64  int64_t
324 #define UINT64 int64_t
325 
326 #define MAX_LONG INTPTR_MAX
327 
328 #define CONNECT_TIMEOUT 10000
329 
330 #define pushEnvironment(A) (*(envStackIdx++) = (UINT)(A))
331 #define popEnvironment() (*(--envStackIdx))
332 
333 /* reading top of stack in copyCell() does not require
334    subtracting 1 from index (changed in 10.3.2 */
335 #define pushResult(A) (*(++resultStackIdx) = (UINT)(A))
336 #define popResult() ((CELL *)*(resultStackIdx--))
337 
338 #define freeMemory free
339 
340 #define INT32_MIN_AS_INT64 (((long long int)0xFFFFFFFF << 32) | 0x80000000)
341 #define MY_INT64_MAX (((long long int)0x7FFFFFFF << 32) | 0xFFFFFFFF)
342 #define TRUE 1
343 #define FALSE 0
344 
345 #define MAX_STRING 2048 /* buffer length */
346 #define MAX_LINE 256 /* buffer length */
347 /* following limits are only for parsing */
348 #define MAX_COMMAND_LINE 1024 /* buffer length */
349 #define MAX_SYMBOL 1023 /* string length -1 */
350 #define MAX_DIGITS 1001 /* 1000 + sign, limitation only for parsing source */
351 #define MAX_HEX_NO MAX_DIGITS /* 16 + 0x */
352 #define MAX_BIN_NO MAX_DIGITS /* 64 + 0B */
353 #define MAX_DECIMALS MAX_DIGITS /* 32, numbers with decimal point */
354 
355 #define MAX_FILE_BUFFER 0x2000
356 #define MAX_BLOCK 4095
357 #define MAX_URL_LEN 255 /* strlen() */
358 
359 #define MAX_REGEX_EXP 16
360 
361 /* token types */
362 #define TKN_ERROR -1
363 #define TKN_EMPTY 0
364 #define TKN_CHARACTER 1
365 #define TKN_HEX 2
366 #define TKN_OCTAL 3
367 #define TKN_BINARY 4
368 #define TKN_DECIMAL 5
369 #define TKN_FLOAT 6
370 #define TKN_STRING 7
371 #define TKN_SYMBOL 8
372 #define TKN_CONTEXT 9
373 #define TKN_LEFT_PAR '('
374 #define TKN_RIGHT_PAR ')'
375 #define TKN_QUOTE '\''
376 
377 /* symbol flags types and masks */
378 #define PRINT_TYPE_MASK 0x0F
379 #define SYMBOL_PROTECTED 0x10
380 #define SYMBOL_GLOBAL 0x20
381 #define SYMBOL_BUILTIN 0x40
382 #define SYMBOL_FFI 0x100
383 #define SYMBOL_MACRO 0x200
384 #define SYMBOL_DESTRUCTIVE 0x400
385 
386 /* cell masks */
387 
388 #define RAW_TYPE_MASK 0x0FFF
389 #define COMPARE_TYPE_MASK 0x000F
390 #define ENVELOPE_TYPE_MASK 0x0010
391 #define LIST_TYPE_MASK 0x0020
392 #define SYMBOL_TYPE_MASK 0x0040
393 #define NUMBER_TYPE_MASK 0x0080
394 #define EVAL_SELF_TYPE_MASK 0x0100
395 #define INT64_MASK 0x0200
396 #define BIGINT_MASK 0x0400
397 #define CALL_CDECL_MASK 0x1000
398 #define CALL_DLL_MASK 0x2000
399 #define CALL_FFI_MASK 0x4000
400 #define IMPORT_MASK (CALL_CDECL_MASK | CALL_DLL_MASK | CALL_FFI_MASK)
401 /* only used for type ids used in shared memory
402    to indicate translation from string */
403 #define SHARED_MEM_EVAL_MASK 0x8000
404 
405 /* cell types, do not change these without changing newlisp.c/cellCopy() */
406 #define CELL_NIL (0 | EVAL_SELF_TYPE_MASK)
407 #define CELL_TRUE (1 | EVAL_SELF_TYPE_MASK)
408 #define CELL_INT 2 /* any INT */
409 #define CELL_LONG (2 | EVAL_SELF_TYPE_MASK | NUMBER_TYPE_MASK)
410 #ifndef NEWLISP64
411 #define CELL_INT64 (2 | EVAL_SELF_TYPE_MASK | NUMBER_TYPE_MASK | INT64_MASK)
412 #endif
413 
414 #ifdef BIGINT
415 #define CELL_BIGINT (2 | EVAL_SELF_TYPE_MASK | NUMBER_TYPE_MASK | BIGINT_MASK)
416 #endif
417 
418 #define CELL_FLOAT (3 | EVAL_SELF_TYPE_MASK | NUMBER_TYPE_MASK)
419 #define CELL_STRING (4 | EVAL_SELF_TYPE_MASK)
420 #define CELL_SYMBOL (5 | SYMBOL_TYPE_MASK)
421 #define CELL_CONTEXT 6
422 #define CELL_PRIMITIVE (7 | EVAL_SELF_TYPE_MASK)
423 #define CELL_IMPORT_CDECL (8 | EVAL_SELF_TYPE_MASK | CALL_CDECL_MASK)
424 #define CELL_IMPORT_DLL (8 | EVAL_SELF_TYPE_MASK | CALL_DLL_MASK)
425 #define CELL_IMPORT_FFI (9 | EVAL_SELF_TYPE_MASK | CALL_FFI_MASK)
426 #define CELL_QUOTE (10 | ENVELOPE_TYPE_MASK)
427 #define CELL_EXPRESSION (11 | ENVELOPE_TYPE_MASK | LIST_TYPE_MASK)
428 #define CELL_LAMBDA (12 | ENVELOPE_TYPE_MASK | LIST_TYPE_MASK | EVAL_SELF_TYPE_MASK)
429 #define CELL_FEXPR (13 | ENVELOPE_TYPE_MASK | LIST_TYPE_MASK | EVAL_SELF_TYPE_MASK)
430 #define CELL_ARRAY (14 | ENVELOPE_TYPE_MASK | EVAL_SELF_TYPE_MASK)
431 #define CELL_DYN_SYMBOL (15 | SYMBOL_TYPE_MASK)
432 #define CELL_FREE 0xFF
433 
434 /* cell type classes */
435 #define isEnvelope(A) ((A) & ENVELOPE_TYPE_MASK)
436 #define isList(A) ((A) & LIST_TYPE_MASK)
437 #define isNumber(A) ((A) & NUMBER_TYPE_MASK)
438 #define isSymbol(A) ((A) & SYMBOL_TYPE_MASK)
439 #define isSelfEval(A) ((A) & EVAL_SELF_TYPE_MASK)
440 
441 /* symbol classes */
442 #define isProtected(A) ((A) & (SYMBOL_PROTECTED | SYMBOL_MACRO))
443 #define isBuiltin(A) ((A) & SYMBOL_BUILTIN)
444 #define isGlobal(A) ((A) & SYMBOL_GLOBAL)
445 #define isFFIsymbol(A) ((A) & SYMBOL_FFI)
446 
447 #define isDigit(A) isdigit((int)(A))
448 #define isHexDigit(A) isxdigit((int)(A))
449 
450 #define isNil(A) ((A)->type == CELL_NIL || ((A)->type == CELL_SYMBOL && (A)->contents == (UINT)nilSymbol))
451 #define isTrue(A) ((A)->type == CELL_TRUE || ((A)->type == CELL_SYMBOL && (A)->contents == (UINT)trueSymbol))
452 #define isEmpty(A) ((A)->type == CELL_EXPRESSION && (A)->contents == (UINT)nilCell)
453 
454 #define symbolType(A) ((CELL*)(A)->contents)->type
455 
456 /* redefine some functions */
457 #ifdef NEWLISP64
458 #define stuffInteger64 stuffInteger
459 #endif
460 
461 /* RED BLACK binary balanced tree: nl-symbol.c */
462 #define BLACK 0
463 #define RED 1
464 #define NIL_SYM &sentinel
465 #define LOOKUP_ONLY 0		/* symbol lookup only, if not found return NULL */
466 #define FORCE_CREATION 1	/* if symbol does not exist, create it */
467 
468 /* traceFlag */
469 #define TRACE_TRUE 0x0001
470 #define TRACE_IN_ENTRY 0x0002
471 #define TRACE_IN_EXIT 0x0004
472 #define TRACE_IN_DEBUG 0x0008
473 #define TRACE_DEBUG_PENDING 0x0010
474 #define TRACE_DEBUG_EVAL 0x0020
475 #define TRACE_DEBUG_STEP 0x0040
476 #define TRACE_DEBUG_NEXT 0x0080
477 #define TRACE_PRINT_EVAL 0x0100
478 #define TRACE_SIGINT 0x1000
479 #define TRACE_TIMER  0x2000
480 #define TRACE_SIGNAL 0x4000
481 #define TRACE_CILK 0x8000
482 
483 /* error handling */
484 
485 #define ERR_NOT_ENOUGH_MEMORY 1
486 #define ERR_OUT_OF_ENV_STACK 2
487 #define ERR_OUT_OF_CALL_STACK 3
488 #define ERR_ACCESSING_FILE 4
489 #define ERR_EXPRESSION 5
490 #define ERR_MISSING_PAR 6
491 #define ERR_STRING_TOO_LONG 7
492 #define ERR_MISSING_ARGUMENT 8
493 #define ERR_NUMBER_OR_STRING_EXPECTED 9
494 #define ERR_NUMBER_EXPECTED 10
495 #define ERR_STRING_EXPECTED 11
496 #define ERR_SYMBOL_EXPECTED 12
497 #define ERR_CONTEXT_EXPECTED 13
498 #define ERR_SYMBOL_OR_CONTEXT_EXPECTED 14
499 #define ERR_LIST_EXPECTED 15
500 #define ERR_LIST_OR_ARRAY_EXPECTED 16
501 #define ERR_LIST_OR_SYMBOL_EXPECTED 17
502 #define ERR_LIST_OR_STRING_EXPECTED 18
503 #define ERR_LIST_OR_NUMBER_EXPECTED 19
504 #define ERR_ARRAY_EXPECTED 20
505 #define ERR_ARRAY_LIST_OR_STRING_EXPECTED 21
506 #define ERR_LAMBDA_EXPECTED 22
507 #define ERR_MACRO_EXPECTED 23
508 #define ERR_INVALID_FUNCTION 24
509 #define ERR_INVALID_LAMBDA 25
510 #define ERR_INVALID_MACRO 26
511 #define ERR_INVALID_LET 27
512 #define ERR_SAVING_FILE 28
513 #define ERR_MATH 29
514 #define ERR_NOT_MATRIX 30
515 #define ERR_WRONG_DIMENSIONS 31
516 #define ERR_SINGULAR 32
517 #define ERR_INVALID_OPTION 33
518 #define ERR_THROW_WO_CATCH 34
519 #define ERR_IMPORT_LIB_NOT_FOUND 35
520 #define ERR_IMPORT_FUNC_NOT_FOUND 36
521 #define ERR_SYMBOL_PROTECTED 37
522 #define ERR_NUMBER_OUT_OF_RANGE 38
523 #define ERR_REGEX 39
524 #define ERR_TEXT_END_TAG 40
525 #define ERR_NUM_ARGS 41
526 #define ERR_FORMAT_STRING 42
527 #define ERR_FORMAT_DATA_TYPE 43
528 #define ERR_INVALID_PARAMETER 44
529 #define ERR_INVALID_PARAMETER_0 45
530 #define ERR_INVALID_PARAMETER_NAN 46
531 #define ERR_INVALID_UTF8 47
532 #define ERR_ILLEGAL_TYPE 48
533 #define ERR_NOT_IN_MAIN 49
534 #define ERR_NOT_CURRENT_CONTEXT 50
535 #define ERR_TARGET_NO_MAIN 51
536 #define ERR_LIST_INDEX_INVALID 52
537 #define ERR_ARRAY_INDEX_OUTOF_BOUNDS 53
538 #define ERR_STRING_INDEX_INVALID 54
539 #define ERR_NESTING_TOO_DEEP 55
540 #define ERR_LIST_REFERENCE_CHANGED 56
541 #define ERR_SYNTAX_WRONG 57
542 #define ERR_USER_ERROR 58
543 #define ERR_USER_RESET 59
544 #define ERR_SIGINT 60
545 #define ERR_NOT_REENTRANT 61
546 #define ERR_CANNOT_PROTECT_LOCAL 62
547 #define ERR_IS_NOT_REFERENCED 63
548 #define ERR_LIST_EMPTY 64
549 #define ERR_IO_ERROR 65
550 #define ERR_WORKING_DIR 66
551 #define ERR_INVALID_PID 67
552 #define ERR_CANNOT_OPEN_SOCKETPAIR 68
553 #define ERR_CANNOT_FORK_PROCESS 69
554 #define ERR_NO_SOCKET 70
555 #define ERR_FFI_PREP_FAILED 71
556 #define ERR_FFI_INVALID_TYPE 72
557 #define ERR_FFI_STRUCT_EXPECTED 73
558 #define ERR_BIGINT_NOT_ALLOWED 74
559 #define ERR_CANNOT_CONVERT 75
560 #define ERR_CANNOT_CONVERT_NULL 76
561 #define MAX_ERROR_NUMBER 76
562 #define UNKNOWN_ERROR "Unknown error"
563 
564 /* network error handling */
565 #define ERR_INET_OPEN_SOCKET 1
566 #define ERR_INET_HOST_UNKNOWN 2
567 #define ERR_INET_INVALID_SERVICE 3
568 #define ERR_INET_CONNECT_FAILED 4
569 #define ERR_INET_ACCEPT 5
570 #define ERR_INET_CONNECTION_DROPPED 6
571 #define ERR_INET_CONNECTION_BROKEN 7
572 #define ERR_INET_READ 8
573 #define ERR_INET_WRITE 9
574 #define ERR_INET_CANNOT_BIND 10
575 #define ERR_INET_TOO_MUCH_SOCKETS 11
576 #define ERR_INET_LISTEN_FAILED 12
577 #define ERR_INET_BAD_FORMED_IP 13
578 #define ERR_INET_SELECT_FAILED 14
579 #define ERR_INET_PEEK_FAILED 15
580 #define ERR_INET_NOT_VALID_SOCKET 16
581 #define ERR_INET_CANNOT_CHANGE_SOCK_BLOCK 17
582 #define ERR_INET_TIMEOUT 18
583 /* used in nl-web.c */
584 #define ERROR_BAD_URL 19
585 #define ERROR_FILE_OP 20
586 #define ERROR_TRANSFER 21
587 #define ERROR_INVALID_RESPONSE 22
588 #define ERROR_NO_RESPONSE 23
589 #define ERROR_NO_CONTENT 24
590 #define ERROR_HEADER 25
591 #define ERROR_CHUNKED_FORMAT 26
592 
593 #define MAX_NET_ERROR 26
594 
595 
596 /* I/O routines */
597 #define OUT_NULL 0
598 #define OUT_DEVICE 1
599 #define OUT_CONSOLE 2
600 #define OUT_LOG 3
601 
602 /* HTTP in nl-web.c */
603 #define HTTP_GET 0
604 #define HTTP_HEAD 1
605 #define HTTP_PUT 2
606 #define HTTP_PUT_APPEND 3
607 #define HTTP_POST 4
608 #define HTTP_DELETE 5
609 
610 /* sysEvalString() in newlisp.c */
611 #define EVAL_STRING 0 /* the classic eval-string: read, xlate, evaluate */
612 #define READ_EXPR 1 /* read one toplevel expression: read */
613 #define READ_EXPR_SYNC 2 /* called from sync */
614 #define READ_EXPR_NET 3 /* called from net-eval */
615 
616 /* used inf setDefine() define in newlisp.c */
617 #define SET_SET 1
618 #define SET_CONSTANT 2
619 #define SET_DEFINE 3
620 
621 extern int vasprintf (char **, const char *, va_list);
622 
623 /* ---------------------------- standard types ------------------------- */
624 
625 typedef struct
626 	{
627 	char *ptr;
628 	char *buffer;
629 	size_t position;
630 	size_t size;
631 	int handle;
632 	} STREAM;
633 
634 typedef struct tagSYMBOL
635 	{
636 	int flags;
637 	int color;
638 	char * name;
639 	UINT contents;
640 	struct tagSYMBOL * context;
641 	struct tagSYMBOL * parent;
642 	struct tagSYMBOL * left;
643 	struct tagSYMBOL * right;
644 	} SYMBOL;
645 
646 typedef struct
647 	{
648 	UINT type;
649 	void * next;
650 	UINT aux;
651 	UINT contents;
652 	} CELL;
653 
654 typedef struct
655 	{
656 	char * name;
657 	CELL * (*function)(CELL *);
658 	short int flags;
659 	} PRIMITIVE;
660 
661 typedef struct
662     {
663     int handle;
664     int family;
665     FILE * stream;
666     void * next;
667     } IO_SESSION;
668 
669 #ifdef FFI
670 
671 #define FFI_FUNCTION (1)
672 #define FFI_CLOSURE  (2)
673 #define FFI_STRUCT   (3)
674 
675 typedef struct {
676   SYMBOL *symbol;
677   void *code;
678 } ffi_closure_data;
679 
680 typedef struct
681     {
682     char *name;
683     void (*func)(void);
684     ffi_cif cif;
685     void *code;
686     ffi_closure *clos;
687     ffi_closure_data *data;
688     ffi_type *cstruct;
689     short int type;
690     } FFIMPORT;
691 #endif
692 
693 /* --------------------------- globals -------------------------------- */
694 
695 extern char startupDir[];
696 extern char * tempDir;
697 extern FILE * IOchannel;
698 extern int ADDR_FAMILY;
699 #ifdef WINDOWS
700 extern int IOchannelIsSocket;
701 #endif
702 extern int MAX_CPU_STACK;
703 extern INT MAX_CELL_COUNT;
704 extern int version;
705 extern int opsys;
706 extern char ostype[];
707 extern size_t cellCount;
708 extern size_t symbolCount;
709 extern int recursionCount;
710 extern UINT printDevice;
711 extern UINT * resultStack;
712 extern UINT * resultStackIdx;
713 extern UINT * envStack;
714 extern UINT * envStackIdx;
715 extern CELL * trueCell;
716 extern CELL * nilCell;
717 extern STREAM strStream;
718 extern SYMBOL * nilSymbol;
719 extern SYMBOL * trueSymbol;
720 extern SYMBOL * startSymbol;
721 extern SYMBOL * questionSymbol;
722 extern SYMBOL * atSymbol;
723 extern SYMBOL * mainContext;
724 extern SYMBOL * currentContext;
725 extern SYMBOL * errorEvent;
726 extern SYMBOL * symbolCheck;
727 extern SYMBOL * itSymbol;
728 extern SYMBOL sentinel;
729 extern void * stringIndexPtr;
730 extern CELL * stringCell;
731 extern int traceFlag;
732 extern int errorReg;
733 extern char * errorMessage[];
734 extern jmp_buf errorJump;
735 extern int pushResultFlag;
736 extern int prettyPrintFlags;
737 #define PRETTYPRINT_DOUBLE 1
738 #define PRETTYPRINT_STRING 2
739 extern char lc_decimal_point;
740 extern CELL * xmlTags;
741 extern CELL * xmlCallback;
742 /* end of file */
743 
744 #endif /* NEWLISP_H */
745 
746