klisp

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

commit 226e61b5a24d6cdbbc9d9e5ca193acc1dfebd52f
parent 7a54a5f90c20153360bcf59a56682ba2d524ba54
Author: Andres Navarro <canavarro82@gmail.com>
Date:   Wed, 22 Aug 2012 01:15:36 -0300

Added thread? and get-current-thread applicatives to the ground environment.

Diffstat:
Msrc/Makefile | 8++++++--
Msrc/kground.c | 2++
Asrc/kgthreads.c | 50++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/kgthreads.h | 16++++++++++++++++
4 files changed, 74 insertions(+), 2 deletions(-)

diff --git a/src/Makefile b/src/Makefile @@ -56,7 +56,7 @@ CORE_O= kobject.o ktoken.o kpair.o kstring.o ksymbol.o kread.o \ kgenvironments.o kgenv_mut.o kgcombiners.o kgcontinuations.o \ kgencapsulations.o kgpromises.o kgkd_vars.o kgks_vars.o kgports.o \ kgchars.o kgnumbers.o kgstrings.o kgbytevectors.o kgvectors.o \ - kgtables.o kgsystem.o kgerrors.o kgkeywords.o \ + kgtables.o kgsystem.o kgerrors.o kgkeywords.o kgthreads.o \ $(if $(USE_LIBFFI),kgffi.o) # TEMP: in klisp there is no distinction between core & lib @@ -265,7 +265,7 @@ kground.o: kground.c kstate.h klimits.h klisp.h kobject.h klispconf.h \ kgcombiners.h kgcontinuations.h kgencapsulations.h kgpromises.h \ kgkd_vars.h kgks_vars.h kgnumbers.h kgstrings.h kgchars.h kgports.h \ kgbytevectors.h kgvectors.h kgtables.h kgsystem.h kgerrors.h \ - kgkeywords.h kglibraries.h kgffi.h keval.h krepl.h + kgkeywords.h kglibraries.h kgthreads.h kgffi.h keval.h krepl.h kgstrings.o: kgstrings.c kstate.h klimits.h klisp.h kobject.h klispconf.h \ ktoken.h kmem.h kapplicative.h koperative.h kcontinuation.h kerror.h \ kpair.h kgc.h ksymbol.h kstring.h kchar.h kvector.h kbytevector.h \ @@ -282,6 +282,10 @@ kgtables.o: kgtables.c kstate.h klimits.h klisp.h kobject.h klispconf.h \ ktoken.h kmem.h kapplicative.h koperative.h kcontinuation.h kerror.h \ kpair.h kgc.h kghelpers.h kvector.h kenvironment.h ksymbol.h kstring.h \ ktable.h kgtables.h +kgthreads.o: kgthreads.c kstate.h klimits.h klisp.h kobject.h klispconf.h \ + ktoken.h kmem.h kghelpers.h kerror.h kpair.h kgc.h kvector.h \ + kapplicative.h koperative.h kcontinuation.h kenvironment.h ksymbol.h \ + kstring.h ktable.h kgvectors.o: kgvectors.c kstate.h klimits.h klisp.h kobject.h klispconf.h \ ktoken.h kmem.h kapplicative.h koperative.h kcontinuation.h kerror.h \ kpair.h kgc.h kvector.h kbytevector.h kghelpers.h kenvironment.h \ diff --git a/src/kground.c b/src/kground.c @@ -42,6 +42,7 @@ #include "kgerrors.h" #include "kgkeywords.h" #include "kglibraries.h" +#include "kgthreads.h" #if KUSE_LIBFFI # include "kgffi.h" @@ -124,6 +125,7 @@ void kinit_ground_env(klisp_State *K) kinit_error_ground_env(K); kinit_keywords_ground_env(K); kinit_libraries_ground_env(K); + kinit_threads_ground_env(K); #if KUSE_LIBFFI kinit_ffi_ground_env(K); #endif diff --git a/src/kgthreads.c b/src/kgthreads.c @@ -0,0 +1,50 @@ +/* +** kgstrings.c +** Strings features for the ground environment +** See Copyright Notice in klisp.h +*/ + +#include <assert.h> +#include <stdlib.h> +#include <stdbool.h> +#include <stdint.h> + +#include "kstate.h" +#include "kobject.h" + +#include "kghelpers.h" + +/* ?.1? thread? */ +/* uses typep */ + +/* ?.2? get-current-thread */ +static void get_current_thread(klisp_State *K) +{ + TValue *xparams = K->next_xparams; + TValue ptree = K->next_value; + TValue denv = K->next_env; + klisp_assert(ttisenvironment(K->next_env)); + UNUSED(xparams); + UNUSED(denv); + check_0p(K, ptree); + kapply_cc(K, gc2th(K)); +} + +/* init ground */ +void kinit_threads_ground_env(klisp_State *K) +{ + TValue ground_env = G(K)->ground_env; + TValue symbol, value; + + /* + ** This section is still missing from the report. The bindings here are + ** taken from a mix of scheme implementations and the pthreads library + */ + + /* ?.1? thread? */ + add_applicative(K, ground_env, "thread?", typep, 2, symbol, + i2tv(K_TTHREAD)); + + /* ?.2? get-current-thread */ + add_applicative(K, ground_env, "get-current-thread", get_current_thread, 0); +} diff --git a/src/kgthreads.h b/src/kgthreads.h @@ -0,0 +1,16 @@ +/* +** kgthreads.h +** Threads features for the ground environment +** See Copyright Notice in klisp.h +*/ + +#ifndef kgthreads_h +#define kgthreads_h + +#include "kstate.h" + +/* init ground */ +void kinit_threads_ground_env(klisp_State *K); + +#endif +