X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fnasal%2Fdata.h;h=deb4fbdc194abd2618edb510d3cbbb8b0aef750c;hb=bcb320b537b6f7e5e3724e8a30d309322171eb43;hp=3c5a23b0c15e4cec2638c7c90d760a6be969ee94;hpb=b05e32fa8c11e6d66bb70850751e170dc472a1a3;p=simgear.git diff --git a/simgear/nasal/data.h b/simgear/nasal/data.h index 3c5a23b0..deb4fbdc 100644 --- a/simgear/nasal/data.h +++ b/simgear/nasal/data.h @@ -9,7 +9,7 @@ // bitmask that sets the top 16 bits. As a double, this is a // signalling NaN that cannot itself be produced by normal numerics // code. The pointer value can be reconstructed if (and only if) we -// are guaranteed that all memory that can be poitned to by a naRef +// are guaranteed that all memory that can be pointed to by a naRef // (i.e. all memory returned by naAlloc) lives in the bottom 48 bits // of memory. Linux on x86_64, Win64, Solaris and Irix all have such // policies with address spaces: @@ -49,10 +49,11 @@ // On 32 bit systems where the pointer is half the width of the // double, we store a special magic number in the structure to make -// the double a NaN. This must appear in the top bits of the double, +// the double a qNaN. This must appear in the top bits of the double, // which is why the structure layout is endianness-dependent. +// qNaN (quiet NaNs) use range 0x7ff80000-0x7fffffff -#define NASAL_REFTAG 0x7ff56789 // == 2,146,789,257 decimal +#define NASAL_REFTAG 0x7fff6789 // == 2,147,444,617 decimal #define IS_REF(r) ((r).ref.reftag == NASAL_REFTAG) #define PTR(r) ((r).ref.ptr) @@ -76,13 +77,12 @@ enum { T_STR, T_VEC, T_HASH, T_CODE, T_FUNC, T_CCODE, T_GHOST, #define IS_GHOST(r) (IS_OBJ(r) && PTR(r).obj->type == T_GHOST) #define IS_CONTAINER(r) (IS_VEC(r)||IS_HASH(r)) #define IS_SCALAR(r) (IS_NUM(r) || IS_STR(r)) -#define IDENTICAL(a, b) (IS_REF(a) && IS_REF(b) \ - && PTR(a).obj == PTR(b).obj) +#define IDENTICAL(a, b) (IS_REF(a) && IS_REF(b) && PTR(a).obj == PTR(b).obj) #define MUTABLE(r) (IS_STR(r) && PTR(r).str->hashcode == 0) // This is a macro instead of a separate struct to allow compilers to -// avoid padding. GCC on x86, at least, will always padd the size of +// avoid padding. GCC on x86, at least, will always pad the size of // an embedded struct up to 32 bits. Doing it this way allows the // implementing objects to pack in 16 bits worth of data "for free". #define GC_HEADER \ @@ -93,11 +93,18 @@ struct naObj { GC_HEADER; }; +#define MAX_STR_EMBLEN 15 struct naStr { GC_HEADER; - int len; - unsigned char* data; + char emblen; /* [0-15], or -1 to indicate "not embedded" */ unsigned int hashcode; + union { + unsigned char buf[16]; + struct { + int len; + unsigned char* ptr; + } ref; + } data; }; struct VecRec { @@ -117,14 +124,6 @@ struct HashNode { struct HashNode* next; }; -struct HashRec { - int size; - int dels; - int lgalloced; - struct HashNode* nodes; - struct HashNode* table[]; -}; - struct naHash { GC_HEADER; struct HashRec* rec; @@ -132,22 +131,26 @@ struct naHash { struct naCode { GC_HEADER; - unsigned char nArgs; - unsigned char nOptArgs; - unsigned char needArgVector; + unsigned int nArgs : 5; + unsigned int nOptArgs : 5; + unsigned int needArgVector : 1; unsigned short nConstants; - unsigned short nLines; unsigned short codesz; - unsigned short* byteCode; - naRef* constants; - int* argSyms; // indices into constants - int* optArgSyms; - int* optArgVals; - unsigned short* lineIps; // pairs of {ip, line} + unsigned short restArgSym; // The "..." vector name, defaults to "arg" + unsigned short nLines; naRef srcFile; - naRef restArgSym; // The "..." vector name, defaults to "arg" + naRef* constants; }; +/* naCode objects store their variable length arrays in a single block + * starting with their constants table. Compute indexes at runtime + * for space efficiency: */ +#define BYTECODE(c) ((unsigned short*)((c)->constants+(c)->nConstants)) +#define ARGSYMS(c) (BYTECODE(c)+(c)->codesz) +#define OPTARGSYMS(c) (ARGSYMS(c)+(c)->nArgs) +#define OPTARGVALS(c) (OPTARGSYMS(c)+(c)->nOptArgs) +#define LINEIPS(c) (OPTARGVALS(c)+(c)->nOptArgs) + struct naFunc { GC_HEADER; naRef code; @@ -194,17 +197,19 @@ int naStr_parsenum(char* str, int len, double* result); int naStr_tonum(naRef str, double* out); naRef naStr_buf(naRef str, int len); -int naHash_tryset(naRef hash, naRef key, naRef val); // sets if exists -int naHash_sym(struct naHash* h, struct naStr* sym, naRef* out); -void naHash_newsym(struct naHash* h, naRef* sym, naRef* val); +int naiHash_tryset(naRef hash, naRef key, naRef val); // sets if exists +int naiHash_sym(struct naHash* h, struct naStr* sym, naRef* out); +void naiHash_newsym(struct naHash* h, naRef* sym, naRef* val); void naGC_init(struct naPool* p, int type); struct naObj** naGC_get(struct naPool* p, int n, int* nout); void naGC_swapfree(void** target, void* val); void naGC_freedead(); +void naiGCMark(naRef r); +void naiGCMarkHash(naRef h); void naStr_gcclean(struct naStr* s); void naVec_gcclean(struct naVec* s); -void naHash_gcclean(struct naHash* s); +void naiGCHashClean(struct naHash* h); #endif // _DATA_H