klisp

an open source interpreter for the Kernel Programming Language.
git clone http://git.hanabi.in/repos/klisp.git
Log | Files | Refs | README

klimits.h (3306B)


      1 /*
      2 ** klimits.h
      3 ** Limits, basic types, and some other `installation-dependent' definitions
      4 ** See Copyright Notice in klisp.h
      5 */
      6 
      7 /*
      8 ** SOURCE NOTE: this is from lua (greatly reduced)
      9 */
     10 
     11 #ifndef klimits_h
     12 #define klimits_h
     13 
     14 #include <limits.h>
     15 #include <stddef.h>
     16 
     17 #ifdef KUSE_ASSERTS
     18 #include <assert.h>
     19 #define klisp_assert(c) (assert(c))
     20 #endif
     21 #include "klisp.h"
     22 
     23 /* internal assertions for in-house debugging */
     24 #ifdef klisp_assert
     25 
     26 #define check_exp(c,e)		(klisp_assert(c), (e))
     27 
     28 #else
     29 
     30 #define klisp_assert(c)		((void)(c))
     31 #define check_exp(c,e)		(e)
     32 
     33 #endif
     34 
     35 
     36 #ifndef UNUSED
     37 #define UNUSED(x)	((void)(x))	/* to avoid warnings */
     38 #endif
     39 
     40 #ifndef cast
     41 #define cast(t, exp)	((t)(exp))
     42 #endif
     43 
     44 /*
     45 ** conversion of pointer to integer
     46 ** this is for hashing only; there is no problem if the integer
     47 ** cannot hold the whole pointer value
     48 */
     49 #define IntPoint(p)  ((uint32_t)(p))
     50 
     51 /* minimum size for the string table (must be power of 2) */
     52 #ifndef MINSTRTABSIZE
     53 #define MINSTRTABSIZE	32
     54 #endif
     55 
     56 /* minimum size for the name & cont_name tables (must be power of 2) */
     57 #ifndef MINNAMETABSIZE
     58 #define MINNAMETABSIZE	32
     59 #endif
     60 
     61 #ifndef MINCONTNAMETABSIZE
     62 #define MINCONTNAMETABSIZE	32
     63 #endif
     64 
     65 #ifndef MINTHREADTABSIZE
     66 #define MINTHREADTABSIZE	32
     67 #endif
     68 
     69 /* minimum size for the require table (must be power of 2) */
     70 #ifndef MINREQUIRETABSIZE
     71 #define MINREQUIRETABSIZE	32
     72 #endif
     73 
     74 /* starting size for ground environment hashtable */
     75 /* at last count, there were about 200 bindings in ground env */
     76 #define ENVTABSIZE	512
     77 
     78 /* starting size for string port buffers */
     79 #ifndef MINSTRINGPORTBUFFER
     80 #define MINSTRINGPORTBUFFER	256
     81 #endif
     82 
     83 /* starting size for bytevector port buffers */
     84 #ifndef MINBYTEVECTORPORTBUFFER
     85 #define MINBYTEVECTORPORTBUFFER	256
     86 #endif
     87 
     88 /* starting size for readline buffer */
     89 #ifndef MINREADLINEBUFFER
     90 #define MINREADLINEBUFFER	80
     91 #endif
     92 
     93 /* XXX for now ignore the return values */
     94 #ifndef klisp_lock
     95 #include <pthread.h>
     96 #define klisp_lock(K) ({                                    \
     97             if (K->gil_count == 0) {                        \
     98                 K->gil_count = 1;                           \
     99                 UNUSED(pthread_mutex_lock(&G(K)->gil));     \
    100             } else {                                        \
    101                 ++K->gil_count;                             \
    102             }})
    103 
    104 #define klisp_unlock(K) ({                                  \
    105             if (K->gil_count <= 1) {                        \
    106                 K->gil_count = 0;                           \
    107                 UNUSED(pthread_mutex_unlock(&G(K)->gil));   \
    108             } else {                                        \
    109                 --K->gil_count;                             \
    110             }})
    111 
    112 /* this will work no matter how many times  (even 0) the lock was acquired */
    113 #define klisp_unlock_all(K) ({                          \
    114             if (K->gil_count > 0) {                     \
    115                 K->gil_count = 1;                       \
    116                 klisp_unlock(K);                        \
    117             }})
    118 
    119 #endif
    120 
    121 /* These were the original defines */
    122 #ifndef klisp_lock
    123 #define klisp_lock(K)     ((void) 0) 
    124 #define klisp_unlock(K)   ((void) 0)
    125 #endif
    126 
    127 #ifndef klispi_threadyield
    128 #define klispi_threadyield(K)     {klisp_unlock(K); klisp_lock(K);}
    129 #endif
    130 
    131 #endif