home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / lucid / lemacs-19.6 / src / lisp.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-03-13  |  28.6 KB  |  940 lines

  1. /* Fundamental definitions for GNU Emacs Lisp interpreter.
  2.    Copyright (C) 1985-1993 Free Software Foundation, Inc.
  3.  
  4. This file is part of GNU Emacs.
  5.  
  6. GNU Emacs is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2, or (at your option)
  9. any later version.
  10.  
  11. GNU Emacs is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GNU Emacs; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. #ifndef _EMACS_LISP_H_
  21. #define _EMACS_LISP_H_
  22.  
  23. #ifdef emacs    /* some things other than emacs want the structs */
  24. #if __STDC__
  25.  
  26. /* I don't know how correct this attempt to get more prototypes is... */
  27. # if defined(sun) && defined(_POSIX_SOURCE)
  28. #  undef _POSIX_SOURCE
  29. # endif
  30.  
  31. # if defined(__lucid) && !defined(__STDC_EXTENDED__)
  32. #  define __STDC_EXTENDED__ 1
  33. # endif
  34.  
  35. # include <stdlib.h>
  36. # include <unistd.h>
  37. # include <string.h>
  38.  
  39. # ifdef __lucid
  40. #  include <sysent.h>
  41. # endif
  42.  
  43. #ifdef NeXT
  44. typedef int pid_t;
  45. #endif
  46.  
  47. #endif /* __STDC__ */
  48. #endif /* emacs */
  49.  
  50. /* Define the fundamental Lisp data structures */
  51.  
  52. /* This is the set of Lisp data types */
  53.  
  54. enum Lisp_Type
  55.   {
  56.     /* Integer.  XINT(obj) is the integer value. */
  57.     Lisp_Int,
  58.  
  59.     /* Symbol.  XSYMBOL (object) points to a struct Lisp_Symbol. */
  60.     Lisp_Symbol,
  61.  
  62.     /* Marker (buffer ptr).  XMARKER(object) points to a struct Lisp_Marker. */
  63.     Lisp_Marker,
  64.  
  65.     /* String.  XSTRING (object) points to a struct Lisp_String.
  66.        The length of the string, and its contents, are stored therein. */
  67.     Lisp_String,
  68.  
  69.     /* Vector of Lisp objects.  XVECTOR(object) points to a struct Lisp_Vector.
  70.        The length of the vector, and its contents, are stored therein. */
  71.     Lisp_Vector,
  72.  
  73.     /* Cons.  XCONS (object) points to a struct Lisp_Cons. */
  74.     Lisp_Cons,
  75.  
  76.     /* Byte-compiled function.  A vector of 4 to 6 elements which are the
  77.        arglist, bytecode-string, constant vector, stack size,
  78.        (optional) doc string, and (optional) interactive spec.  */
  79.     Lisp_Compiled,
  80.  
  81.     /* Editor buffer.  XBUFFER(obj) points to a struct buffer.  */
  82.     Lisp_Buffer,
  83.  
  84.     /* Built-in function.  XSUBR(obj) points to a struct Lisp_Subr
  85.        which describes how to call the function, and its documentation,
  86.        as well as pointing to the code. */
  87.     Lisp_Subr,
  88.  
  89.     /* Internal value return by subroutines of read.
  90.        The user never sees this data type.
  91.        Its value is just a number. */
  92.     Lisp_Internal,
  93.  
  94.     /* Forwarding pointer to an int variable.
  95.        This is allowed only in the value cell of a symbol,
  96.        and it means that the symbol's value really lives in the
  97.        specified int variable.
  98.        XINTPTR(obj) points to the int variable. */
  99.     Lisp_Intfwd,
  100.  
  101.     /* Boolean forwarding pointer to an int variable.
  102.        This is like Lisp_Intfwd except that the ostensible
  103.        "value" of the symbol is t if the int variable is nonzero,
  104.        nil if it is zero.  XINTPTR(obj) points to the int variable. */
  105.     Lisp_Boolfwd,
  106.  
  107.     /* Object describing a connection to a subprocess.
  108.        It points to storage of type  struct Lisp_Process  */
  109.     Lisp_Process,
  110.  
  111.     /* Forwarding pointer to a Lisp_Object variable.
  112.        This is allowed only in the value cell of a symbol,
  113.        and it means that the symbol's value really lives in the
  114.        specified variable.
  115.        XOBJFWD(obj) points to the Lisp_Object variable. */
  116.     Lisp_Objfwd,
  117.  
  118.     /* Pointer to a vector-like object describing a display screen
  119.        on which Emacs can display a window hierarchy.  */
  120.     Lisp_Screen,
  121.  
  122.     /* Used when a FILE * value needs to be passed
  123.        in an argument of type Lisp_Object.
  124.        You must do *(FILE **) XPNTR(obj) to get the value.
  125.        The user will never see this data type. */
  126.     Lisp_Internal_Stream,
  127.  
  128.     /* Used in a symbol value cell when the symbol's value is per-buffer.
  129.         The actual contents are a cons cell which starts a list like this:
  130.         (REALVALUE BUFFER CURRENT-ALIST-ELEMENT . DEFAULT-VALUE)).
  131.  
  132.     BUFFER is the last buffer for which this symbol's value was
  133.     made up to date.
  134.  
  135.         CURRENT-ALIST-ELEMENT is a pointer to an element of BUFFER's
  136.     b_local_var_alist, that being the element whose car is this variable.
  137.         Or it can be a pointer to the (CURRENT-ALIST-ELEMENT . DEFAULT-VALUE), if BUFFER
  138.     does not have an element in its alist for this variable
  139.     (that is, if BUFFER sees the default value of this variable).
  140.  
  141.     If we want to examine or set the value and BUFFER is current,
  142.     we just examine or set REALVALUE.
  143.     If BUFFER is not current, we store the current REALVALUE value into
  144.     CURRENT-ALIST-ELEMENT, then find the appropriate alist element for
  145.     the buffer now current and set up CURRENT-ALIST-ELEMENT.
  146.     Then we set REALVALUE out of that element, and store into BUFFER.
  147.  
  148.     If we are setting the variable and the current buffer does not have
  149.     an alist entry for this variable, an alist entry is created.
  150.  
  151.     Note that REALVALUE can be a forwarding pointer.
  152.     Each time it is examined or set, forwarding must be done.  */
  153.     Lisp_Buffer_Local_Value,
  154.  
  155.     /* Like Lisp_Buffer_Local_Value with one difference:
  156.     merely setting the variable while some buffer is current
  157.     does not cause that buffer to have its own local value of this variable.
  158.     Only make-local-variable does that.  */
  159.     Lisp_Some_Buffer_Local_Value,
  160.  
  161.  
  162.     /* Like Lisp_Objfwd except that value lives in a slot
  163.        in the current buffer.  Value is byte index of slot within buffer */
  164.     Lisp_Buffer_Objfwd,
  165.  
  166.     /* In symbol value cell, means var is unbound.
  167.        In symbol function cell, means function name is undefined. */
  168.     Lisp_Void,
  169.  
  170.     /* Window used for Emacs display.
  171.        Data inside looks like a Lisp_Vector.  */
  172.     Lisp_Window,
  173.  
  174.     /* Used by save,set,restore-window-configuration */
  175.     Lisp_Window_Configuration,
  176.  
  177.     /* An active region in buffer or string.  XEXTENT (obj) is
  178.        typedef EXTENT. */
  179.     Lisp_Extent,
  180.  
  181.     Lisp_Extent_Data,
  182.  
  183.     Lisp_Extent_Replica,
  184.  
  185. #ifdef LISP_FLOAT_TYPE
  186.     Lisp_Float,
  187. #endif /* LISP_FLOAT_TYPE */
  188.  
  189.     Lisp_Event,
  190.     Lisp_Keymap
  191.   };
  192.  
  193. #ifndef NO_UNION_TYPE
  194.  
  195. #ifndef BIG_ENDIAN
  196.  
  197. /* Definition of Lisp_Object for little-endian machines.  */
  198.  
  199. typedef
  200. union Lisp_Object
  201.   {
  202.     /* Used for comparing two Lisp_Objects;
  203.        also, positive integers can be accessed fast this way. */
  204.     int i;
  205.  
  206.     struct
  207.       {
  208.     int val: 24;
  209.     char type;
  210.       } s;
  211.     struct
  212.       {
  213.     unsigned int val: 24;
  214.     char type;
  215.       } u;
  216.     struct
  217.       {
  218.     unsigned int val: 24;
  219.     enum Lisp_Type type: 7;
  220.     /* The markbit is not really part of the value of a Lisp_Object,
  221.        and is always zero except during garbage collection.  */
  222.     unsigned int markbit: 1;
  223.       } gu;
  224.   }
  225. Lisp_Object;
  226.  
  227. #else /* If BIG_ENDIAN */
  228.  
  229. typedef
  230. union Lisp_Object
  231.   {
  232.     /* Used for comparing two Lisp_Objects;
  233.        also, positive integers can be accessed fast this way. */
  234.     int i;
  235.  
  236.     struct
  237.       {
  238.     char type;
  239.     int val: 24;
  240.       } s;
  241.     struct
  242.       {
  243.     char type;
  244.     unsigned int val: 24;
  245.       } u;
  246.     struct
  247.       {
  248.     /* The markbit is not really part of the value of a Lisp_Object,
  249.        and is always zero except during garbage collection.  */
  250.     unsigned int markbit: 1;
  251.     enum Lisp_Type type: 7;
  252.     unsigned int val: 24;
  253.       } gu;
  254.   }
  255. Lisp_Object;
  256.  
  257. #endif /* BIG_ENDIAN */
  258.  
  259. #endif /* NO_UNION_TYPE */
  260.  
  261.  
  262. /* If union type is not wanted, define Lisp_Object as just a number
  263.    and define the macros below to extract fields by shifting */
  264.  
  265. #ifdef NO_UNION_TYPE
  266.  
  267. #define Lisp_Object int
  268.  
  269. /* These values are overridden by the m- file on some machines.  */
  270. #ifndef VALBITS
  271. #define VALBITS 24
  272. #endif
  273.  
  274. #ifndef GCTYPEBITS
  275. #define GCTYPEBITS 7
  276. #endif
  277.  
  278. #ifndef VALMASK
  279. #define VALMASK ((1<<VALBITS) - 1)
  280. #endif
  281. #define GCTYPEMASK ((1<<GCTYPEBITS) - 1)
  282. #define MARKBIT (1 << (VALBITS + GCTYPEBITS))
  283.  
  284. #endif /* NO_UNION_TYPE */
  285.  
  286. /* These macros extract various sorts of values from a Lisp_Object.
  287.  For example, if tem is a Lisp_Object whose type is Lisp_Cons,
  288.  XCONS (tem) is the struct Lisp_Cons * pointing to the memory for that cons. */
  289.  
  290. #ifdef NO_UNION_TYPE
  291.  
  292. /* One need to override this if there must be high bits set in data space
  293.    (doing the result of the below & ((1 << (GCTYPE + 1)) - 1) would work
  294.     on all machines, but would penalise machines which don't need it)
  295.  */
  296. #ifndef XTYPE
  297. #define XTYPE(a) ((enum Lisp_Type) ((a) >> VALBITS))
  298. #endif
  299.  
  300. #ifndef XSETTYPE
  301. #define XSETTYPE(a, b) ((a)  =  XUINT (a) | ((int)(b) << VALBITS))
  302. #endif
  303.  
  304. /* Use XFASTINT for fast retrieval and storage of integers known
  305.   to be positive.  This takes advantage of the fact that Lisp_Int is 0.  */
  306. #define XFASTINT(a) (a)
  307.  
  308. /* Extract the value of a Lisp_Object as a signed integer.  */
  309.  
  310. #ifndef XINT   /* Some machines need to do this differently.  */
  311. #define XINT(a) (((a) << (INTBITS-VALBITS)) >> (INTBITS-VALBITS))
  312. #endif
  313.  
  314. /* Extract the value as an unsigned integer.  This is a basis
  315.    for extracting it as a pointer to a structure in storage.  */
  316.  
  317. #ifndef XUINT
  318. #define XUINT(a) ((a) & VALMASK)
  319. #endif
  320.  
  321. #ifndef XPNTR
  322. #ifdef HAVE_SHM
  323. /* In this representation, data is found in two widely separated segments.  */
  324. extern int pure_size;
  325. #define XPNTR(a) \
  326.   (XUINT (a) | (XUINT (a) > pure_size ? DATA_SEG_BITS : PURE_SEG_BITS))
  327. #else /* not HAVE_SHM */
  328. #ifdef DATA_SEG_BITS
  329. /* This case is used for the rt-pc.
  330.    In the diffs I was given, it checked for ptr = 0
  331.    and did not adjust it in that case.
  332.    But I don't think that zero should ever be found
  333.    in a Lisp object whose data type says it points to something.  */
  334. #define XPNTR(a) (XUINT (a) | DATA_SEG_BITS)
  335. #else
  336. #define XPNTR(a) XUINT (a)
  337. #endif
  338. #endif /* not HAVE_SHM */
  339. #endif /* no XPNTR */
  340.  
  341. #ifndef XSETINT
  342. #if 0 /* This is the nominal def, but it breaks things. */
  343. #define XSETINT(a, b)  XSET ((a), Lisp_Int, (b))
  344. #endif
  345. #define XSETINT(a, b)  ((a) = ((a) & ~VALMASK) |  ((b) & VALMASK))
  346. #endif
  347.  
  348. #ifndef XSET
  349. #define XSET(var, type, ptr) \
  350.    ((var) = ((int)(type) << VALBITS) + ((int) (ptr) & VALMASK))
  351. #endif
  352.  
  353. /* During garbage collection, XGCTYPE must be used for extracting types
  354.  so that the mark bit is ignored.  XMARKBIT accesses the markbit.
  355.  Markbits are used only in particular slots of particular structure types.
  356.  Other markbits are always zero.
  357.  Outside of garbage collection, all mark bits are always zero.  */
  358.  
  359. #ifndef XGCTYPE
  360. #define XGCTYPE(a) ((enum Lisp_Type) (((a) >> VALBITS) & GCTYPEMASK))
  361. #endif
  362.  
  363. #if VALBITS + GCTYPEBITS == INTBITS - 1
  364. /* Make XMARKBIT faster if mark bit is sign bit.  */
  365. #ifndef XMARKBIT
  366. #define XMARKBIT(a) ((a) < 0)
  367. #endif
  368. #endif /* markbit is sign bit */
  369.  
  370. #ifndef XMARKBIT
  371. #define XMARKBIT(a) ((a) & MARKBIT)
  372. #endif
  373.  
  374. #ifndef XSETMARKBIT
  375. #define XSETMARKBIT(a,b) ((a) = ((a) & ~MARKBIT) | ((b) ? MARKBIT : 0))
  376. #endif
  377.  
  378. #ifndef XMARK
  379. #define XMARK(a) ((a) |= MARKBIT)
  380. #endif
  381.  
  382. #ifndef XUNMARK
  383. #define XUNMARK(a) ((a) &= ~MARKBIT)
  384. #endif
  385.  
  386. #endif /* NO_UNION_TYPE */
  387.  
  388. #ifndef NO_UNION_TYPE
  389.  
  390. #define XTYPE(a) ((enum Lisp_Type) (a).u.type)
  391. #define XSETTYPE(a, b) ((a).u.type = (char) (b))
  392.  
  393. /* Use XFASTINT for fast retrieval and storage of integers known
  394.   to be positive.  This takes advantage of the fact that Lisp_Int is 0.  */
  395. #define XFASTINT(a) ((a).i)
  396.  
  397. #ifdef EXPLICIT_SIGN_EXTEND
  398. /* Make sure we sign-extend; compilers have been known to fail to do so.  */
  399. #define XINT(a) (((a).i << (32-VALBITS)) >> (32-VALBITS))
  400. #else
  401. #define XINT(a) ((a).s.val)
  402. #endif /* EXPLICIT_SIGN_EXTEND */
  403.  
  404. #define XUINT(a) ((a).u.val)
  405. #define XPNTR(a) ((a).u.val)
  406. #define XSETINT(a, b) ((a).s.val = (int) (b))
  407.  
  408. #define XSET(var, vartype, ptr) \
  409.    (((var).s.type = ((char) (vartype))), ((var).s.val = ((int) (ptr))))
  410.  
  411. /* During garbage collection, XGCTYPE must be used for extracting types
  412.  so that the mark bit is ignored.  XMARKBIT access the markbit.
  413.  Markbits are used only in particular slots of particular structure types.
  414.  Other markbits are always zero.
  415.  Outside of garbage collection, all mark bits are always zero.  */
  416.  
  417. #define XGCTYPE(a) ((a).gu.type)
  418. #define XMARKBIT(a) ((a).gu.markbit)
  419. #define XSETMARKBIT(a,b) (XMARKBIT(a) = (b))
  420. #define XMARK(a) (XMARKBIT(a) = 1)
  421. #define XUNMARK(a) (XMARKBIT(a) = 0)
  422.  
  423. #endif /* NO_UNION_TYPE */
  424.  
  425.  
  426. #define XCONS(a) ((struct Lisp_Cons *) XPNTR(a))
  427. #define XBUFFER(a) ((struct buffer *) XPNTR(a))
  428. #define XVECTOR(a) ((struct Lisp_Vector *) XPNTR(a))
  429. #define XSUBR(a) ((struct Lisp_Subr *) XPNTR(a))
  430. #define XSTRING(a) ((struct Lisp_String *) XPNTR(a))
  431. #define XSYMBOL(a) ((struct Lisp_Symbol *) XPNTR(a))
  432. #define XMARKER(a) ((struct Lisp_Marker *) XPNTR(a))
  433. #define XOBJFWD(a) ((Lisp_Object *) XPNTR(a))
  434. #define XINTPTR(a) ((int *) XPNTR(a))
  435. #define XWINDOW(a) ((struct window *) XPNTR(a))
  436. #define XEXTENT(a) ((EXTENT) XPNTR(a))
  437. #define XEXTENT_REPLICA(a) ((EXTENT_REPLICA) XPNTR(a))
  438. #define XPROCESS(a) ((struct Lisp_Process *) XPNTR(a))
  439. #ifdef LISP_FLOAT_TYPE
  440. #define XFLOAT(a) ((struct Lisp_Float *) XPNTR(a))
  441. #else
  442. #define XFLOAT(a) --- error!  No float support. ---
  443. #endif
  444. #define XEVENT(a) ((struct Lisp_Event *) XPNTR(a))
  445. #define XKEYMAP(a) ((struct Lisp_Keymap *) XPNTR(a))
  446.  
  447.  
  448. /* In a cons, the markbit of the car is the gc mark bit */
  449.  
  450. struct Lisp_Cons
  451.   {
  452.     Lisp_Object car, cdr;
  453.   };
  454.  
  455. /* In a string or vector, the sign bit of the `size' is the gc mark bit */
  456.  
  457. struct Lisp_String
  458.   {
  459.     int size;
  460.     Lisp_Object dup_list;
  461.     unsigned char *data;
  462.   };
  463.  
  464. struct Lisp_Vector
  465.   {
  466.     int size;
  467.     struct Lisp_Vector *next;
  468.     Lisp_Object contents[1];
  469.   };
  470.  
  471. /* In a symbol, the markbit of the plist is used as the gc mark bit */
  472.  
  473. struct Lisp_Symbol
  474.   {
  475.     struct Lisp_String *name;
  476.     Lisp_Object value;
  477.     Lisp_Object function;
  478.     Lisp_Object plist;
  479.     struct Lisp_Symbol *next;    /* -> next symbol in this obarray bucket */
  480.   };
  481. /* next symbol in this obarray bucket */
  482. #define symbol_next(s) ((s)->next)
  483.  
  484. struct Lisp_Subr
  485.   {
  486.     Lisp_Object (*function) ();
  487.     short min_args, max_args;
  488.     char *symbol_name;
  489.     char *prompt;
  490.     char *doc;
  491.   };
  492. #define subr_function(subr) (subr)->function
  493. #define subr_name(subr) (subr)->symbol_name
  494.  
  495. /* In a marker, the markbit of the chain field is used as the gc mark bit */
  496.  
  497. struct Lisp_Marker
  498.   {
  499.     struct buffer *buffer;
  500.     Lisp_Object chain;
  501.     int bufpos;
  502. #if 0
  503.     int modified;
  504. #endif
  505.   };
  506.  
  507. #ifdef LISP_FLOAT_TYPE
  508. struct Lisp_Float
  509.   {
  510.     Lisp_Object type;        /* essentially used for mark-bit 
  511.                    and chaining when on free-list */
  512.     double data;  
  513.   };
  514. #endif /* LISP_FLOAT_TYPE */
  515.  
  516. /* These structures are defined elsewhere, but assert that they name global
  517.    structures so that we can use pointers to them in prototypes. */
  518. struct Lisp_Event;
  519. struct Lisp_Process;
  520.  
  521.  
  522. #ifdef emacs /* gdb doesn't like this */
  523.  
  524. /* A character, declared with the following typedef, is a member
  525.    of some character set associated with the current buffer. */
  526. typedef unsigned char UCHAR;
  527.  
  528. #endif /* emacs */
  529.  
  530. /* A UCHAR is displayed on a given terminal by means of a
  531.    sequence of one or more GLYPHs.
  532.    A GLYPH is something that takes
  533.    up exactly one display position on the screen.  */
  534. typedef unsigned short GLYPH;
  535.  
  536. /* Meanings of slots in a Lisp_Compiled:  */
  537.  
  538. #define COMPILED_ARGLIST 0
  539. #define COMPILED_BYTECODE 1
  540. #define COMPILED_CONSTANTS 2
  541. #define COMPILED_STACK_DEPTH 3
  542. #define COMPILED_DOC_STRING 4
  543. #define COMPILED_INTERACTIVE 5
  544.  
  545. /* Data type checking */
  546.  
  547. #define NILP(x)  (XFASTINT (x) == XFASTINT (Qnil))
  548.  
  549. #define CONSP(x) (XTYPE ((x)) == Lisp_Cons)
  550. #define SYMBOLP(x) (XTYPE ((x)) == Lisp_Symbol)
  551. #define FIXNUMP(x) (XTYPE ((x)) == Lisp_Int)
  552. #define MARKERP(x) (XTYPE ((x)) == Lisp_Marker)
  553. #define STRINGP(x) (XTYPE ((x)) == Lisp_String)
  554. #define VECTORP(x) (XTYPE ((x)) == Lisp_Vector)
  555. #define SUBRP(x) (XTYPE ((x)) == Lisp_Subr)
  556. #define PROCESSP(x) (XTYPE ((x)) == Lisp_Process)
  557. #define BUFFERP(x) (XTYPE ((x)) == Lisp_Buffer)
  558. #define WINDOWP(x) (XTYPE ((x)) == Lisp_Window)
  559. #define SCREENP(x) (XTYPE ((x)) == Lisp_Screen)
  560. #define KEYMAPP(x) (XTYPE ((x)) == Lisp_Keymap)
  561. #define COMPILEDP(x) (XTYPE ((x)) == Lisp_Compiled)
  562. #define EVENTP(x) (XTYPE ((x)) == Lisp_Event)
  563. #define EXTENTP(x) (XTYPE ((x)) == Lisp_Extent)
  564. #define EXTENT_REPLICA_P(x) (XTYPE ((x)) == Lisp_Extent_Replica)
  565.  
  566. #ifdef LISP_FLOAT_TYPE
  567. #define FLOATP(x) (XTYPE ((x)) == Lisp_Float)
  568. #define NUMBERP(x) (FIXNUMP (x) || FLOATP (x))
  569. #else
  570. #define FLOATP(x) --- error! no float support. ---
  571. #define NUMBERP(x) (FIXNUMP (x))
  572. #endif
  573.  
  574. #define EQ(x, y) (XFASTINT (x) == XFASTINT (y))
  575.  
  576. #ifdef emacs
  577.  
  578. #define CHECK_LIST(x, i) \
  579.   { if ((!CONSP ((x))) && !NILP (x)) x = wrong_type_argument (Qlistp, (x)); }
  580.  
  581. #define CHECK_STRING(x, i) \
  582.   { if (!STRINGP ((x))) x = wrong_type_argument (Qstringp, (x)); }
  583.  
  584. #define CHECK_CONS(x, i) \
  585.   { if (!CONSP ((x))) x = wrong_type_argument (Qconsp, (x)); }
  586.  
  587. #define CHECK_SYMBOL(x, i) \
  588.   { if (!SYMBOLP ((x))) x = wrong_type_argument (Qsymbolp, (x)); }
  589.  
  590. #define CHECK_VECTOR(x, i) \
  591.   { if (!VECTORP ((x))) x = wrong_type_argument (Qvectorp, (x)); }
  592.  
  593. #define CHECK_BUFFER(x, i) \
  594.   { if (!BUFFERP ((x))) x = wrong_type_argument (Qbufferp, (x)); }
  595.  
  596. #define CHECK_WINDOW(x, i) \
  597.   { if (!WINDOWP ((x))) x = wrong_type_argument (Qwindowp, (x)); }
  598.  
  599. #define CHECK_EXTENT(x, i) \
  600.   { if (!EXTENTP ((x))) x = wrong_type_argument (Qextentp, (x)); }
  601.  
  602. #define CHECK_EXTENT_REPLICA(x, i) \
  603.   { if (!EXTENT_REPLICA_P ((x))) \
  604.       x = wrong_type_argument (Qextent_replica_p, (x)); }
  605.  
  606. #define CHECK_PROCESS(x, i) \
  607.   { if (!PROCESSP ((x))) x = wrong_type_argument (Qprocessp, (x)); }
  608.  
  609. #define CHECK_EVENT(x, i) \
  610.   { if (!EVENTP ((x))) x = wrong_type_argument (Qeventp, (x)); }
  611.  
  612. #define CHECK_KEYMAP(x, i) \
  613.   { if (!KEYMAPP ((x))) x = wrong_type_argument (Qkeymapp, (x)); }
  614.  
  615. #define CHECK_FIXNUM(x, i) \
  616.   { if (!FIXNUMP ((x))) x = wrong_type_argument (Qintegerp, (x)); }
  617.  
  618. #define CHECK_NUMBER(x, i)  \
  619.   { if (!NUMBERP (x)) x = wrong_type_argument (Qnumberp, (x)); }
  620.  
  621. #define CHECK_NATNUM(x, i) \
  622.   { if (!FIXNUMP ((x)) || XINT ((x)) < 0) \
  623.       x = wrong_type_argument (Qnatnump, (x)); }
  624.  
  625. #define CHECK_FIXNUM_COERCE_MARKER(x, i) \
  626.   { if (MARKERP ((x))) XFASTINT (x) = marker_position (x); \
  627.     else if (!FIXNUMP ((x))) \
  628.       x = wrong_type_argument (Qinteger_or_marker_p, (x)); }
  629.  
  630. #define CHECK_NUMBER_COERCE_MARKER(x, i) \
  631.   { if (MARKERP ((x))) XFASTINT (x) = marker_position (x); \
  632.     else if (!NUMBERP ((x))) \
  633.       x = wrong_type_argument (Qnumber_or_marker_p, (x)); }
  634.  
  635. /* The second check is looking for GCed markers still in use */
  636. #define CHECK_MARKER(x, i) \
  637.   { if (!MARKERP ((x))) x = wrong_type_argument (Qmarkerp, (x)); \
  638.     if (FIXNUMP (XMARKER ((x))->chain)) abort (); }
  639.  
  640. #ifdef LISP_FLOAT_TYPE
  641.  
  642. #ifndef DBL_DIG
  643. #define DBL_DIG 16
  644. #endif
  645.  
  646. #define CHECK_FLOAT(x, i) \
  647. { if (!FLOATP (x)) x = wrong_type_argument (Qfloatp, (x)); }
  648.  
  649. #define XFLOATINT(n) extract_float((n))
  650.  
  651. #else  /* Not LISP_FLOAT_TYPE */
  652.  
  653. #define CHECK_FLOAT(x,i) --- error! no float support. ---
  654.  
  655. #define XFLOATINT(n) XINT((n))
  656.  
  657. #endif /* LISP_FLOAT_TYPE */
  658.  
  659. #ifdef VIRT_ADDR_VARIES
  660.  
  661. /* For machines like APOLLO where text and data can go anywhere
  662.    in virtual memory.  */
  663. #define CHECK_IMPURE(obj) \
  664.   { extern int pure[]; \
  665.     if ((PNTR_COMPARISON_TYPE) XPNTR (obj) < (PNTR_COMPARISON_TYPE) ((char *) pure + PURESIZE) \
  666.     && (PNTR_COMPARISON_TYPE) XPNTR (obj) >= (PNTR_COMPARISON_TYPE) pure) \
  667.       pure_write_error (); }
  668.  
  669. #else /* not VIRT_ADDR_VARIES */
  670. #ifdef PNTR_COMPARISON_TYPE
  671.  
  672. /* when PNTR_COMPARISON_TYPE is not the default (unsigned int) */
  673. #define CHECK_IMPURE(obj) \
  674.   { extern char my_edata; \
  675.     if ((PNTR_COMPARISON_TYPE) XPNTR (obj) < (PNTR_COMPARISON_TYPE) &my_edata) \
  676.       pure_write_error (); }
  677.  
  678. #else /* not VIRT_ADDRESS_VARIES, not PNTR_COMPARISON_TYPE */
  679.  
  680. #define CHECK_IMPURE(obj) \
  681.   { extern char my_edata; \
  682.     if (XPNTR (obj) < (unsigned int) &my_edata) \
  683.       pure_write_error (); }
  684.  
  685. #endif /* PNTR_COMPARISON_TYPE */
  686. #endif /* VIRT_ADDRESS_VARIES */
  687.  
  688. /* Cast pointers to this type to compare them.  Some machines want int.  */
  689. #ifndef PNTR_COMPARISON_TYPE
  690. #define PNTR_COMPARISON_TYPE unsigned int
  691. #endif
  692.  
  693.  
  694. /* Define a built-in function for calling from Lisp.
  695.  `lname' should be the name to give the function in Lisp,
  696.     as a null-terminated C string.
  697.  `fnname' should be the name of the function in C.
  698.     By convention, it starts with F.
  699.  `sname' should be the name for the C constant structure
  700.     that records information on this function for internal use.
  701.     By convention, it should be the same as `fnname' but with S instead of F.
  702.     It's too bad that C macros can't compute this from `fnname'.
  703.  `minargs' should be a number, the minimum number of arguments allowed.
  704.  `maxargs' should be a number, the maximum number of arguments allowed,
  705.     or else MANY or UNEVALLED.
  706.     MANY means pass a vector of evaluated arguments,
  707.      in the form of an integer number-of-arguments
  708.      followed by the address of a vector of Lisp_Objects
  709.      which contains the argument values.
  710.     UNEVALLED means pass the list of unevaluated arguments
  711.  `prompt' says how to read arguments for an interactive call.
  712.     This can be zero or a C string.
  713.     Zero means that interactive calls are not allowed.
  714.     A string is interpreted in a hairy way:
  715.      it should contain one line for each argument to be read, terminated by \n.
  716.      The first character of the line controls the type of parsing:
  717.        s  --  read a string.
  718.        S  --  read a symbol.
  719.        k  --  read a key sequence and return it as a string.
  720.        a  --  read a function name (symbol) with completion.
  721.        C  --  read a command name (symbol) with completion.
  722.        v  --  read a variable name (symbol) with completion.
  723.        b  --  read a buffer name (a string) with completion.
  724.        B  --  buffer name, may be existing buffer or may not be.
  725.        f  --  read a file name, file must exist.
  726.        F  --  read a file name, file need not exist.
  727.        n  --  read a number.
  728.        c  --  read a character and return it as a number.
  729.        p  --  use the numeric value of the prefix argument.
  730.        P  --  use raw value of prefix - can be nil, -, (NUMBER) or NUMBER.
  731.        x  --  read a Lisp object from the minibuffer.
  732.        X  --  read a Lisp form from the minibuffer and use its value.
  733.     A null string means call interactively with no arguments.
  734.  `doc' is documentation for the user.
  735. */
  736.  
  737. #define DEFUN(lname, fnname, sname, minargs, maxargs, prompt, doc) \
  738.   Lisp_Object fnname (); \
  739.   struct Lisp_Subr sname = {fnname, minargs, maxargs, lname, prompt, 0}; \
  740.   Lisp_Object fnname
  741.  
  742. /* defsubr (Sname);
  743.  is how we define the symbol for function `name' at start-up time. */
  744. extern void defsubr (struct Lisp_Subr *);
  745.  
  746. #define MANY -2
  747. #define UNEVALLED -1
  748. #define SUBR_MAX_ARGS 7
  749.  
  750. extern void defvar_lisp (const char *namestring,
  751.                          Lisp_Object *address, const char *doc);
  752. extern void defvar_lisp_nopro (const char *namestring,
  753.                                Lisp_Object *address, const char *doc);
  754. extern void defvar_bool (const char *namestring,
  755.                          int *address, const char *doc);
  756. extern void defvar_int (const char *namestring,
  757.                         int *address, const char *doc);
  758.  
  759. /* Macros we use to define forwarded Lisp variables.
  760.    These are used in the syms_of_FILENAME functions.  */
  761.  
  762. #define DEFVARLISP(lname, vname, doc) defvar_lisp (lname, vname, doc)
  763. #define DEFVARBOOL(lname, vname, doc) defvar_bool (lname, vname, doc)
  764. #define DEFVARINT(lname, vname, doc) defvar_int (lname, vname, doc)
  765.  
  766. #define DEFVAR_LISP(lname, vname, doc) defvar_lisp (lname, vname, doc)
  767. #define DEFVAR_LISP_NOPRO(lname, vname, doc) \
  768.  defvar_lisp_nopro (lname, vname, doc)
  769. #define DEFVAR_BOOL(lname, vname, doc) defvar_bool (lname, vname, doc)
  770. #define DEFVAR_INT(lname, vname, doc) defvar_int (lname, vname, doc)
  771.  
  772. /* Structure for recording Lisp call stack for backtrace purposes */
  773.  
  774. struct specbinding
  775.   {
  776.     Lisp_Object symbol, old_value;
  777.     Lisp_Object (*func) ();
  778.     Lisp_Object unused;        /* Dividing by 16 is faster than by 12 */
  779.   };
  780.  
  781. extern struct specbinding *specpdl;
  782. extern struct specbinding *specpdl_ptr;
  783. extern int specpdl_depth;
  784.  
  785. struct handler
  786.   {
  787.     Lisp_Object handlers;
  788.     Lisp_Object handler_arg;
  789.     struct catchtag *tag;
  790.     struct handler *next;
  791.   };
  792.  
  793. extern struct handler *handlerlist;
  794.  
  795. /* Check quit-flag and quit if it is non-nil. */
  796.  
  797. #define QUIT \
  798.   if (!NILP (Vquit_flag) && NILP (Vinhibit_quit)) \
  799.     { Vquit_flag = Qnil; Fsignal (Qquit, Qnil); }
  800.  
  801. /* Nonzero if ought to quit now.  */
  802.  
  803. #define QUITP (!NILP (Vquit_flag) && NILP (Vinhibit_quit))
  804.  
  805. /* 1 if CH is upper case.  */
  806.  
  807. #define UPPERCASEP(CH) (XSTRING (current_buffer->downcase_table)->data[CH] != (CH))
  808.  
  809. /* 1 if CH is lower case.  */
  810.  
  811. #define LOWERCASEP(CH) \
  812.   (!UPPERCASEP (CH) && XSTRING (current_buffer->upcase_table)->data[CH] != (CH))
  813.  
  814. /* 1 if CH is neither upper nor lower case.  */
  815.  
  816. #define NOCASEP(CH) (XSTRING (current_buffer->upcase_table)->data[CH] == (CH))
  817.  
  818. /* Upcase a character, or make no change if that cannot be done.  */
  819.  
  820. #define UPCASE(CH) (XSTRING (current_buffer->downcase_table)->data[CH] == (CH) \
  821.             ? UPCASE1 (CH) : (CH))
  822.  
  823. /* Upcase a character known to be not upper case.  */
  824.  
  825. #define UPCASE1(CH) (XSTRING (current_buffer->upcase_table)->data[CH])
  826.  
  827. /* Downcase a character, or make no change if that cannot be done. */
  828.  
  829. #define DOWNCASE(CH) (XSTRING (current_buffer->downcase_table)->data[CH])
  830.  
  831. /* Current buffer's map from characters to lower-case characters.  */
  832.  
  833. #define DOWNCASE_TABLE XSTRING (current_buffer->downcase_table)->data
  834.  
  835. /* Table mapping each char to the next char with the same lowercase version.
  836.    This mapping is a no-op only for characters that don't have case.  */
  837. #define UPCASE_TABLE XSTRING (current_buffer->upcase_table)->data
  838.  
  839. extern Lisp_Object Vascii_downcase_table, Vascii_upcase_table;
  840.  
  841. /* number of bytes of structure consed since last GC */
  842.  
  843. extern int consing_since_gc;
  844.  
  845. /* threshold for doing another gc */
  846.  
  847. extern int gc_cons_threshold;
  848.  
  849. /* Structure for recording stack slots that need marking */
  850.  
  851. /* This is a chain of structures, each of which points at a Lisp_Object variable
  852.  whose value should be marked in garbage collection.
  853.  Normally every link of the chain is an automatic variable of a function,
  854.  and its `val' points to some argument or local variable of the function.
  855.  On exit to the function, the chain is set back to the value it had on entry.
  856.  This way, no link remains in the chain when the stack frame containing the link disappears.
  857.  
  858.  Every function that can call Feval must protect in this fashion all
  859.  Lisp_Object variables whose contents will be used again. */
  860.  
  861. extern struct gcpro *gcprolist;
  862.  
  863. struct gcpro
  864.   {
  865.     struct gcpro *next;
  866.     Lisp_Object *var;        /* Address of first protected variable */
  867.     int nvars;            /* Number of consecutive protected variables */
  868.   };
  869.  
  870. #ifdef DEBUG_GCPRO
  871.  
  872. extern void debug_gcpro1(), debug_gcpro2(), debug_gcpro3(), debug_gcpro4(),
  873.   debug_ungcpro();
  874.  
  875. #define GCPRO1(v) \
  876.  debug_gcpro1 (__FILE__, __LINE__,&gcpro1,&v)
  877. #define GCPRO2(v1,v2) \
  878.  debug_gcpro2 (__FILE__, __LINE__,&gcpro1,&gcpro2,&v1,&v2)
  879. #define GCPRO3(v1,v2,v3) \
  880.  debug_gcpro3 (__FILE__, __LINE__,&gcpro1,&gcpro2,&gcpro3,&v1,&v2,&v3)
  881. #define GCPRO4(v1,v2,v3,v4) \
  882.  debug_gcpro4 (__FILE__, __LINE__,&gcpro1,&gcpro2,&gcpro3,&gcpro4,\
  883.            &v1,&v2,&v3,&v4)
  884. #define UNGCPRO \
  885.  debug_ungcpro(__FILE__, __LINE__,&gcpro1)
  886.  
  887. #else /* ! DEBUG_GCPRO */
  888.  
  889. #define GCPRO1(varname) \
  890.  {gcpro1.next = gcprolist; gcpro1.var = &varname; gcpro1.nvars = 1; \
  891.   gcprolist = &gcpro1; }
  892.  
  893. #define GCPRO2(varname1, varname2) \
  894.  {gcpro1.next = gcprolist; gcpro1.var = &varname1; gcpro1.nvars = 1; \
  895.   gcpro2.next = &gcpro1; gcpro2.var = &varname2; gcpro2.nvars = 1; \
  896.   gcprolist = &gcpro2; }
  897.  
  898. #define GCPRO3(varname1, varname2, varname3) \
  899.  {gcpro1.next = gcprolist; gcpro1.var = &varname1; gcpro1.nvars = 1; \
  900.   gcpro2.next = &gcpro1; gcpro2.var = &varname2; gcpro2.nvars = 1; \
  901.   gcpro3.next = &gcpro2; gcpro3.var = &varname3; gcpro3.nvars = 1; \
  902.   gcprolist = &gcpro3; }
  903.  
  904. #define GCPRO4(varname1, varname2, varname3, varname4) \
  905.  {gcpro1.next = gcprolist; gcpro1.var = &varname1; gcpro1.nvars = 1; \
  906.   gcpro2.next = &gcpro1; gcpro2.var = &varname2; gcpro2.nvars = 1; \
  907.   gcpro3.next = &gcpro2; gcpro3.var = &varname3; gcpro3.nvars = 1; \
  908.   gcpro4.next = &gcpro3; gcpro4.var = &varname4; gcpro4.nvars = 1; \
  909.   gcprolist = &gcpro4; }
  910.  
  911. #define UNGCPRO (gcprolist = gcpro1.next)
  912.  
  913. #endif /* ! DEBUG_GCPRO */
  914.  
  915. /* Evaluate expr, UNGCPRO, and then return the value of expr.  */
  916. #define RETURN_UNGCPRO(expr)         \
  917.   do                     \
  918.     {                     \
  919.       Lisp_Object ret_ungc_val = (expr); \
  920.       UNGCPRO;                 \
  921.       return ret_ungc_val;         \
  922.     }                     \
  923.   while (0)
  924.  
  925. /* Call staticpro (&var) to protect static variable `var'. */
  926.  
  927. extern void staticpro (Lisp_Object *);
  928.  
  929. /* Nonzero means Emacs has already been initialized.
  930.    Used during startup to detect startup of dumped Emacs.  */
  931. extern int initialized;
  932.  
  933. extern int immediate_quit;       /* Nonzero means ^G can quit instantly */
  934.  
  935. #include "emacsfns.h"
  936.  
  937. #endif /* emacs */
  938.  
  939. #endif /* _EMACS_LISP_H_ */
  940.