klisp

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

kobject.c (2969B)


      1 /*
      2 ** kobject.c
      3 ** Type definitions for Kernel Objects
      4 ** See Copyright Notice in klisp.h
      5 */
      6 
      7 #include "kobject.h"
      8 
      9 #ifdef KTRACK_MARKS
     10 int32_t kmark_count = 0;
     11 #endif
     12 /*
     13 ** The global const variables
     14 */
     15 const TValue knil = KNIL_;
     16 const TValue kignore = KIGNORE_;
     17 const TValue kinert = KINERT_;
     18 const TValue keof = KEOF_;
     19 const TValue ktrue = KTRUE_;
     20 const TValue kfalse = KFALSE_;
     21 const TValue kepinf = KEPINF_;
     22 const TValue keminf = KEMINF_;
     23 const TValue kipinf = KIPINF_;
     24 const TValue kiminf = KIMINF_;
     25 const TValue krwnpv = KRWNPV_;
     26 const TValue kundef = KUNDEF_;
     27 const TValue kfree = KFREE_;
     28 
     29 const TValue knull = KNULL_;
     30 const TValue kalarm = KALARM_;
     31 const TValue kbackspace = KBACKSPACE_;
     32 const TValue ktab = KTAB_;
     33 const TValue knewline = KNEWLINE_;
     34 const TValue kreturn = KRETURN_;
     35 const TValue kescape = KESCAPE_;
     36 const TValue kspace = KSPACE_;
     37 const TValue kdelete = KDELETE_;
     38 const TValue kvtab = KVTAB_;
     39 const TValue kformfeed = KFORMFEED_;
     40 
     41 /*
     42 ** The name strings for all TValue types
     43 ** This should be updated if types are modified in kobject.h
     44 */
     45 char *ktv_names[] = {
     46     [K_TFIXINT] = "fixint",
     47     [K_TBIGINT] = "bigint", 
     48     [K_TFIXRAT] = "fixrat", 
     49     [K_TBIGRAT] = "bigrat", 
     50     [K_TEINF] = "einf", 
     51     [K_TDOUBLE] = "double", 
     52     [K_TBDOUBLE] = "bdouble", 
     53     [K_TIINF] = "einf", 
     54     [K_TIINF] = "iinf", 
     55     
     56     [K_TRWNPV] = "rwnpv", 
     57     [K_TCOMPLEX] = "complex", 
     58     [K_TUNDEFINED] = "undefined", 
     59 
     60     [K_TNIL] = "nil",          
     61     [K_TIGNORE] = "ignore",
     62     [K_TINERT] = "inert", 
     63     [K_TEOF] = "eof", 
     64     [K_TBOOLEAN] = "boolean", 
     65     [K_TCHAR] = "char", 
     66     [K_TFREE] = "free entry", 
     67     [K_TDEADKEY] = "dead key", 
     68 
     69     [K_TUSER] = "user pointer", 
     70 
     71     [K_TPAIR] = "pair", 
     72     [K_TSTRING] = "string", 
     73     [K_TSYMBOL] = "symbol",
     74     [K_TENVIRONMENT] = "environment",
     75     [K_TCONTINUATION] = "continuation",
     76     [K_TOPERATIVE] = "operative",
     77     [K_TAPPLICATIVE] = "applicative",
     78     [K_TENCAPSULATION] = "encapsulation",
     79     [K_TPROMISE] = "promise",
     80     [K_TTABLE] = "table", 
     81     [K_TERROR] = "error", 
     82     [K_TBYTEVECTOR] = "bytevector",
     83     [K_TFPORT] = "file port",
     84     [K_TMPORT] = "mem port",
     85     [K_TKEYWORD] = "keyword",
     86     [K_TLIBRARY] = "library"
     87 };
     88 
     89 int32_t klispO_log2 (uint32_t x) {
     90     static const uint8_t log_2[256] = {
     91         0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
     92         6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
     93         7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
     94         7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
     95         8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
     96         8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
     97         8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
     98         8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8
     99     };
    100     int32_t l = -1;
    101     while (x >= 256) { l += 8; x >>= 8; }
    102     return l + log_2[x];
    103 }