klisp

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

commit fd4110cc2e2cf4870bef7da472e37d294f77f2fa
parent 4dbcfb476b39aacc26ec47b3f2ac7c0e29c956b0
Author: Andres Navarro <canavarro82@gmail.com>
Date:   Fri,  8 Jul 2011 17:08:24 -0300

Some content on blobs, mainly definitions.

Diffstat:
Asrc/kblob.h | 30++++++++++++++++++++++++++++++
Msrc/kobject.h | 15++++++++++++++-
Msrc/kstring.h | 12++++++------
3 files changed, 50 insertions(+), 7 deletions(-)

diff --git a/src/kblob.h b/src/kblob.h @@ -0,0 +1,30 @@ +/* +** kblob.h +** Kernel Blobs (byte vectors) +** See Copyright Notice in klisp.h +*/ + +#ifndef kblob_h +#define kblob_h + +#include "kobject.h" +#include "kstate.h" + +/* General constructor for blobs */ +TValue kblob_new_g(klisp_State *K, bool m, uint32_t size); +TValue kblob_new_imm(klisp_State *K, bool m, uint32_t size); +TValue kblob_new(klisp_State *K, bool m, uint32_t size); + +/* both obj1 and obj2 should be blobs, this compares byte by byte + and doesn't differentiate immutable from mutable blobs */ +bool kblob_equalp(TValue obj1, TValue obj2); +bool kblob(TValue obj); + +/* some macros to access the parts of the blobs */ +#define kblob_buf(tv_) (tv2blob(tv_)->b) +#define kblob_size(tv_) (tv2blob(tv_)->size) + +#define kblob_mutablep(tv_) (kis_mutable(tv_)) +#define kblob_immutablep(tv_) (kis_immutable(tv_)) + +#endif diff --git a/src/kobject.h b/src/kobject.h @@ -161,6 +161,7 @@ typedef struct __attribute__ ((__packed__)) GCheader { #define K_TPORT 39 #define K_TTABLE 40 #define K_TERROR 41 +#define K_TBLOB 42 /* for tables */ #define K_TDEADKEY 60 @@ -213,6 +214,7 @@ typedef struct __attribute__ ((__packed__)) GCheader { #define K_TAG_PORT K_MAKE_VTAG(K_TPORT) #define K_TAG_TABLE K_MAKE_VTAG(K_TTABLE) #define K_TAG_ERROR K_MAKE_VTAG(K_TERROR) +#define K_TAG_BLOB K_MAKE_VTAG(K_TBLOB) /* @@ -294,6 +296,7 @@ typedef struct __attribute__ ((__packed__)) GCheader { #define ttisport(o) (tbasetype_(o) == K_TAG_PORT) #define ttistable(o) (tbasetype_(o) == K_TAG_TABLE) #define ttiserror(o) (tbasetype_(o) == K_TAG_ERROR) +#define ttisblob(o) (tbasetype_(o) == K_TAG_BLOB) /* macros to easily check boolean values */ #define kis_true(o_) (tv_equal((o_), KTRUE)) @@ -478,6 +481,14 @@ typedef struct __attribute__ ((__packed__)) { TValue irritants; /* list of extra objs */ } Error; +/* Blobs (binary vectors) */ +typedef struct __attribute__ ((__packed__)) { + CommonHeader; + uint32_t size; + int32_t __dummy; /* for alignment to 64 bits */ + char b[]; /* buffer */ +} Blob; + /* ** `module' operation for hashing (size is always a power of 2) */ @@ -505,7 +516,7 @@ typedef struct __attribute__ ((__packed__)) { TValue mark; /* for cycle/sharing aware algorithms */ uint32_t size; uint32_t hash; /* only used for immutable strings */ - char b[]; // buffer + char b[]; /* buffer */ } String; /* MAYBE: mark fields could be replaced by a hashtable or a bit + a hashtable */ @@ -637,6 +648,7 @@ const TValue kfree; #define gc2port(o_) (gc2tv(K_TAG_PORT, o_)) #define gc2table(o_) (gc2tv(K_TAG_TABLE, o_)) #define gc2error(o_) (gc2tv(K_TAG_ERROR, o_)) +#define gc2blob(o_) (gc2tv(K_TAG_BLOB, o_)) #define gc2deadkey(o_) (gc2tv(K_TAG_DEADKEY, o_)) /* Macro to convert a TValue into a specific heap allocated object */ @@ -654,6 +666,7 @@ const TValue kfree; #define tv2port(v_) ((Port *) gcvalue(v_)) #define tv2table(v_) ((Table *) gcvalue(v_)) #define tv2error(v_) ((Error *) gcvalue(v_)) +#define tv2blob(v_) ((Blob *) gcvalue(v_)) #define tv2gch(v_) ((GCheader *) gcvalue(v_)) #define tv2mgch(v_) ((MGCheader *) gcvalue(v_)) diff --git a/src/kstring.h b/src/kstring.h @@ -17,14 +17,14 @@ /* for immutable string table */ void klispS_resize (klisp_State *K, int32_t newsize); -/* -** Constructors for immutable strings -*/ - /* General constructor for strings */ TValue kstring_new_bs_g(klisp_State *K, bool m, const char *buf, uint32_t size); +/* +** Constructors for immutable strings +*/ + /* main immutable string constructor */ /* with buffer & size */ TValue kstring_new_bs_imm(klisp_State *K, const char *buf, uint32_t size); @@ -66,6 +66,7 @@ TValue kstring_new_sf(klisp_State *K, uint32_t size, char fill); #define kstring_new_sf_imm(K_, size_, fill_) \ kstring_new_sf_g(K_, false, size_, fill_) #endif + /* some macros to access the parts of the string */ #define kstring_buf(tv_) (tv2str(tv_)->b) #define kstring_size(tv_) (tv2str(tv_)->size) @@ -75,9 +76,8 @@ TValue kstring_new_sf(klisp_State *K, uint32_t size, char fill); #define kstring_immutablep(tv_) (kis_immutable(tv_)) /* both obj1 and obj2 should be strings, this compares char by char - but differentiates immutable from mutable strings */ + and doesn't differentiate immutable from mutable strings */ bool kstring_equalp(TValue obj1, TValue obj2); - bool kstringp(TValue obj); #endif