klisp

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

kpromise.c (678B)


      1 /*
      2 ** kpromise.c
      3 ** Kernel Promises
      4 ** See Copyright Notice in klisp.h
      5 */
      6 
      7 #include "kobject.h"
      8 #include "kstate.h"
      9 #include "kpromise.h"
     10 #include "kpair.h"
     11 #include "kmem.h"
     12 #include "kgc.h"
     13 
     14 /* GC: Assumes exp & maybe_env are roooted */
     15 TValue kmake_promise(klisp_State *K, TValue exp, TValue maybe_env)
     16 {
     17     Promise *new_prom = klispM_new(K, Promise);
     18 
     19     /* header + gc_fields */
     20     klispC_link(K, (GCObject *) new_prom, K_TPROMISE, 0);
     21 
     22     /* promise specific fields */
     23     new_prom->node = KNIL; /* temp in case of GC */
     24     krooted_tvs_push(K, gc2prom(new_prom));
     25     new_prom->node = kcons(K, exp, maybe_env);
     26     krooted_tvs_pop(K);
     27     return gc2prom(new_prom);
     28 }