klisp

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

commit ef72093ba723f1d9592e0b21399d774b00ebd939
parent a7031fb36626cda9e2fa0e9f9c199d549792b1e8
Author: Andres Navarro <canavarro82@gmail.com>
Date:   Tue, 22 Mar 2011 23:52:18 -0300

Added string-length to the ground environment.

Diffstat:
Msrc/kground.c | 5++---
Msrc/kgstrings.c | 11++++++++++-
Msrc/kgstrings.h | 3++-
3 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/src/kground.c b/src/kground.c @@ -583,11 +583,10 @@ void kinit_ground_env(klisp_State *K) i2tv(K_TSTRING)); /* 13.1.2? make-string */ - add_applicative(K, ground_env, "make-string", kgmake_string, 2, symbol, - i2tv(K_TSTRING)); + add_applicative(K, ground_env, "make-string", kgmake_string, 0); /* 13.1.3? string-length */ - /* TODO */ + add_applicative(K, ground_env, "string-length", kgstring_length, 0); /* 13.1.4? string-ref */ /* TODO */ diff --git a/src/kgstrings.c b/src/kgstrings.c @@ -48,7 +48,16 @@ void kgmake_string(klisp_State *K, TValue *xparams, TValue ptree, TValue denv) } /* 13.1.3? string-length */ -/* TODO */ +void kgstring_length(klisp_State *K, TValue *xparams, TValue ptree, + TValue denv) +{ + UNUSED(xparams); + UNUSED(denv); + bind_1tp(K, "string-length", ptree, "string", ttisstring, str); + + TValue res = i2tv(kstring_size(str)); + kapply_cc(K, res); +} /* 13.1.4? string-ref */ /* TODO */ diff --git a/src/kgstrings.h b/src/kgstrings.h @@ -25,7 +25,8 @@ void kgmake_string(klisp_State *K, TValue *xparams, TValue ptree, TValue denv); /* 13.1.3? string-length */ -/* TODO */ +void kgstring_length(klisp_State *K, TValue *xparams, TValue ptree, + TValue denv); /* 13.1.4? string-ref */ /* TODO */