klisp

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

commit 47035f4886166583d84ffaae29f95edb1ac0334c
parent 4d1f83db67b92f2e444b26a9b7412160764e90b2
Author: Andres Navarro <canavarro82@gmail.com>
Date:   Wed, 23 Mar 2011 00:02:02 -0300

Added string-set! to the ground environment.

Diffstat:
Msrc/kground.c | 8++++----
Msrc/kgstrings.c | 25+++++++++++++++++++++----
Msrc/kgstrings.h | 8++++----
3 files changed, 29 insertions(+), 12 deletions(-)

diff --git a/src/kground.c b/src/kground.c @@ -583,16 +583,16 @@ void kinit_ground_env(klisp_State *K) i2tv(K_TSTRING)); /* 13.1.2? make-string */ - add_applicative(K, ground_env, "make-string", kgmake_string, 0); + add_applicative(K, ground_env, "make-string", make_string, 0); /* 13.1.3? string-length */ - add_applicative(K, ground_env, "string-length", kgstring_length, 0); + add_applicative(K, ground_env, "string-length", string_length, 0); /* 13.1.4? string-ref */ - add_applicative(K, ground_env, "string-ref", kstring_ref, 0); + add_applicative(K, ground_env, "string-ref", string_ref, 0); /* 13.1.5? string-set! */ - /* TODO */ + add_applicative(K, ground_env, "string-set!", string_setS, 0); /* ** 13.2 Library features diff --git a/src/kgstrings.c b/src/kgstrings.c @@ -27,7 +27,7 @@ /* uses typep */ /* 13.1.2? make-string */ -void kgmake_string(klisp_State *K, TValue *xparams, TValue ptree, TValue denv) +void make_string(klisp_State *K, TValue *xparams, TValue ptree, TValue denv) { UNUSED(xparams); UNUSED(denv); @@ -48,7 +48,7 @@ void kgmake_string(klisp_State *K, TValue *xparams, TValue ptree, TValue denv) } /* 13.1.3? string-length */ -void kgstring_length(klisp_State *K, TValue *xparams, TValue ptree, +void string_length(klisp_State *K, TValue *xparams, TValue ptree, TValue denv) { UNUSED(xparams); @@ -60,7 +60,7 @@ void kgstring_length(klisp_State *K, TValue *xparams, TValue ptree, } /* 13.1.4? string-ref */ -void kstring_ref(klisp_State *K, TValue *xparams, TValue ptree, TValue denv) +void string_ref(klisp_State *K, TValue *xparams, TValue ptree, TValue denv) { UNUSED(xparams); UNUSED(denv); @@ -80,7 +80,24 @@ void kstring_ref(klisp_State *K, TValue *xparams, TValue ptree, TValue denv) } /* 13.1.5? string-set! */ -/* TODO */ +void string_setS(klisp_State *K, TValue *xparams, TValue ptree, TValue denv) +{ + UNUSED(xparams); + UNUSED(denv); + bind_3tp(K, "string-set!", ptree, "string", ttisstring, str, + "finite integer", ttisfixint, tv_i, "char", ttischar, tv_ch); + + int32_t i = ivalue(tv_i); + + if (i < 0 || i >= kstring_size(str)) { + /* TODO show index */ + klispE_throw(K, "string-set!: index out of bounds"); + return; + } + + kstring_buf(str)[i] = chvalue(tv_ch); + kapply_cc(K, KINERT); +} /* 13.2.1? string */ /* TODO */ diff --git a/src/kgstrings.h b/src/kgstrings.h @@ -22,17 +22,17 @@ /* uses typep */ /* 13.1.2? make-string */ -void kgmake_string(klisp_State *K, TValue *xparams, TValue ptree, TValue denv); +void make_string(klisp_State *K, TValue *xparams, TValue ptree, TValue denv); /* 13.1.3? string-length */ -void kgstring_length(klisp_State *K, TValue *xparams, TValue ptree, +void string_length(klisp_State *K, TValue *xparams, TValue ptree, TValue denv); /* 13.1.4? string-ref */ -void kstring_ref (klisp_State *K, TValue *xparams, TValue ptree, TValue denv); +void string_ref (klisp_State *K, TValue *xparams, TValue ptree, TValue denv); /* 13.1.5? string-set! */ -/* TODO */ +void string_setS (klisp_State *K, TValue *xparams, TValue ptree, TValue denv); /* 13.2.1? string */ /* TODO */