klisp

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

kauxlib.c (725B)


      1 /*
      2 ** kauxlib.h
      3 ** Auxiliary functions for klisp
      4 ** See Copyright Notice in klisp.h
      5 */
      6 
      7 /*
      8 ** SOURCE NOTE: this is from lua, but is greatly reduced (for now)
      9 */
     10 
     11 #include <stddef.h>
     12 #include <stdlib.h>
     13 
     14 #include "klisp.h"
     15 #include "kstate.h"
     16 
     17 /* generic alloc function */
     18 static void *k_alloc (void *ud, void *ptr, size_t osize, size_t nsize) {
     19     (void)ud;
     20     (void)osize;
     21 
     22     if (nsize == 0) {
     23         free(ptr);
     24         return NULL;
     25     } else {
     26         return realloc(ptr, nsize);
     27     }
     28 }
     29 
     30 /*
     31 ** Create a new state with the default allocator
     32 */
     33 klisp_State *klispL_newstate (void)
     34 {
     35     klisp_State *K = klisp_newstate(k_alloc, NULL);
     36     /* TODO: set any panic functions or something like that... */
     37     return K;
     38 }
     39