klisp

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

kencapsulation.c (820B)


      1 /*
      2 ** kencapsulation.c
      3 ** Kernel Encapsulation Types
      4 ** See Copyright Notice in klisp.h
      5 */
      6 
      7 #include "kobject.h"
      8 #include "kmem.h"
      9 #include "kstate.h"
     10 #include "kencapsulation.h"
     11 #include "kpair.h"
     12 #include "kgc.h"
     13 
     14 bool kis_encapsulation_type(TValue enc, TValue key)
     15 {
     16     return ttisencapsulation(enc) && tv_equal(kget_enc_key(enc), key);
     17 }
     18 
     19 /* GC: Assumes that key & val are rooted */
     20 TValue kmake_encapsulation(klisp_State *K, TValue key, TValue val)
     21 {
     22     Encapsulation *new_enc = klispM_new(K, Encapsulation);
     23 
     24     /* header + gc_fields */
     25     klispC_link(K, (GCObject *) new_enc, K_TENCAPSULATION, 0);
     26 
     27     /* encapsulation specific fields */
     28     new_enc->key = key;
     29     new_enc->value = val;
     30 
     31     return gc2enc(new_enc);
     32 }
     33 
     34 TValue kmake_encapsulation_key(klisp_State *K)
     35 {
     36     return kcons(K, KINERT, KINERT);
     37 }