klisp

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

koperative.c (836B)


      1 /*
      2 ** koperative.c
      3 ** Kernel Operatives
      4 ** See Copyright Notice in klisp.h
      5 */
      6 
      7 #include <stdarg.h>
      8 
      9 #include "koperative.h"
     10 #include "kobject.h"
     11 #include "kstate.h"
     12 #include "kmem.h"
     13 #include "kgc.h"
     14 
     15 /* GC: Assumes all argps are rooted */
     16 TValue kmake_operative(klisp_State *K, klisp_CFunction fn, int32_t xcount, ...)
     17 {
     18     va_list argp;
     19 
     20     Operative *new_op = (Operative *) 
     21         klispM_malloc(K, sizeof(Operative) + sizeof(TValue) * xcount);
     22 
     23     /* header + gc_fields */
     24     klispC_link(K, (GCObject *) new_op, K_TOPERATIVE, 
     25                 K_FLAG_CAN_HAVE_NAME);
     26 
     27     /* operative specific fields */
     28     new_op->fn = fn;
     29     new_op->extra_size = xcount;
     30 
     31     va_start(argp, xcount);
     32     for (int i = 0; i < xcount; i++) {
     33         new_op->extra[i] = va_arg(argp, TValue);
     34     }
     35     va_end(argp);
     36 
     37     return gc2op(new_op);
     38 }