klisp

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

commit e6b4234760def6982fbbe9cca46cecfe7003802e
parent 72d5129b0105a16cc9370a358fdf8a601307c144
Author: Andres Navarro <canavarro82@gmail.com>
Date:   Tue,  6 Dec 2011 20:04:51 -0300

Added write support for keywords.

Diffstat:
Msrc/Makefile | 2+-
Msrc/kwrite.c | 22+++++++++++++++++-----
2 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/src/Makefile b/src/Makefile @@ -300,7 +300,7 @@ kvector.o: kvector.c kvector.h kobject.h klimits.h klisp.h klispconf.h \ kstate.h ktoken.h kmem.h kgc.h kwrite.o: kwrite.c kwrite.h kobject.h klimits.h klisp.h klispconf.h \ kstate.h ktoken.h kmem.h kinteger.h imath.h krational.h imrat.h kreal.h \ - kpair.h kgc.h kstring.h ksymbol.h kerror.h ktable.h kport.h \ + kpair.h kgc.h kstring.h ksymbol.h kkeyword.h kerror.h ktable.h kport.h \ kenvironment.h kbytevector.h kvector.h ktoken.h imath.o: imath.c imath.h kobject.h klimits.h klisp.h klispconf.h kstate.h \ ktoken.h kmem.h kerror.h kpair.h kgc.h diff --git a/src/kwrite.c b/src/kwrite.c @@ -20,6 +20,7 @@ #include "kpair.h" #include "kstring.h" #include "ksymbol.h" +#include "kkeyword.h" #include "kstate.h" #include "kerror.h" #include "ktable.h" @@ -237,16 +238,13 @@ void kw_print_string(klisp_State *K, TValue str) } /* -** Helper for printing symbols. +** Helper for printing symbols & keywords. ** If symbol is not a regular identifier it ** uses the "|...|" syntax, escaping '|', '\' and ** non printing characters. */ -void kw_print_symbol(klisp_State *K, TValue sym) +void kw_print_symbol_buf(klisp_State *K, char *buf, uint32_t size) { - uint32_t size = ksymbol_size(sym); - char *buf = ksymbol_buf(sym); - /* first determine if it's a simple identifier */ bool identifierp; if (size == 0) @@ -325,6 +323,17 @@ void kw_print_symbol(klisp_State *K, TValue sym) kw_printf(K, "|"); } +void kw_print_symbol(klisp_State *K, TValue sym) +{ + kw_print_symbol_buf(K, ksymbol_buf(sym), ksymbol_size(sym)); +} + +void kw_print_keyword(klisp_State *K, TValue keyw) +{ + kw_printf(K, "#:"); + kw_print_symbol_buf(K, kkeyword_buf(keyw), kkeyword_size(keyw)); +} + /* ** Mark initialization and clearing */ @@ -565,6 +574,9 @@ void kwrite_scalar(klisp_State *K, TValue obj) case K_TSYMBOL: kw_print_symbol(K, obj); break; + case K_TKEYWORD: + kw_print_keyword(K, obj); + break; case K_TINERT: kw_printf(K, "#inert"); break;