klisp

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

commit e3539cf770682df26b98bc7ae9b84e4774dc9dcd
parent 58aa1bb5f9a376eb6448f5249ffc12f377559641
Author: Andres Navarro <canavarro82@gmail.com>
Date:   Tue,  6 Dec 2011 19:19:01 -0300

Added keyword type definition to kobject & kgc.

Diffstat:
Msrc/kgc.c | 18+++++++++++++++---
Msrc/kobject.h | 17+++++++++++++++++
2 files changed, 32 insertions(+), 3 deletions(-)

diff --git a/src/kgc.c b/src/kgc.c @@ -100,6 +100,7 @@ static void reallymarkobject (klisp_State *K, GCObject *o) break; case K_TPAIR: case K_TSYMBOL: + case K_TKEYWORD: case K_TSTRING: case K_TENVIRONMENT: case K_TCONTINUATION: @@ -261,6 +262,11 @@ static int32_t propagatemark (klisp_State *K) { markvalue(K, s->str); return sizeof(Symbol); } + case K_TKEYWORD: { + Keyword *k = cast(Keyword *, o); + markvalue(K, k->str); + return sizeof(Keyword); + } case K_TSTRING: { String *s = cast(String *, o); markvalue(K, s->mark); @@ -432,6 +438,12 @@ static void freeobj (klisp_State *K, GCObject *o) { K->strt.nuse--; klispM_free(K, (Symbol *)o); break; + case K_TKEYWORD: + /* keywords are in the string table */ + /* The string will be freed before/after */ + K->strt.nuse--; + klispM_free(K, (Keyword *)o); + break; case K_TSTRING: /* immutable strings are in the string/symbol table */ if (kstring_immutablep(gc2str(o))) @@ -580,7 +592,7 @@ void klispC_freeall (klisp_State *K) { K->currentwhite = WHITEBITS | bitmask(SFIXEDBIT); /* in klisp this may not be necessary */ sweepwholelist(K, &K->rootgc); - /* free all symbol/string/bytevectors lists */ + /* free all keyword/symbol/string/bytevectors lists */ for (int32_t i = 0; i < K->strt.size; i++) sweepwholelist(K, &K->strt.hash[i]); } @@ -811,8 +823,8 @@ void klispC_barrierback (klisp_State *K, Table *t) { } /* NOTE: kflags is added for klisp */ -/* NOTE: symbols, immutable strings and immutable bytevectors do this - "by hand", they don't call this */ +/* NOTE: symbols, keywords, immutable strings and immutable bytevectors do + this "by hand", they don't call this */ void klispC_link (klisp_State *K, GCObject *o, uint8_t tt, uint8_t kflags) { o->gch.next = K->rootgc; K->rootgc = o; diff --git a/src/kobject.h b/src/kobject.h @@ -168,6 +168,7 @@ typedef struct __attribute__ ((__packed__)) GCheader { #define K_TFPORT 42 #define K_TMPORT 43 #define K_TVECTOR 44 +#define K_TKEYWORD 45 /* for tables */ #define K_TDEADKEY 60 @@ -223,6 +224,7 @@ typedef struct __attribute__ ((__packed__)) GCheader { #define K_TAG_FPORT K_MAKE_VTAG(K_TFPORT) #define K_TAG_MPORT K_MAKE_VTAG(K_TMPORT) #define K_TAG_VECTOR K_MAKE_VTAG(K_TVECTOR) +#define K_TAG_KEYWORD K_MAKE_VTAG(K_TKEYWORD) /* ** Macros to test types @@ -322,6 +324,7 @@ typedef struct __attribute__ ((__packed__)) GCheader { #define ttisport(o_) ({ int32_t t_ = tbasetype_(o_); \ t_ == K_TAG_FPORT || t_ == K_TAG_MPORT;}) #define ttisvector(o) (tbasetype_(o) == K_TAG_VECTOR) +#define ttiskeyword(o) (tbasetype_(o) == K_TAG_KEYWORD) /* macros to easily check boolean values */ #define kis_true(o_) (tv_equal((o_), KTRUE)) @@ -536,6 +539,17 @@ typedef struct __attribute__ ((__packed__)) { TValue array[]; /* array of elements */ } Vector; +/* Unlike symbols, keywords can be marked because they don't record + source info */ +typedef struct __attribute__ ((__packed__)) { + CommonHeader; /* symbols are marked via their strings */ + TValue mark; /* for cycle/sharing aware algorithms */ + TValue str; /* could use String * here, but for now... */ + uint32_t hash; /* this is different from the symbol & string hash + to avoid having the string, the symbol, and the + keyword always falling in the same bucket */ +} Keyword; + /* ** `module' operation for hashing (size is always a power of 2) */ @@ -598,6 +612,7 @@ union GCObject { FPort fport; MPort mport; Vector vector; + Keyword keyw; }; @@ -712,6 +727,7 @@ const TValue kfree; #define gc2error(o_) (gc2tv(K_TAG_ERROR, o_)) #define gc2bytevector(o_) (gc2tv(K_TAG_BYTEVECTOR, o_)) #define gc2vector(o_) (gc2tv(K_TAG_VECTOR, o_)) +#define gc2keyw(o_) (gc2tv(K_TAG_KEYWORD, o_)) #define gc2deadkey(o_) (gc2tv(K_TAG_DEADKEY, o_)) /* Macro to convert a TValue into a specific heap allocated object */ @@ -733,6 +749,7 @@ const TValue kfree; #define tv2fport(v_) ((FPort *) gcvalue(v_)) #define tv2mport(v_) ((MPort *) gcvalue(v_)) #define tv2port(v_) ((Port *) gcvalue(v_)) +#define tv2keyw(v_) ((Keyword *) gcvalue(v_)) #define tv2gch(v_) ((GCheader *) gcvalue(v_)) #define tv2mgch(v_) ((MGCheader *) gcvalue(v_))