commit 3031b5beebbb874a4689498567e25180057ccf02
parent e6b4234760def6982fbbe9cca46cecfe7003802e
Author: Andres Navarro <canavarro82@gmail.com>
Date: Tue, 6 Dec 2011 20:35:48 -0300
Added ground combiners for keywords (type predicate + conversion to and from strings and symbols).
Diffstat:
5 files changed, 26 insertions(+), 23 deletions(-)
diff --git a/src/Makefile b/src/Makefile
@@ -36,12 +36,12 @@ CORE_O= kobject.o ktoken.o kpair.o kstring.o ksymbol.o kread.o \
kcontinuation.o koperative.o kapplicative.o keval.o krepl.o \
kencapsulation.o kpromise.o kport.o kinteger.o krational.o ksystem.o \
kreal.o ktable.o kgc.o imath.o imrat.o kbytevector.o kvector.o \
- kchar.o ksymbol.o kground.o kghelpers.o kgbooleans.o kgeqp.o \
+ kchar.o kkeyword.o kground.o kghelpers.o kgbooleans.o kgeqp.o \
kgequalp.o kgsymbols.o kgcontrol.o kgpairs_lists.o kgpair_mut.o \
kgenvironments.o kgenv_mut.o kgcombiners.o kgcontinuations.o \
kgencapsulations.o kgpromises.o kgkd_vars.o kgks_vars.o kgports.o \
kgchars.o kgnumbers.o kgstrings.o kgbytevectors.o kgvectors.o \
- kgsystem.o kgerrors.o \
+ kgsystem.o kgerrors.o kgkeywords.o \
$(if $(USE_LIBFFI),kgffi.o)
# TEMP: in klisp there is no distinction between core & lib
@@ -237,6 +237,10 @@ kgsymbols.o: kgsymbols.c kstate.h klimits.h klisp.h kobject.h klispconf.h \
ktoken.h kmem.h kcontinuation.h kpair.h kgc.h kstring.h ksymbol.h \
kerror.h kghelpers.h kapplicative.h koperative.h kenvironment.h ktable.h \
kgsymbols.h
+kgkeywords.o: kgkeywords.c kgkeywords.h kstate.h klimits.h klisp.h kobject.h \
+ klispconf.h ktoken.h kmem.h kcontinuation.h kpair.h kgc.h kstring.h \
+ ksymbol.h kerror.h kghelpers.h kapplicative.h koperative.h kenvironment.h \
+ ktable.h kkeyword.h
kgsystem.o: kgsystem.c kstate.h klimits.h klisp.h kobject.h klispconf.h \
ktoken.h kmem.h kpair.h kgc.h kerror.h ksystem.h kghelpers.h \
kapplicative.h koperative.h kcontinuation.h kenvironment.h ksymbol.h \
diff --git a/src/kgkeywords.h b/src/kgkeywords.h
@@ -0,0 +1,15 @@
+/*
+** kgkeywords.h
+** Keyword features for the ground environment
+** See Copyright Notice in klisp.h
+*/
+
+#ifndef kgkeywords_h
+#define kgkeywords_h
+
+#include "kstate.h"
+
+/* init ground */
+void kinit_keywords_ground_env(klisp_State *K);
+
+#endif
diff --git a/src/kground.c b/src/kground.c
@@ -39,6 +39,7 @@
#include "kgvectors.h"
#include "kgsystem.h"
#include "kgerrors.h"
+#include "kgkeywords.h"
#if KUSE_LIBFFI
# include "kgffi.h"
@@ -116,6 +117,7 @@ void kinit_ground_env(klisp_State *K)
kinit_vectors_ground_env(K);
kinit_system_ground_env(K);
kinit_error_ground_env(K);
+ kinit_keywords_ground_env(K);
#if KUSE_LIBFFI
kinit_ffi_ground_env(K);
#endif
diff --git a/src/kgsymbols.c b/src/kgsymbols.c
@@ -41,16 +41,6 @@ void symbol_to_string(klisp_State *K)
}
/* 13.3.2? string->symbol */
-/* TEMP: for now this can create symbols with no external representation
- this includes all symbols with non identifiers characters.
-*/
-/* NOTE:
- Symbols with uppercase alphabetic characters will write as lowercase and
- so, when read again will not compare as either eq? or equal?. This is ok
- because the report only says that read objects when written and read
- again must be equal? which happens here
-*/
-/* If the string is mutable it is copied */
void string_to_symbol(klisp_State *K)
{
TValue *xparams = K->next_xparams;
@@ -61,6 +51,7 @@ void string_to_symbol(klisp_State *K)
UNUSED(denv);
bind_1tp(K, ptree, "string", ttisstring, str);
/* TODO si */
+ /* If the string is mutable it is copied */
TValue new_sym = ksymbol_new_str(K, str, KNIL);
kapply_cc(K, new_sym);
}
@@ -74,21 +65,12 @@ void kinit_symbols_ground_env(klisp_State *K)
/* 4.4.1 symbol? */
add_applicative(K, ground_env, "symbol?", typep, 2, symbol,
i2tv(K_TSYMBOL));
- /*
+ /*
** This section is still missing from the report. The bindings here are
** taken from r5rs scheme and should not be considered standard.
*/
/* ?.?.1? symbol->string */
add_applicative(K, ground_env, "symbol->string", symbol_to_string, 0);
/* ?.?.2? string->symbol */
- /* TEMP: for now this can create symbols with no external representation
- this includes all symbols with non identifiers characters.
- */
- /* NOTE:
- Symbols with uppercase alphabetic characters will write as lowercase and
- so, when read again will not compare as either eq? or equal?. This is ok
- because the report only says that read objects when written and read
- again must be equal? which happens here
- */
add_applicative(K, ground_env, "string->symbol", string_to_symbol, 0);
}
diff --git a/src/kkeyword.c b/src/kkeyword.c
@@ -41,7 +41,7 @@ TValue kkeyword_new_bs(klisp_State *K, const char *buf, int32_t size)
if (ts->size == size && (memcmp(buf, ts->b, size) == 0)) {
/* keyword and/or string may be dead */
if (isdead(K, o)) changewhite(o);
- if (isdead(K, (Object *) ts)) changewhite((Object *) ts);
+ if (isdead(K, (GCObject *) ts)) changewhite((GCObject *) ts);
return gc2keyw(o);
}
}