klisp

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

commit cba5b0fd23a245318366ac131e76169d37ee94dd
parent 28dbb9c6e746e9b6cd942b33ac63e662efa6429f
Author: Andres Navarro <canavarro82@gmail.com>
Date:   Sun, 20 Mar 2011 03:48:57 -0300

Added negative?, positive?, odd? & even? to the ground environment.

Diffstat:
Msrc/kgnumbers.c | 18++++++++++++++++++
Msrc/kgnumbers.h | 17+++++++++++++++++
Msrc/kground.c | 19+++++++++++++++++++
3 files changed, 54 insertions(+), 0 deletions(-)

diff --git a/src/kgnumbers.c b/src/kgnumbers.c @@ -227,3 +227,21 @@ void kminus(klisp_State *K, TValue *xparams, TValue ptree, TValue denv) /* Helper for zero? */ bool kzerop(TValue n) { return kfast_zerop(n); } + +/* 12.5.8 div, mod, div-and-mod */ +/* TODO */ + +/* 12.5.9 div0, mod0, div0-and-mod0 */ +/* TODO */ + +/* 12.5.10 positive?, negative? */ +/* use ftyped_predp */ + +/* 12.5.10 odd?, even? */ +/* use ftyped_predp */ + +/* Helpers for positive?, negative?, odd? & even? */ +bool kpositivep(TValue n) { return ivalue(n) > 0; } +bool knegativep(TValue n) { return ivalue(n) < 0; } +bool koddp(TValue n) { return (ivalue(n) & 1) != 0; } +bool kevenp(TValue n) { return (ivalue(n) & 1) == 0; } diff --git a/src/kgnumbers.h b/src/kgnumbers.h @@ -62,6 +62,23 @@ void kminus(klisp_State *K, TValue *xparams, TValue ptree, TValue denv); /* Helper for zero? */ bool kzerop(TValue n); +/* 12.5.8 div, mod, div-and-mod */ +/* TODO */ + +/* 12.5.9 div0, mod0, div0-and-mod0 */ +/* TODO */ + +/* 12.5.10 positive?, negative? */ +/* use ftyped_predp */ + +/* 12.5.10 odd?, even? */ +/* use ftyped_predp */ + +/* Helpers for positive?, negative?, odd? & even? */ +bool kpositivep(TValue n); +bool knegativep(TValue n); +bool koddp(TValue n); +bool kevenp(TValue n); /* Misc Helpers */ inline bool kfast_zerop(TValue n) { return ttisfixint(n) && ivalue(n) == 0; } diff --git a/src/kground.c b/src/kground.c @@ -521,6 +521,25 @@ void kinit_ground_env(klisp_State *K) add_applicative(K, ground_env, "zero?", ftyped_predp, 3, symbol, p2tv(knumberp), p2tv(kzerop)); + /* 12.5.8 div, mod, div-and-mod */ + /* TODO */ + + /* 12.5.9 div0, mod0, div0-and-mod0 */ + /* TODO */ + + /* 12.5.10 positive?, negative? */ + add_applicative(K, ground_env, "positive?", ftyped_predp, 3, symbol, + p2tv(knumberp), p2tv(kpositivep)); + add_applicative(K, ground_env, "negative?", ftyped_predp, 3, symbol, + p2tv(knumberp), p2tv(knegativep)); + + /* 12.5.11 odd?, even? */ + add_applicative(K, ground_env, "odd?", ftyped_predp, 3, symbol, + p2tv(kintegerp), p2tv(koddp)); + add_applicative(K, ground_env, "even?", ftyped_predp, 3, symbol, + p2tv(kintegerp), p2tv(kevenp)); + + /* ... TODO */ /*