klisp

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

commit 4220b3288dea3f805274c8a7d5f3bc13bfbbb843
parent e1a2beb5435794502beec95a9e66edb366e1b7ae
Author: Andres Navarro <canavarro82@gmail.com>
Date:   Tue,  5 Apr 2011 16:19:12 -0300

Added dummy char-ready? to the ground environment. (TODO: actually check if there are waiting chars, this dummy version always returns true).

Diffstat:
Msrc/kgports.c | 32++++++++++++++++++++++++++------
Msrc/kgports.h | 2+-
Msrc/kground.c | 2+-
3 files changed, 28 insertions(+), 8 deletions(-)

diff --git a/src/kgports.c b/src/kgports.c @@ -302,17 +302,37 @@ void read_peek_char(klisp_State *K, TValue *xparams, TValue ptree, /* 15.1.? read-char */ -/* TODO */ +/* uses read_peek_char */ /* 15.1.? peek-char */ -/* TODO */ +/* uses read_peek_char */ /* 15.1.? char-ready? */ -/* TODO */ /* XXX: this always return #t, proper behaviour requires platform - specific code (probably select for posix, a thread for windows - (at least for files & consoles), I think pipes and sockets may - have something */ + specific code (probably select for posix & a thread for windows + (at least for files & consoles, I think pipes and sockets may + have something) */ +void char_readyp(klisp_State *K, TValue *xparams, TValue ptree, TValue denv) +{ + UNUSED(xparams); + UNUSED(denv); + + TValue port = ptree; + if (!get_opt_tpar(K, "char-ready?", K_TPORT, &port)) { + port = kcdr(K->kd_in_port_key); /* access directly */ + } else if (!kport_is_input(port)) { + klispE_throw(K, "char-ready?: the port should be an input port"); + return; + } + if (kport_is_closed(port)) { + klispE_throw(K, "char-ready?: the port is already closed"); + return; + } + + /* TODO: check if there are pending chars */ + kapply_cc(K, KTRUE); +} + /* 15.2.1 call-with-input-file, call-with-output-file */ /* XXX: The report is incomplete here... for now use an empty environment, diff --git a/src/kgports.h b/src/kgports.h @@ -64,11 +64,11 @@ void read_peek_char(klisp_State *K, TValue *xparams, TValue ptree, /* uses read_peek_char */ /* 15.1.? char-ready? */ -/* TODO */ /* XXX: this always return #t, proper behaviour requires platform specific code (probably select for posix, a thread for windows (at least for files & consoles), I think pipes and sockets may have something */ +void char_readyp(klisp_State *K, TValue *xparams, TValue ptree, TValue denv); /* 15.2.1 call-with-input-file, call-with-output-file */ void call_with_file(klisp_State *K, TValue *xparams, TValue ptree, diff --git a/src/kground.c b/src/kground.c @@ -972,11 +972,11 @@ void kinit_ground_env(klisp_State *K) b2tv(true)); /* 15.1.? char-ready? */ - /* TODO */ /* XXX: this always return #t, proper behaviour requires platform specific code (probably select for posix, a thread for windows (at least for files & consoles), I think pipes and sockets may have something */ + add_applicative(K, ground_env, "char-ready?", char_readyp, 0); /* ** 15.2 Library features