issue #195 lua 5.4 object.h layout for easier comparison

lua54-tables
Dibyendu Majumdar 4 years ago
parent d2b9810a06
commit d2a295688f

@ -1,5 +1,5 @@
/*
** $Id: lobject.h,v 2.117.1.1 2017/04/19 17:39:34 roberto Exp $
** $Id: lobject.h $
** Type definitions for Lua objects
** See Copyright Notice in lua.h
*/
@ -27,57 +27,8 @@
*/
#define LUA_TOTALTAGS (LUA_TPROTO + 2)
/*
** tags for Tagged Values have the following use of bits:
** bits 0-3: actual tag (a LUA_T* value)
** bits 4-5: variant bits
** bit 6: whether value is collectable
*/
/*
** LUA_TFUNCTION variants:
** 0 - Lua function
** 1 - light C function
** 2 - regular C function (closure)
** 4 - fast light C dunction (Ravi extension)
*/
/* Variant tags for functions */
#define LUA_TLCL (LUA_TFUNCTION | (0 << 4)) /* Lua closure */
#define LUA_TLCF (LUA_TFUNCTION | (1 << 4)) /* light C function */
#define LUA_TCCL (LUA_TFUNCTION | (2 << 4)) /* C closure */
#define RAVI_TFCF (LUA_TFUNCTION | (4 << 4)) /* fast light C function */
/* Variant tags for strings */
#define LUA_TSHRSTR (LUA_TSTRING | (0 << 4)) /* short strings */
#define LUA_TLNGSTR (LUA_TSTRING | (1 << 4)) /* long strings */
/* Variant tags for numbers */
#define LUA_TNUMFLT (LUA_TNUMBER | (0 << 4)) /* float numbers */
#define LUA_TNUMINT (LUA_TNUMBER | (1 << 4)) /* integer numbers */
/** RAVI table subtypes **/
#define RAVI_TIARRAY (LUA_TTABLE | (1 << 4)) /* Ravi int array */
#define RAVI_TFARRAY (LUA_TTABLE | (2 << 4)) /* Ravi float array */
/* Bit mark for collectable types */
#define BIT_ISCOLLECTABLE (1 << 15)
/* mark a tag as collectable */
#define ctb(t) ((t) | BIT_ISCOLLECTABLE)
/*
** Common type for all collectable objects
*/
typedef struct GCObject GCObject;
/*
** Value type extended to 16-bits so that we can hold more info.
** In Ravi, value type is extended to 16-bits so that we can hold more info.
** The actual type code is still 1 byte (least significant byte)
** and in particular all GC-able type codes must fit into 1 byte because
** the GC CommonHeader only allows 1 byte for the type code.
@ -87,21 +38,35 @@ typedef struct GCObject GCObject;
typedef uint16_t LuaType;
/*
** Common Header for all collectable objects (in macro form, to be
** included in other objects)
** Note that tt field is a byte - this means that a GC object's
** type must have all information in the first byte
** tags for Tagged Values have the following use of bits:
** bits 0-3: actual tag (a LUA_T* value)
** bits 4-5: variant bits
** bit 15: whether value is collectable
*/
#define CommonHeader GCObject *next; lu_byte tt; lu_byte marked
/* add variant bits to a type */
#define makevariant(t,v) ((t) | ((v) << 4))
/*
** Common type has only the common header
*/
struct GCObject {
CommonHeader;
};
/* RAVI: Following are the types we will use
** use in parsing. The rationale for types is
** performance - as of now these are the only types that
** we care about from a performance point of view - if any
** other types appear then they are all treated as ANY
**/
typedef enum {
RAVI_TANY = 0, /* Lua dynamic type */
RAVI_TNUMINT = 1, /* integer number */
RAVI_TNUMFLT, /* floating point number */
RAVI_TARRAYINT, /* array of ints */
RAVI_TARRAYFLT, /* array of doubles */
RAVI_TFUNCTION, /* Lua or C Function */
RAVI_TTABLE, /* Lua table */
RAVI_TSTRING, /* string */
RAVI_TNIL, /* NIL */
RAVI_TBOOLEAN, /* boolean */
RAVI_TUSERDATA /* userdata or lightuserdata */
} ravitype_t;
@ -114,7 +79,7 @@ struct GCObject {
** Union of all Lua values
*/
typedef union Value {
GCObject *gc; /* collectable objects */
struct GCObject *gc; /* collectable objects */
void *p; /* light userdata */
int b; /* booleans */
lua_CFunction f; /* light C functions */
@ -123,8 +88,12 @@ typedef union Value {
} Value;
#define TValuefields Value value_; LuaType tt_
/*
** Tagged Values. This is the basic representation of values in Lua:
** an actual value plus a tag with its type.
*/
#define TValuefields Value value_; LuaType tt_
typedef struct lua_TValue {
TValuefields;
@ -132,9 +101,6 @@ typedef struct lua_TValue {
/* macro defining a nil value */
#define NILCONSTANT {NULL}, LUA_TNIL
#define val_(o) ((o)->value_)
@ -156,200 +122,196 @@ typedef struct lua_TValue {
/* Macros to test type */
#define checktag(o,t) (rttype(o) == (t))
#define checktype(o,t) (ttnov(o) == (t))
#define ttisnumber(o) checktype((o), LUA_TNUMBER)
#define ttisfloat(o) checktag((o), LUA_TNUMFLT)
#define ttisinteger(o) checktag((o), LUA_TNUMINT)
#define ttisnil(o) checktag((o), LUA_TNIL)
#define ttisboolean(o) checktag((o), LUA_TBOOLEAN)
#define ttislightuserdata(o) checktag((o), LUA_TLIGHTUSERDATA)
#define ttisstring(o) checktype((o), LUA_TSTRING)
#define ttisshrstring(o) checktag((o), ctb(LUA_TSHRSTR))
#define ttislngstring(o) checktag((o), ctb(LUA_TLNGSTR))
/* RAVI change: we support two sub types of table type
and hence need to distinguish between the types.
ttistable() returns true for all table types
ttisLtable() only returns true if the value is a Lua table
ttisiarray() only returns true if the value is a Ravi subtype integer[]
ttisfarray() only returns true if the value is a Ravi subtype number[]
*/
#define ttistable(o) checktype((o), LUA_TTABLE)
#define ttisiarray(o) checktag((o), ctb(RAVI_TIARRAY))
#define ttisfarray(o) checktag((o), ctb(RAVI_TFARRAY))
#define ttisarray(o) (ttisiarray(o) || ttisfarray(o))
#define ttisLtable(o) checktag((o), ctb(LUA_TTABLE))
#define ttisfunction(o) checktype(o, LUA_TFUNCTION)
#define ttisclosure(o) ((rttype(o) & 0x1F) == LUA_TFUNCTION)
#define ttisCclosure(o) checktag((o), ctb(LUA_TCCL))
#define ttisLclosure(o) checktag((o), ctb(LUA_TLCL))
#define ttislcf(o) checktag((o), LUA_TLCF)
#define ttisfcf(o) (ttype(o) == RAVI_TFCF)
#define ttisfulluserdata(o) checktag((o), ctb(LUA_TUSERDATA))
#define ttisthread(o) checktag((o), ctb(LUA_TTHREAD))
#define ttisdeadkey(o) checktag((o), LUA_TDEADKEY)
/* Macros to access values */
#define ivalue(o) check_exp(ttisinteger(o), val_(o).i)
#define fltvalue(o) check_exp(ttisfloat(o), val_(o).n)
#define nvalue(o) check_exp(ttisnumber(o), \
(ttisinteger(o) ? cast_num(ivalue(o)) : fltvalue(o)))
#define gcvalue(o) check_exp(iscollectable(o), val_(o).gc)
#define pvalue(o) check_exp(ttislightuserdata(o), val_(o).p)
#define tsvalue(o) check_exp(ttisstring(o), gco2ts(val_(o).gc))
#define uvalue(o) check_exp(ttisfulluserdata(o), gco2u(val_(o).gc))
#define clvalue(o) check_exp(ttisclosure(o), gco2cl(val_(o).gc))
#define clLvalue(o) check_exp(ttisLclosure(o), gco2lcl(val_(o).gc))
#define clCvalue(o) check_exp(ttisCclosure(o), gco2ccl(val_(o).gc))
#define fvalue(o) check_exp(ttislcf(o), val_(o).f)
#define fcfvalue(o) check_exp(ttisfcf(o), val_(o).p)
#define hvalue(o) check_exp(ttisLtable(o), gco2t(val_(o).gc))
#define arrvalue(o) check_exp(ttisarray(o), gco2array(val_(o).gc))
#define bvalue(o) check_exp(ttisboolean(o), val_(o).b)
#define thvalue(o) check_exp(ttisthread(o), gco2th(val_(o).gc))
/* a dead value may get the 'gc' field, but cannot access its contents */
#define deadvalue(o) check_exp(ttisdeadkey(o), cast(void *, val_(o).gc))
#define l_isfalse(o) (ttisnil(o) || (ttisboolean(o) && bvalue(o) == 0))
#define iscollectable(o) (rttype(o) & BIT_ISCOLLECTABLE)
/* Macros for internal tests */
/* collectable object has the same tag as the original value */
#define righttt(obj) (ttype(obj) == gcvalue(obj)->tt)
/*
** Any value being manipulated by the program either is non
** collectable, or the collectable object has the right tag
** and it is not dead.
*/
#define checkliveness(L,obj) \
lua_longassert(!iscollectable(obj) || \
(righttt(obj) && (L == NULL || !isdead(G(L),gcvalue(obj)))))
/* Macros to set values */
/* set a value's tag */
#define settt_(o,t) ((o)->tt_=(t))
#define setfltvalue(obj,x) \
{ TValue *io=(obj); val_(io).n=(x); settt_(io, LUA_TNUMFLT); }
#define chgfltvalue(obj,x) \
{ TValue *io=(obj); lua_assert(ttisfloat(io)); val_(io).n=(x); }
/* main macro to copy values (from 'obj1' to 'obj2') */
#define setobj(L,obj1,obj2) \
{ TValue *io1=(obj1); const TValue *io2=(obj2); \
io1->value_ = io2->value_; settt_(io1, io2->tt_); \
(void)L; checkliveness(L,io1); }
#define setivalue(obj,x) \
{ TValue *io=(obj); val_(io).i=(x); settt_(io, LUA_TNUMINT); }
#define chgivalue(obj,x) \
{ TValue *io=(obj); lua_assert(ttisinteger(io)); val_(io).i=(x); }
/*
** different types of assignments, according to destination
*/
/* from stack to (same) stack */
#define setobjs2s setobj
/* to stack (not from same stack) */
#define setobj2s setobj
/* from table to same table */
#define setobjt2t setobj
/* to new object */
#define setobj2n setobj
/* to table */
#define setobj2t setobj
typedef TValue *StkId; /* index to stack elements */
/*
** {==================================================================
** Nil
** ===================================================================
*/
/* macro defining a nil value */
#define NILCONSTANT {NULL}, LUA_TNIL
/* macro to test for (any kind of) nil */
#define ttisnil(o) checktag((o), LUA_TNIL)
#define setnilvalue(obj) settt_(obj, LUA_TNIL)
/* }================================================================== */
#define setfvalue(obj,x) \
{ TValue *io=(obj); val_(io).f=(x); settt_(io, LUA_TLCF); }
/* The Fast C function call type is encoded as two
bytes. The Hi Byte holds a function tag. The Lo Byte
holds the Lua typecode */
#define setfvalue_fastcall(obj, x, tag) \
{ \
TValue *io = (obj); \
lua_assert(tag >= 1 && tag < 0x80); \
val_(io).p = (x); \
settt_(io, ((tag << 8) | RAVI_TFCF)); \
}
#define getfcf_tag(typecode) (typecode >> 8)
/*
** {==================================================================
** Booleans
** ===================================================================
*/
#define setpvalue(obj,x) \
{ TValue *io=(obj); val_(io).p=(x); settt_(io, LUA_TLIGHTUSERDATA); }
#define ttisboolean(o) checktag((o), LUA_TBOOLEAN)
#define bvalue(o) check_exp(ttisboolean(o), val_(o).b)
#define l_isfalse(o) (ttisnil(o) || (ttisboolean(o) && bvalue(o) == 0))
#define setbvalue(obj,x) \
{ TValue *io=(obj); val_(io).b=(x); settt_(io, LUA_TBOOLEAN); }
/* }================================================================== */
#define setgcovalue(L,obj,x) \
{ TValue *io = (obj); GCObject *i_g=(x); \
val_(io).gc = i_g; settt_(io, ctb(i_g->tt)); }
#define setsvalue(L,obj,x) \
{ TValue *io = (obj); TString *x_ = (x); \
val_(io).gc = obj2gco(x_); settt_(io, ctb(x_->tt)); \
checkliveness(L,io); }
/*
** {==================================================================
** Threads
** ===================================================================
*/
#define setuvalue(L,obj,x) \
{ TValue *io = (obj); Udata *x_ = (x); \
val_(io).gc = obj2gco(x_); settt_(io, ctb(LUA_TUSERDATA)); \
checkliveness(L,io); }
#define ttisthread(o) checktag((o), ctb(LUA_TTHREAD))
#define thvalue(o) check_exp(ttisthread(o), gco2th(val_(o).gc))
#define setthvalue(L,obj,x) \
{ TValue *io = (obj); lua_State *x_ = (x); \
val_(io).gc = obj2gco(x_); settt_(io, ctb(LUA_TTHREAD)); \
checkliveness(L,io); }
#define setclLvalue(L,obj,x) \
{ TValue *io = (obj); LClosure *x_ = (x); \
val_(io).gc = obj2gco(x_); settt_(io, ctb(LUA_TLCL)); \
checkliveness(L,io); }
#define setclCvalue(L,obj,x) \
{ TValue *io = (obj); CClosure *x_ = (x); \
val_(io).gc = obj2gco(x_); settt_(io, ctb(LUA_TCCL)); \
checkliveness(L,io); }
/* }================================================================== */
#define sethvalue(L,obj,x) \
{ TValue *io = (obj); Table *x_ = (x); \
val_(io).gc = obj2gco(x_); settt_(io, ctb(LUA_TTABLE)); \
checkliveness(L,io); }
/** RAVI extension **/
#define setiarrayvalue(L,obj,x) \
{ TValue *io = (obj); RaviArray *x_ = (x); \
val_(io).gc = obj2gco(x_); settt_(io, ctb(RAVI_TIARRAY)); \
checkliveness(L,io); }
/*
** {==================================================================
** Collectable Objects
** ===================================================================
*/
/** RAVI extension **/
#define setfarrayvalue(L,obj,x) \
{ TValue *io = (obj); RaviArray *x_ = (x); \
val_(io).gc = obj2gco(x_); settt_(io, ctb(RAVI_TFARRAY)); \
checkliveness(L,io); }
/*
** Common Header for all collectable objects (in macro form, to be
** included in other objects)
** Note that tt field is a byte.
*/
#define CommonHeader struct GCObject *next; lu_byte tt; lu_byte marked
#define setdeadvalue(obj) settt_(obj, LUA_TDEADKEY)
/* Common type for all collectable objects */
typedef struct GCObject {
CommonHeader;
} GCObject;
#define setobj(L,obj1,obj2) \
{ TValue *io1=(obj1); const TValue *io2=(obj2); \
io1->value_ = io2->value_; io1->tt_ = io2->tt_; \
(void)L; checkliveness(L,io1); }
/* Bit mark for collectable types */
#define BIT_ISCOLLECTABLE (1 << 15)
#define iscollectable(o) (rttype(o) & BIT_ISCOLLECTABLE)
/* mark a tag as collectable */
#define ctb(t) ((t) | BIT_ISCOLLECTABLE)
#define gcvalue(o) check_exp(iscollectable(o), val_(o).gc)
#define setgcovalue(L,obj,x) \
{ TValue *io = (obj); GCObject *i_g=(x); \
val_(io).gc = i_g; settt_(io, ctb(i_g->tt)); }
/* }================================================================== */
/*
** different types of assignments, according to destination
** {==================================================================
** Numbers
** ===================================================================
*/
/* from stack to (same) stack */
#define setobjs2s setobj
/* to stack (not from same stack) */
#define setobj2s setobj
#define setsvalue2s setsvalue
#define sethvalue2s sethvalue
#define setptvalue2s setptvalue
/* from table to same table */
#define setobjt2t setobj
/* to new object */
#define setobj2n setobj
#define setsvalue2n setsvalue
/* to table */
#define setobj2t setobj
/* Variant tags for numbers */
#define LUA_TNUMFLT makevariant(LUA_TNUMBER, 0) /* float numbers */
#define LUA_TNUMINT makevariant(LUA_TNUMBER, 1) /* integer numbers */
#define ttisnumber(o) checktype((o), LUA_TNUMBER)
#define ttisfloat(o) checktag((o), LUA_TNUMFLT)
#define ttisinteger(o) checktag((o), LUA_TNUMINT)
#define nvalue(o) check_exp(ttisnumber(o), \
(ttisinteger(o) ? cast_num(ivalue(o)) : fltvalue(o)))
#define fltvalue(o) check_exp(ttisfloat(o), val_(o).n)
#define ivalue(o) check_exp(ttisinteger(o), val_(o).i)
#define setfltvalue(obj,x) \
{ TValue *io=(obj); val_(io).n=(x); settt_(io, LUA_TNUMFLT); }
#define chgfltvalue(obj,x) \
{ TValue *io=(obj); lua_assert(ttisfloat(io)); val_(io).n=(x); }
#define setivalue(obj,x) \
{ TValue *io=(obj); val_(io).i=(x); settt_(io, LUA_TNUMINT); }
#define chgivalue(obj,x) \
{ TValue *io=(obj); lua_assert(ttisinteger(io)); val_(io).i=(x); }
/* }================================================================== */
/*
** {======================================================
** types and prototypes
** =======================================================
** {==================================================================
** Strings
** ===================================================================
*/
/* Variant tags for strings */
#define LUA_TSHRSTR makevariant(LUA_TSTRING, 0) /* short strings */
#define LUA_TLNGSTR makevariant(LUA_TSTRING, 1) /* long strings */
typedef TValue *StkId; /* index to stack elements */
#define ttisstring(o) checktype((o), LUA_TSTRING)
#define ttisshrstring(o) checktag((o), ctb(LUA_TSHRSTR))
#define ttislngstring(o) checktag((o), ctb(LUA_TLNGSTR))
#define tsvalue(o) check_exp(ttisstring(o), gco2ts(val_(o).gc))
#define setsvalue(L,obj,x) \
{ TValue *io = (obj); TString *x_ = (x); \
val_(io).gc = obj2gco(x_); settt_(io, ctb(x_->tt)); \
checkliveness(L,io); }
/* set a string to the stack */
#define setsvalue2s setsvalue
/* set a string to a new object */
#define setsvalue2n setsvalue
/*
** Header for string value; string bytes follow the end of this structure
@ -375,7 +337,6 @@ typedef union UTString {
TString tsv;
} UTString;
/*
** Get the actual string (array of bytes) from a 'TString'.
** (Access to 'extra' ensures that value is really a 'TString'.)
@ -393,6 +354,34 @@ typedef union UTString {
/* get string length from 'TValue *o' */
#define vslen(o) tsslen(tsvalue(o))
/* }================================================================== */
/*
** {==================================================================
** Userdata
** ===================================================================
*/
/*
** Light userdata should be a variant of userdata, but for compatibility
** reasons they are also different types.
*/
#define ttislightuserdata(o) checktag((o), LUA_TLIGHTUSERDATA)
#define ttisfulluserdata(o) checktag((o), ctb(LUA_TUSERDATA))
#define pvalue(o) check_exp(ttislightuserdata(o), val_(o).p)
#define uvalue(o) check_exp(ttisfulluserdata(o), gco2u(val_(o).gc))
#define setpvalue(obj,x) \
{ TValue *io=(obj); val_(io).p=(x); settt_(io, LUA_TLIGHTUSERDATA); }
#define setuvalue(L,obj,x) \
{ TValue *io = (obj); Udata *x_ = (x); \
val_(io).gc = obj2gco(x_); settt_(io, ctb(LUA_TUSERDATA)); \
checkliveness(L,io); }
/*
** Header for userdata; memory area follows the end of this structure
@ -434,25 +423,14 @@ typedef union UUdata {
io->value_ = iu->user_; settt_(io, iu->ttuv_); \
checkliveness(L,io); }
/* RAVI: Following are the types we will use
** use in parsing. The rationale for types is
** performance - as of now these are the only types that
** we care about from a performance point of view - if any
** other types appear then they are all treated as ANY
**/
typedef enum {
RAVI_TANY = 0, /* Lua dynamic type */
RAVI_TNUMINT = 1, /* integer number */
RAVI_TNUMFLT, /* floating point number */
RAVI_TARRAYINT, /* array of ints */
RAVI_TARRAYFLT, /* array of doubles */
RAVI_TFUNCTION, /* Lua or C Function */
RAVI_TTABLE, /* Lua table */
RAVI_TSTRING, /* string */
RAVI_TNIL, /* NIL */
RAVI_TBOOLEAN, /* boolean */
RAVI_TUSERDATA /* userdata or lightuserdata */
} ravitype_t;
/* }================================================================== */
/*
** {==================================================================
** Prototypes
** ===================================================================
*/
/*
** Description of an upvalue for function prototypes
@ -504,7 +482,7 @@ typedef struct RaviJITProto {
*/
typedef struct Proto {
CommonHeader;
lu_byte numparams; /* number of fixed parameters */
lu_byte numparams; /* number of fixed (named) parameters */
lu_byte is_vararg;
lu_byte maxstacksize; /* number of registers needed by this function */
int sizeupvalues; /* size of 'upvalues' */
@ -528,8 +506,67 @@ typedef struct Proto {
RaviJITProto ravi_jit;
} Proto;
/*
** {==================================================================
** Closures
** ===================================================================
*/
/*
** LUA_TFUNCTION variants:
** 0 - Lua function
** 1 - light C function
** 2 - regular C function (closure)
** 4 - fast light C dunction (Ravi extension)
*/
/* Variant tags for functions */
#define LUA_TLCL makevariant(LUA_TFUNCTION, 0) /* Lua closure */
#define LUA_TLCF makevariant(LUA_TFUNCTION, 1) /* light C function */
#define LUA_TCCL makevariant(LUA_TFUNCTION, 2) /* C closure */
#define RAVI_TFCF makevariant(LUA_TFUNCTION, 4) /* Ravi extension: fast light C function */
#define ttisfunction(o) checktype(o, LUA_TFUNCTION)
#define ttisclosure(o) ((rttype(o) & 0x1F) == LUA_TFUNCTION)
#define ttisLclosure(o) checktag((o), ctb(LUA_TLCL))
#define ttislcf(o) checktag((o), LUA_TLCF)
#define ttisCclosure(o) checktag((o), ctb(LUA_TCCL))
#define ttisfcf(o) (ttype(o) == RAVI_TFCF)
#define isLfunction(o) ttisLclosure(o)
#define clvalue(o) check_exp(ttisclosure(o), gco2cl(val_(o).gc))
#define clLvalue(o) check_exp(ttisLclosure(o), gco2lcl(val_(o).gc))
#define fvalue(o) check_exp(ttislcf(o), val_(o).f)
#define clCvalue(o) check_exp(ttisCclosure(o), gco2ccl(val_(o).gc))
#define fcfvalue(o) check_exp(ttisfcf(o), val_(o).p)
#define setclLvalue(L,obj,x) \
{ TValue *io = (obj); LClosure *x_ = (x); \
val_(io).gc = obj2gco(x_); settt_(io, ctb(LUA_TLCL)); \
checkliveness(L,io); }
#define setfvalue(obj,x) \
{ TValue *io=(obj); val_(io).f=(x); settt_(io, LUA_TLCF); }
#define setclCvalue(L,obj,x) \
{ TValue *io = (obj); CClosure *x_ = (x); \
val_(io).gc = obj2gco(x_); settt_(io, ctb(LUA_TCCL)); \
checkliveness(L,io); }
/* The Fast C function call type is encoded as two
bytes. The Hi Byte holds a function tag. The Lo Byte
holds the Lua typecode */
#define setfvalue_fastcall(obj, x, tag) \
{ \
TValue *io = (obj); \
lua_assert(tag >= 1 && tag < 0x80); \
val_(io).p = (x); \
settt_(io, ((tag << 8) | RAVI_TFCF)); \
}
#define getfcf_tag(typecode) (typecode >> 8)
/*
** Lua Upvalues
*/
@ -563,10 +600,110 @@ typedef union Closure {
} Closure;
#define isLfunction(o) ttisLclosure(o)
#define getproto(o) (clLvalue(o)->p)
/* }================================================================== */
/*
** {==================================================================
** Tables
** ===================================================================
*/
/* RAVI change: we support two sub types of table type
and hence need to distinguish between the types.
ttistable() returns true for all table types
ttisLtable() only returns true if the value is a Lua table
ttisiarray() only returns true if the value is a Ravi subtype integer[]
ttisfarray() only returns true if the value is a Ravi subtype number[]
*/
/** RAVI table subtypes **/
#define RAVI_TIARRAY makevariant(LUA_TTABLE, 1) /* Ravi int array */
#define RAVI_TFARRAY makevariant(LUA_TTABLE, 2) /* Ravi float array */
#define ttistable(o) checktype((o), LUA_TTABLE)
#define ttisiarray(o) checktag((o), ctb(RAVI_TIARRAY))
#define ttisfarray(o) checktag((o), ctb(RAVI_TFARRAY))
#define ttisarray(o) (ttisiarray(o) || ttisfarray(o))
#define ttisLtable(o) checktag((o), ctb(LUA_TTABLE))
#define ttisdeadkey(o) checktag((o), LUA_TDEADKEY)
/* Macros to access values */
#define hvalue(o) check_exp(ttisLtable(o), gco2t(val_(o).gc))
#define arrvalue(o) check_exp(ttisarray(o), gco2array(val_(o).gc))
/* a dead value may get the 'gc' field, but cannot access its contents */
#define deadvalue(o) check_exp(ttisdeadkey(o), cast(void *, val_(o).gc))
#define sethvalue(L,obj,x) \
{ TValue *io = (obj); Table *x_ = (x); \
val_(io).gc = obj2gco(x_); settt_(io, ctb(LUA_TTABLE)); \
checkliveness(L,io); }
/** RAVI extension **/
#define setiarrayvalue(L,obj,x) \
{ TValue *io = (obj); RaviArray *x_ = (x); \
val_(io).gc = obj2gco(x_); settt_(io, ctb(RAVI_TIARRAY)); \
checkliveness(L,io); }
/** RAVI extension **/
#define setfarrayvalue(L,obj,x) \
{ TValue *io = (obj); RaviArray *x_ = (x); \
val_(io).gc = obj2gco(x_); settt_(io, ctb(RAVI_TFARRAY)); \
checkliveness(L,io); }
#define sethvalue2s sethvalue
#define setptvalue2s setptvalue
/*
** {======================================================
** types and prototypes
** =======================================================
*/
/*
** Tables
@ -581,6 +718,13 @@ typedef union TKey {
} TKey;
typedef struct Node {
TValue i_val;
TKey i_key;
} Node;
/* copy a value into a key without messing up field 'next' */
#define setnodekey(L,key,obj) \
{ TKey *k_=(key); const TValue *io_=(obj); \
@ -588,10 +732,46 @@ typedef union TKey {
(void)L; checkliveness(L,io_); }
typedef struct Node {
TValue i_val;
TKey i_key;
} Node;
typedef struct Table {
CommonHeader;
lu_byte flags; /* 1<<p means tagmethod(p) is not present */
lu_byte lsizenode; /* log2 of size of 'node' array */
unsigned int sizearray; /* size of 'array' array */
TValue *array; /* array part */
Node *node;
Node *lastfree; /* any free position is before this position */
struct Table *metatable;
GCObject *gclist;
#if RAVI_USE_NEWHASH
// TODO we should reorganize this structure
unsigned int hmask; /* Hash part mask (size of hash part - 1) - borrowed from LuaJIT */
#endif
} Table;
/*
** Macros to manipulate keys inserted in nodes
*/
#define keytt(node) ((node)->nk.tt_)
#define keyval(node) ((node)->nk.value_)
#define keyisnil(node) (keytt(node) == LUA_TNIL)
#define keyisinteger(node) (keytt(node) == LUA_TNUMINT)
#define keyival(node) (keyval(node).i)
#define keyisshrstr(node) (keytt(node) == ctb(LUA_TSHRSTR))
#define keystrval(node) (gco2ts(keyval(node).gc))
#define setnilkey(node) (keytt(node) = LUA_TNIL)
#define keyiscollectable(n) (keytt(n) & BIT_ISCOLLECTABLE)
#define gckey(n) (keyval(n).gc)
#define gckeyN(n) (keyiscollectable(n) ? gckey(n) : NULL)
#define setdeadvalue(obj) settt_(obj, LUA_TDEADKEY)
/* }================================================================== */
/** RAVI extension */
typedef enum RaviArrayModifer {
@ -623,23 +803,6 @@ typedef struct RaviArray {
struct Table *metatable;
} RaviArray;
typedef struct Table {
CommonHeader;
lu_byte flags; /* 1<<p means tagmethod(p) is not present */
lu_byte lsizenode; /* log2 of size of 'node' array */
unsigned int sizearray; /* size of 'array' array */
TValue *array; /* array part */
Node *node;
Node *lastfree; /* any free position is before this position */
struct Table *metatable;
GCObject *gclist;
#if RAVI_USE_NEWHASH
// TODO we should reorganize this structure
unsigned int hmask; /* Hash part mask (size of hash part - 1) - borrowed from LuaJIT */
#endif
} Table;
/*
** 'module' operation for hashing (size is always a power of 2)
@ -674,7 +837,7 @@ LUAI_FUNC void luaO_tostring (lua_State *L, StkId obj);
LUAI_FUNC const char *luaO_pushvfstring (lua_State *L, const char *fmt,
va_list argp);
LUAI_FUNC const char *luaO_pushfstring (lua_State *L, const char *fmt, ...);
LUAI_FUNC void luaO_chunkid (char *out, const char *source, size_t len);
LUAI_FUNC void luaO_chunkid (char *out, const char *source, size_t srclen);
#endif

Loading…
Cancel
Save