1 /* misc.h
2  *
3  * $Id$
4  *
5  * Copyright 1990, 1991, 1992, 1993, 1994, 1995, Oliver Laumann, Berlin
6  * Copyright 2002, 2003 Sam Hocevar <sam@hocevar.net>, Paris
7  *
8  * This software was derived from Elk 1.2, which was Copyright 1987, 1988,
9  * 1989, Nixdorf Computer AG and TELES GmbH, Berlin (Elk 1.2 has been written
10  * by Oliver Laumann for TELES Telematic Services, Berlin, in a joint project
11  * between TELES and Nixdorf Microprocessor Engineering, Berlin).
12  *
13  * Oliver Laumann, TELES GmbH, Nixdorf Computer AG and Sam Hocevar, as co-
14  * owners or individual owners of copyright in this software, grant to any
15  * person or company a worldwide, royalty free, license to
16  *
17  *    i) copy this software,
18  *   ii) prepare derivative works based on this software,
19  *  iii) distribute copies of this software or derivative works,
20  *   iv) perform this software, or
21  *    v) display this software,
22  *
23  * provided that this notice is not removed and that neither Oliver Laumann
24  * nor Teles nor Nixdorf are deemed to have made any representations as to
25  * the suitability of this software for any purpose nor are held responsible
26  * for any defects of this software.
27  *
28  * THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
29  */
30 
31 extern_c Object elk_import False2;
32 
33 #define Nullp(x)    (TYPE(x) == T_Null)
34 #define Truep(x)    (!EQ(x,False) && !EQ(x,False2))
35 #define Car(x)      PAIR(x)->car
36 #define Cdr(x)      PAIR(x)->cdr
37 #define Cons        P_Cons
38 #define Begin       P_Begin
39 #define Assq(x,y)   General_Assoc(x,y,0)
40 #define Print(x)    General_Print_Object (x, Curr_Output_Port, 0)
41 #define Numeric(t)  (t == T_Fixnum || t == T_Flonum || t == T_Bignum)
42 
43 #define Whitespace(c) (c == ' ' || c == '\t' || c == '\014' || c == '\n' || c == '\r')
44 #define Delimiter(c) (c == ';' || c == ')' || c == '(' || c == '[' || c == ']' || c == '"')
45 
46 
47 /* Align heap addresses */
48 #ifdef ALIGN_8BYTE
49 #  define ELK_ALIGN(ptr) ((ptr) = (void *)(((intptr_t)(ptr) + 7) & ~7))
50 #else
51 #  define ELK_ALIGN(ptr) ((ptr) = (void *)(((intptr_t)(ptr) + 3) & ~3))
52 #endif
53 
54 /* Normalize stack addresses */
55 #define NORM(addr)  ((intptr_t)(addr) + delta)
56 
57 
58 /* Used in special forms: */
59 extern int Tail_Call;
60 
61 #define TC_Prolog   register int _t = Tail_Call
62 #define TC_Disable  Tail_Call = 0
63 #define TC_Enable   Tail_Call = _t
64 
65 
66 /* Macros to be used by readers registered with Define_Reader().
67  * They operate on variables c, port, f, and str.
68  */
69 #define Reader_Getc {\
70     c = str ? String_Getc (port) : getc (f);\
71     if (c == '\n') PORT(port)->lno++;\
72 }
73 
74 #define Reader_Ungetc {\
75     if (str) String_Ungetc (port,c); else (void)ungetc (c,f);\
76     if (c == '\n') if (PORT(port)->lno > 1) PORT(port)->lno--;\
77 }
78 
79 #define Reader_Tweak_Stream {\
80     if (!str && (feof (f) || ferror (f))) clearerr (f);\
81 }
82 
83 #define Reader_Sharp_Eof {\
84     Reader_Tweak_Stream;\
85     Reader_Error (port, "end of file after `#'");\
86 }
87