klisp

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

commit d52c9b26037f44d57d15725f8c79a1f8a837648e
parent d14d0e6aa65b3ab23a3da953301764c8e0742831
Author: Andres Navarro <canavarro82@gmail.com>
Date:   Thu,  3 Mar 2011 18:51:30 -0300

Added continuation constructor. Changed some continuation fields in kobject.h

Diffstat:
Msrc/Makefile | 8+++++---
Asrc/kcontinuation.c | 36++++++++++++++++++++++++++++++++++++
Asrc/kcontinuation.h | 17+++++++++++++++++
Msrc/kenvironment.c | 2+-
Msrc/kobject.h | 4++++
5 files changed, 63 insertions(+), 4 deletions(-)

diff --git a/src/Makefile b/src/Makefile @@ -8,7 +8,8 @@ MYLDFLAGS= MYLIBS= CORE_O= kobject.o ktoken.o kpair.o kstring.o ksymbol.o kread.o \ - kwrite.o kstate.o kmem.o kerror.o kauxlib.o kenvironment.o + kwrite.o kstate.o kmem.o kerror.o kauxlib.o kenvironment.o \ + kcontinuation.o KRN_T= klisp KRN_O= klisp.o @@ -48,4 +49,5 @@ kmem.o: kmem.c kmem.h klisp.h kerror.h kerror.o: kerror.c kerror.h klisp.h kstate.h kauxlib.o: kauxlib.c kauxlib.h klisp.h kstate.h kenvironment.o: kenvironment.c kenvironment.h kpair.h kobject.h kerror.h \ - kmem.h kstate.h -\ No newline at end of file + kmem.h kstate.h +kcontinuation.o: kcontinuation.c kcontinuation.h kmem.h kstate.h kobject.h +\ No newline at end of file diff --git a/src/kcontinuation.c b/src/kcontinuation.c @@ -0,0 +1,36 @@ +/* +** kcontinuation.c +** Kernel Continuations +** See Copyright Notice in klisp.h +*/ + +#include <stdarg.h> + +#include "kcontinuation.h" +#include "kobject.h" +#include "kstate.h" +#include "kmem.h" + +TValue kmake_continuation(klisp_State *K, TValue parent, TValue name, + TValue si, klisp_Ifunc fn, int32_t xcount, ...) +{ + va_list argp; + Continuation *new_cont = klispM_malloc(K, sizeof(Continuation) + + sizeof(TValue) * xcount); + new_cont->next = NULL; + new_cont->gct = 0; + new_cont->tt = K_TCONTINUATION; + new_cont->mark = KFALSE; + new_cont->name = name; + new_cont->si = si; + new_cont->parent = parent; + new_cont->fn = fn; + new_cont->extra_size = xcount; + + va_start(argp, xcount); + for (int i = 0; i < xcount; i++) { + new_cont->extra[i] = va_arg(argp, TValue); + } + va_end(argp); + return gc2cont(new_cont); +} diff --git a/src/kcontinuation.h b/src/kcontinuation.h @@ -0,0 +1,17 @@ +/* +** kcontinuation.h +** Kernel Continuations +** See Copyright Notice in klisp.h +*/ + +#ifndef kcontinuation_h +#define kcontinuation_h + +#include "kobject.h" +#include "kstate.h" + +/* TODO: make some specialized constructors for 0, 1 and 2 parameters */ +TValue kmake_continuation(klisp_State *K, TValue parent, TValue name, + TValue si, klisp_Ifunc fn, int xcount, ...); + +#endif diff --git a/src/kenvironment.c b/src/kenvironment.c @@ -1,5 +1,5 @@ /* -** kenvironmment.c +** kenvironment.c ** Kernel Environments ** See Copyright Notice in klisp.h */ diff --git a/src/kobject.h b/src/kobject.h @@ -246,8 +246,10 @@ typedef void (*klisp_Ifunc) (TValue *ud, TValue val, TValue env); typedef struct __attribute__ ((__packed__)) { CommonHeader; + TValue mark; /* for guarding continuation */ TValue name; /* cont name/type */ TValue si; /* source code info (either () or (filename line col) */ + TValue parent; /* may be () for root continuation */ klisp_Ifunc fn; /* the function that does the work */ int32_t extra_size; TValue extra[]; @@ -361,12 +363,14 @@ const TValue keminf; #define gc2str(o_) (gc2tv(K_TAG_STRING, o_)) #define gc2sym(o_) (gc2tv(K_TAG_SYMBOL, o_)) #define gc2env(o_) (gc2tv(K_TAG_ENVIRONMENT, o_)) +#define gc2cont(o_) (gc2tv(K_TAG_CONTINUATION, o_)) /* Macro to convert a TValue into a specific heap allocated object */ #define tv2pair(v_) ((Pair *) gcvalue(v_)) #define tv2str(v_) ((String *) gcvalue(v_)) #define tv2sym(v_) ((Symbol *) gcvalue(v_)) #define tv2env(v_) ((Environment *) gcvalue(v_)) +#define tv2cont(v_) ((Continuation *) gcvalue(v_)) #define tv2mgch(v_) ((MGCheader *) gcvalue(v_))