X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fnasal%2Fdata.h;h=a2c023ef2fd324e9ca366a3c61ef239d55a38491;hb=66193d728365098783e56a292541f01e9a4c57ca;hp=7c851be590c28b884552f25f26a4130e6ab41a39;hpb=de6003367d006218782d64b5c0da4d8c8ea8ede0;p=simgear.git diff --git a/simgear/nasal/data.h b/simgear/nasal/data.h index 7c851be5..a2c023ef 100644 --- a/simgear/nasal/data.h +++ b/simgear/nasal/data.h @@ -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,8 +77,7 @@ 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) @@ -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; @@ -157,7 +160,15 @@ struct naFunc { struct naCCode { GC_HEADER; - naCFunction fptr; + union { + naCFunction fptr; //