klisp

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

commit f90a7baa42f04fd1f5539efe7d33c66e34110f55
parent 1e1e8c18bca2b7a7d8dec0583b66c8d876974c5b
Author: Andres Navarro <canavarro82@gmail.com>
Date:   Wed, 23 Mar 2011 01:52:12 -0300

Added copy-string to the ground environment.

Diffstat:
Msrc/kground.c | 2+-
Msrc/kgstrings.c | 16+++++++++++++++-
Msrc/kgstrings.h | 2+-
3 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/src/kground.c b/src/kground.c @@ -620,7 +620,7 @@ void kinit_ground_env(klisp_State *K) /* TODO */ /* 13.2.8? string-copy */ - /* TODO */ + add_applicative(K, ground_env, "string-copy", string_copy, 0); /* 13.2.9? string-fill! */ add_applicative(K, ground_env, "string-fill!", string_fillS, 0); diff --git a/src/kgstrings.c b/src/kgstrings.c @@ -122,7 +122,21 @@ void string_setS(klisp_State *K, TValue *xparams, TValue ptree, TValue denv) /* TODO */ /* 13.2.8? string-copy */ -/* TODO */ +void string_copy(klisp_State *K, TValue *xparams, TValue ptree, TValue denv) +{ + UNUSED(xparams); + UNUSED(denv); + bind_1tp(K, "string-copy", ptree, "string", ttisstring, str); + + TValue new_str; + /* the if isn't strictly necessary but it's clearer this way */ + if (tv_equal(str, K->empty_string)) { + new_str = str; + } else { + new_str = kstring_new(K, kstring_buf(str), kstring_size(str)); + } + kapply_cc(K, new_str); +} /* 13.2.9? string-fill! */ void string_fillS(klisp_State *K, TValue *xparams, TValue ptree, TValue denv) diff --git a/src/kgstrings.h b/src/kgstrings.h @@ -56,7 +56,7 @@ void string_setS (klisp_State *K, TValue *xparams, TValue ptree, TValue denv); /* TODO */ /* 13.2.8? string-copy */ -/* TODO */ +void string_copy(klisp_State *K, TValue *xparams, TValue ptree, TValue denv); /* 13.2.9? string-fill! */ void string_fillS(klisp_State *K, TValue *xparams, TValue ptree, TValue denv);