root/lj_obj.h

/* [<][>][^][v][top][bottom][index][help] */

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. MMDEF
  2. setlightudV
  3. setgcVraw
  4. setgcV
  5. setintV
  6. setint64V
  7. copyTV
  8. lj_num2bit
  9. lj_num2u64
  10. numberVint
  11. numberVnum

   1 /*
   2 ** LuaJIT VM tags, values and objects.
   3 ** Copyright (C) 2005-2017 Mike Pall. See Copyright Notice in luajit.h
   4 **
   5 ** Portions taken verbatim or adapted from the Lua interpreter.
   6 ** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h
   7 */
   8 
   9 #ifndef _LJ_OBJ_H
  10 #define _LJ_OBJ_H
  11 
  12 #include "lua.h"
  13 #include "lj_def.h"
  14 #include "lj_arch.h"
  15 
  16 /* -- Memory references (32 bit address space) ---------------------------- */
  17 
  18 /* Memory and GC object sizes. */
  19 typedef uint32_t MSize;
  20 #if LJ_GC64
  21 typedef uint64_t GCSize;
  22 #else
  23 typedef uint32_t GCSize;
  24 #endif
  25 
  26 /* Memory reference */
  27 typedef struct MRef {
  28 #if LJ_GC64
  29   uint64_t ptr64;       /* True 64 bit pointer. */
  30 #else
  31   uint32_t ptr32;       /* Pseudo 32 bit pointer. */
  32 #endif
  33 } MRef;
  34 
  35 #if LJ_GC64
  36 #define mref(r, t)      ((t *)(void *)(r).ptr64)
  37 
  38 #define setmref(r, p)   ((r).ptr64 = (uint64_t)(void *)(p))
  39 #define setmrefr(r, v)  ((r).ptr64 = (v).ptr64)
  40 #else
  41 #define mref(r, t)      ((t *)(void *)(uintptr_t)(r).ptr32)
  42 
  43 #define setmref(r, p)   ((r).ptr32 = (uint32_t)(uintptr_t)(void *)(p))
  44 #define setmrefr(r, v)  ((r).ptr32 = (v).ptr32)
  45 #endif
  46 
  47 /* -- GC object references (32 bit address space) ------------------------- */
  48 
  49 /* GCobj reference */
  50 typedef struct GCRef {
  51 #if LJ_GC64
  52   uint64_t gcptr64;     /* True 64 bit pointer. */
  53 #else
  54   uint32_t gcptr32;     /* Pseudo 32 bit pointer. */
  55 #endif
  56 } GCRef;
  57 
  58 /* Common GC header for all collectable objects. */
  59 #define GCHeader        GCRef nextgc; uint8_t marked; uint8_t gct
  60 /* This occupies 6 bytes, so use the next 2 bytes for non-32 bit fields. */
  61 
  62 #if LJ_GC64
  63 #define gcref(r)        ((GCobj *)(r).gcptr64)
  64 #define gcrefp(r, t)    ((t *)(void *)(r).gcptr64)
  65 #define gcrefu(r)       ((r).gcptr64)
  66 #define gcrefeq(r1, r2) ((r1).gcptr64 == (r2).gcptr64)
  67 
  68 #define setgcref(r, gc) ((r).gcptr64 = (uint64_t)&(gc)->gch)
  69 #define setgcreft(r, gc, it) \
  70   (r).gcptr64 = (uint64_t)&(gc)->gch | (((uint64_t)(it)) << 47)
  71 #define setgcrefp(r, p) ((r).gcptr64 = (uint64_t)(p))
  72 #define setgcrefnull(r) ((r).gcptr64 = 0)
  73 #define setgcrefr(r, v) ((r).gcptr64 = (v).gcptr64)
  74 #else
  75 #define gcref(r)        ((GCobj *)(uintptr_t)(r).gcptr32)
  76 #define gcrefp(r, t)    ((t *)(void *)(uintptr_t)(r).gcptr32)
  77 #define gcrefu(r)       ((r).gcptr32)
  78 #define gcrefeq(r1, r2) ((r1).gcptr32 == (r2).gcptr32)
  79 
  80 #define setgcref(r, gc) ((r).gcptr32 = (uint32_t)(uintptr_t)&(gc)->gch)
  81 #define setgcrefp(r, p) ((r).gcptr32 = (uint32_t)(uintptr_t)(p))
  82 #define setgcrefnull(r) ((r).gcptr32 = 0)
  83 #define setgcrefr(r, v) ((r).gcptr32 = (v).gcptr32)
  84 #endif
  85 
  86 #define gcnext(gc)      (gcref((gc)->gch.nextgc))
  87 
  88 /* IMPORTANT NOTE:
  89 **
  90 ** All uses of the setgcref* macros MUST be accompanied with a write barrier.
  91 **
  92 ** This is to ensure the integrity of the incremental GC. The invariant
  93 ** to preserve is that a black object never points to a white object.
  94 ** I.e. never store a white object into a field of a black object.
  95 **
  96 ** It's ok to LEAVE OUT the write barrier ONLY in the following cases:
  97 ** - The source is not a GC object (NULL).
  98 ** - The target is a GC root. I.e. everything in global_State.
  99 ** - The target is a lua_State field (threads are never black).
 100 ** - The target is a stack slot, see setgcV et al.
 101 ** - The target is an open upvalue, i.e. pointing to a stack slot.
 102 ** - The target is a newly created object (i.e. marked white). But make
 103 **   sure nothing invokes the GC inbetween.
 104 ** - The target and the source are the same object (self-reference).
 105 ** - The target already contains the object (e.g. moving elements around).
 106 **
 107 ** The most common case is a store to a stack slot. All other cases where
 108 ** a barrier has been omitted are annotated with a NOBARRIER comment.
 109 **
 110 ** The same logic applies for stores to table slots (array part or hash
 111 ** part). ALL uses of lj_tab_set* require a barrier for the stored value
 112 ** *and* the stored key, based on the above rules. In practice this means
 113 ** a barrier is needed if *either* of the key or value are a GC object.
 114 **
 115 ** It's ok to LEAVE OUT the write barrier in the following special cases:
 116 ** - The stored value is nil. The key doesn't matter because it's either
 117 **   not resurrected or lj_tab_newkey() will take care of the key barrier.
 118 ** - The key doesn't matter if the *previously* stored value is guaranteed
 119 **   to be non-nil (because the key is kept alive in the table).
 120 ** - The key doesn't matter if it's guaranteed not to be part of the table,
 121 **   since lj_tab_newkey() takes care of the key barrier. This applies
 122 **   trivially to new tables, but watch out for resurrected keys. Storing
 123 **   a nil value leaves the key in the table!
 124 **
 125 ** In case of doubt use lj_gc_anybarriert() as it's rather cheap. It's used
 126 ** by the interpreter for all table stores.
 127 **
 128 ** Note: In contrast to Lua's GC, LuaJIT's GC does *not* specially mark
 129 ** dead keys in tables. The reference is left in, but it's guaranteed to
 130 ** be never dereferenced as long as the value is nil. It's ok if the key is
 131 ** freed or if any object subsequently gets the same address.
 132 **
 133 ** Not destroying dead keys helps to keep key hash slots stable. This avoids
 134 ** specialization back-off for HREFK when a value flips between nil and
 135 ** non-nil and the GC gets in the way. It also allows safely hoisting
 136 ** HREF/HREFK across GC steps. Dead keys are only removed if a table is
 137 ** resized (i.e. by NEWREF) and xREF must not be CSEd across a resize.
 138 **
 139 ** The trade-off is that a write barrier for tables must take the key into
 140 ** account, too. Implicitly resurrecting the key by storing a non-nil value
 141 ** may invalidate the incremental GC invariant.
 142 */
 143 
 144 /* -- Common type definitions --------------------------------------------- */
 145 
 146 /* Types for handling bytecodes. Need this here, details in lj_bc.h. */
 147 typedef uint32_t BCIns;  /* Bytecode instruction. */
 148 typedef uint32_t BCPos;  /* Bytecode position. */
 149 typedef uint32_t BCReg;  /* Bytecode register. */
 150 typedef int32_t BCLine;  /* Bytecode line number. */
 151 
 152 /* Internal assembler functions. Never call these directly from C. */
 153 typedef void (*ASMFunction)(void);
 154 
 155 /* Resizable string buffer. Need this here, details in lj_buf.h. */
 156 typedef struct SBuf {
 157   MRef p;               /* String buffer pointer. */
 158   MRef e;               /* String buffer end pointer. */
 159   MRef b;               /* String buffer base. */
 160   MRef L;               /* lua_State, used for buffer resizing. */
 161 } SBuf;
 162 
 163 /* -- Tags and values ----------------------------------------------------- */
 164 
 165 /* Frame link. */
 166 typedef union {
 167   int32_t ftsz;         /* Frame type and size of previous frame. */
 168   MRef pcr;             /* Or PC for Lua frames. */
 169 } FrameLink;
 170 
 171 /* Tagged value. */
 172 typedef LJ_ALIGN(8) union TValue {
 173   uint64_t u64;         /* 64 bit pattern overlaps number. */
 174   lua_Number n;         /* Number object overlaps split tag/value object. */
 175 #if LJ_GC64
 176   GCRef gcr;            /* GCobj reference with tag. */
 177   int64_t it64;
 178   struct {
 179     LJ_ENDIAN_LOHI(
 180       int32_t i;        /* Integer value. */
 181     , uint32_t it;      /* Internal object tag. Must overlap MSW of number. */
 182     )
 183   };
 184 #else
 185   struct {
 186     LJ_ENDIAN_LOHI(
 187       union {
 188         GCRef gcr;      /* GCobj reference (if any). */
 189         int32_t i;      /* Integer value. */
 190       };
 191     , uint32_t it;      /* Internal object tag. Must overlap MSW of number. */
 192     )
 193   };
 194 #endif
 195 #if LJ_FR2
 196   int64_t ftsz;         /* Frame type and size of previous frame, or PC. */
 197 #else
 198   struct {
 199     LJ_ENDIAN_LOHI(
 200       GCRef func;       /* Function for next frame (or dummy L). */
 201     , FrameLink tp;     /* Link to previous frame. */
 202     )
 203   } fr;
 204 #endif
 205   struct {
 206     LJ_ENDIAN_LOHI(
 207       uint32_t lo;      /* Lower 32 bits of number. */
 208     , uint32_t hi;      /* Upper 32 bits of number. */
 209     )
 210   } u32;
 211 } TValue;
 212 
 213 typedef const TValue cTValue;
 214 
 215 #define tvref(r)        (mref(r, TValue))
 216 
 217 /* More external and GCobj tags for internal objects. */
 218 #define LAST_TT         LUA_TTHREAD
 219 #define LUA_TPROTO      (LAST_TT+1)
 220 #define LUA_TCDATA      (LAST_TT+2)
 221 
 222 /* Internal object tags.
 223 **
 224 ** Format for 32 bit GC references (!LJ_GC64):
 225 **
 226 ** Internal tags overlap the MSW of a number object (must be a double).
 227 ** Interpreted as a double these are special NaNs. The FPU only generates
 228 ** one type of NaN (0xfff8_0000_0000_0000). So MSWs > 0xfff80000 are available
 229 ** for use as internal tags. Small negative numbers are used to shorten the
 230 ** encoding of type comparisons (reg/mem against sign-ext. 8 bit immediate).
 231 **
 232 **                  ---MSW---.---LSW---
 233 ** primitive types |  itype  |         |
 234 ** lightuserdata   |  itype  |  void * |  (32 bit platforms)
 235 ** lightuserdata   |ffff|    void *    |  (64 bit platforms, 47 bit pointers)
 236 ** GC objects      |  itype  |  GCRef  |
 237 ** int (LJ_DUALNUM)|  itype  |   int   |
 238 ** number           -------double------
 239 **
 240 ** Format for 64 bit GC references (LJ_GC64):
 241 **
 242 ** The upper 13 bits must be 1 (0xfff8...) for a special NaN. The next
 243 ** 4 bits hold the internal tag. The lowest 47 bits either hold a pointer,
 244 ** a zero-extended 32 bit integer or all bits set to 1 for primitive types.
 245 **
 246 **                     ------MSW------.------LSW------
 247 ** primitive types    |1..1|itype|1..................1|
 248 ** GC objects/lightud |1..1|itype|-------GCRef--------|
 249 ** int (LJ_DUALNUM)   |1..1|itype|0..0|-----int-------|
 250 ** number              ------------double-------------
 251 **
 252 ** ORDER LJ_T
 253 ** Primitive types nil/false/true must be first, lightuserdata next.
 254 ** GC objects are at the end, table/userdata must be lowest.
 255 ** Also check lj_ir.h for similar ordering constraints.
 256 */
 257 #define LJ_TNIL                 (~0u)
 258 #define LJ_TFALSE               (~1u)
 259 #define LJ_TTRUE                (~2u)
 260 #define LJ_TLIGHTUD             (~3u)
 261 #define LJ_TSTR                 (~4u)
 262 #define LJ_TUPVAL               (~5u)
 263 #define LJ_TTHREAD              (~6u)
 264 #define LJ_TPROTO               (~7u)
 265 #define LJ_TFUNC                (~8u)
 266 #define LJ_TTRACE               (~9u)
 267 #define LJ_TCDATA               (~10u)
 268 #define LJ_TTAB                 (~11u)
 269 #define LJ_TUDATA               (~12u)
 270 /* This is just the canonical number type used in some places. */
 271 #define LJ_TNUMX                (~13u)
 272 
 273 /* Integers have itype == LJ_TISNUM doubles have itype < LJ_TISNUM */
 274 #if LJ_64 && !LJ_GC64
 275 #define LJ_TISNUM               0xfffeffffu
 276 #else
 277 #define LJ_TISNUM               LJ_TNUMX
 278 #endif
 279 #define LJ_TISTRUECOND          LJ_TFALSE
 280 #define LJ_TISPRI               LJ_TTRUE
 281 #define LJ_TISGCV               (LJ_TSTR+1)
 282 #define LJ_TISTABUD             LJ_TTAB
 283 
 284 #if LJ_GC64
 285 #define LJ_GCVMASK              (((uint64_t)1 << 47) - 1)
 286 #endif
 287 
 288 /* -- String object ------------------------------------------------------- */
 289 
 290 /* String object header. String payload follows. */
 291 typedef struct GCstr {
 292   GCHeader;
 293   uint8_t reserved;     /* Used by lexer for fast lookup of reserved words. */
 294   uint8_t unused;
 295   MSize hash;           /* Hash of string. */
 296   MSize len;            /* Size of string. */
 297 } GCstr;
 298 
 299 #define strref(r)       (&gcref((r))->str)
 300 #define strdata(s)      ((const char *)((s)+1))
 301 #define strdatawr(s)    ((char *)((s)+1))
 302 #define strVdata(o)     strdata(strV(o))
 303 #define sizestring(s)   (sizeof(struct GCstr)+(s)->len+1)
 304 
 305 /* -- Userdata object ----------------------------------------------------- */
 306 
 307 /* Userdata object. Payload follows. */
 308 typedef struct GCudata {
 309   GCHeader;
 310   uint8_t udtype;       /* Userdata type. */
 311   uint8_t unused2;
 312   GCRef env;            /* Should be at same offset in GCfunc. */
 313   MSize len;            /* Size of payload. */
 314   GCRef metatable;      /* Must be at same offset in GCtab. */
 315   uint32_t align1;      /* To force 8 byte alignment of the payload. */
 316 } GCudata;
 317 
 318 /* Userdata types. */
 319 enum {
 320   UDTYPE_USERDATA,      /* Regular userdata. */
 321   UDTYPE_IO_FILE,       /* I/O library FILE. */
 322   UDTYPE_FFI_CLIB,      /* FFI C library namespace. */
 323   UDTYPE__MAX
 324 };
 325 
 326 #define uddata(u)       ((void *)((u)+1))
 327 #define sizeudata(u)    (sizeof(struct GCudata)+(u)->len)
 328 
 329 /* -- C data object ------------------------------------------------------- */
 330 
 331 /* C data object. Payload follows. */
 332 typedef struct GCcdata {
 333   GCHeader;
 334   uint16_t ctypeid;     /* C type ID. */
 335 } GCcdata;
 336 
 337 /* Prepended to variable-sized or realigned C data objects. */
 338 typedef struct GCcdataVar {
 339   uint16_t offset;      /* Offset to allocated memory (relative to GCcdata). */
 340   uint16_t extra;       /* Extra space allocated (incl. GCcdata + GCcdatav). */
 341   MSize len;            /* Size of payload. */
 342 } GCcdataVar;
 343 
 344 #define cdataptr(cd)    ((void *)((cd)+1))
 345 #define cdataisv(cd)    ((cd)->marked & 0x80)
 346 #define cdatav(cd)      ((GCcdataVar *)((char *)(cd) - sizeof(GCcdataVar)))
 347 #define cdatavlen(cd)   check_exp(cdataisv(cd), cdatav(cd)->len)
 348 #define sizecdatav(cd)  (cdatavlen(cd) + cdatav(cd)->extra)
 349 #define memcdatav(cd)   ((void *)((char *)(cd) - cdatav(cd)->offset))
 350 
 351 /* -- Prototype object ---------------------------------------------------- */
 352 
 353 #define SCALE_NUM_GCO   ((int32_t)sizeof(lua_Number)/sizeof(GCRef))
 354 #define round_nkgc(n)   (((n) + SCALE_NUM_GCO-1) & ~(SCALE_NUM_GCO-1))
 355 
 356 typedef struct GCproto {
 357   GCHeader;
 358   uint8_t numparams;    /* Number of parameters. */
 359   uint8_t framesize;    /* Fixed frame size. */
 360   MSize sizebc;         /* Number of bytecode instructions. */
 361 #if LJ_GC64
 362   uint32_t unused_gc64;
 363 #endif
 364   GCRef gclist;
 365   MRef k;               /* Split constant array (points to the middle). */
 366   MRef uv;              /* Upvalue list. local slot|0x8000 or parent uv idx. */
 367   MSize sizekgc;        /* Number of collectable constants. */
 368   MSize sizekn;         /* Number of lua_Number constants. */
 369   MSize sizept;         /* Total size including colocated arrays. */
 370   uint8_t sizeuv;       /* Number of upvalues. */
 371   uint8_t flags;        /* Miscellaneous flags (see below). */
 372   uint16_t trace;       /* Anchor for chain of root traces. */
 373   /* ------ The following fields are for debugging/tracebacks only ------ */
 374   GCRef chunkname;      /* Name of the chunk this function was defined in. */
 375   BCLine firstline;     /* First line of the function definition. */
 376   BCLine numline;       /* Number of lines for the function definition. */
 377   MRef lineinfo;        /* Compressed map from bytecode ins. to source line. */
 378   MRef uvinfo;          /* Upvalue names. */
 379   MRef varinfo;         /* Names and compressed extents of local variables. */
 380 } GCproto;
 381 
 382 /* Flags for prototype. */
 383 #define PROTO_CHILD             0x01    /* Has child prototypes. */
 384 #define PROTO_VARARG            0x02    /* Vararg function. */
 385 #define PROTO_FFI               0x04    /* Uses BC_KCDATA for FFI datatypes. */
 386 #define PROTO_NOJIT             0x08    /* JIT disabled for this function. */
 387 #define PROTO_ILOOP             0x10    /* Patched bytecode with ILOOP etc. */
 388 /* Only used during parsing. */
 389 #define PROTO_HAS_RETURN        0x20    /* Already emitted a return. */
 390 #define PROTO_FIXUP_RETURN      0x40    /* Need to fixup emitted returns. */
 391 /* Top bits used for counting created closures. */
 392 #define PROTO_CLCOUNT           0x20    /* Base of saturating 3 bit counter. */
 393 #define PROTO_CLC_BITS          3
 394 #define PROTO_CLC_POLY          (3*PROTO_CLCOUNT)  /* Polymorphic threshold. */
 395 
 396 #define PROTO_UV_LOCAL          0x8000  /* Upvalue for local slot. */
 397 #define PROTO_UV_IMMUTABLE      0x4000  /* Immutable upvalue. */
 398 
 399 #define proto_kgc(pt, idx) \
 400   check_exp((uintptr_t)(intptr_t)(idx) >= (uintptr_t)-(intptr_t)(pt)->sizekgc, \
 401             gcref(mref((pt)->k, GCRef)[(idx)]))
 402 #define proto_knumtv(pt, idx) \
 403   check_exp((uintptr_t)(idx) < (pt)->sizekn, &mref((pt)->k, TValue)[(idx)])
 404 #define proto_bc(pt)            ((BCIns *)((char *)(pt) + sizeof(GCproto)))
 405 #define proto_bcpos(pt, pc)     ((BCPos)((pc) - proto_bc(pt)))
 406 #define proto_uv(pt)            (mref((pt)->uv, uint16_t))
 407 
 408 #define proto_chunkname(pt)     (strref((pt)->chunkname))
 409 #define proto_chunknamestr(pt)  (strdata(proto_chunkname((pt))))
 410 #define proto_lineinfo(pt)      (mref((pt)->lineinfo, const void))
 411 #define proto_uvinfo(pt)        (mref((pt)->uvinfo, const uint8_t))
 412 #define proto_varinfo(pt)       (mref((pt)->varinfo, const uint8_t))
 413 
 414 /* -- Upvalue object ------------------------------------------------------ */
 415 
 416 typedef struct GCupval {
 417   GCHeader;
 418   uint8_t closed;       /* Set if closed (i.e. uv->v == &uv->u.value). */
 419   uint8_t immutable;    /* Immutable value. */
 420   union {
 421     TValue tv;          /* If closed: the value itself. */
 422     struct {            /* If open: double linked list, anchored at thread. */
 423       GCRef prev;
 424       GCRef next;
 425     };
 426   };
 427   MRef v;               /* Points to stack slot (open) or above (closed). */
 428   uint32_t dhash;       /* Disambiguation hash: dh1 != dh2 => cannot alias. */
 429 } GCupval;
 430 
 431 #define uvprev(uv_)     (&gcref((uv_)->prev)->uv)
 432 #define uvnext(uv_)     (&gcref((uv_)->next)->uv)
 433 #define uvval(uv_)      (mref((uv_)->v, TValue))
 434 
 435 /* -- Function object (closures) ------------------------------------------ */
 436 
 437 /* Common header for functions. env should be at same offset in GCudata. */
 438 #define GCfuncHeader \
 439   GCHeader; uint8_t ffid; uint8_t nupvalues; \
 440   GCRef env; GCRef gclist; MRef pc
 441 
 442 typedef struct GCfuncC {
 443   GCfuncHeader;
 444   lua_CFunction f;      /* C function to be called. */
 445   TValue upvalue[1];    /* Array of upvalues (TValue). */
 446 } GCfuncC;
 447 
 448 typedef struct GCfuncL {
 449   GCfuncHeader;
 450   GCRef uvptr[1];       /* Array of _pointers_ to upvalue objects (GCupval). */
 451 } GCfuncL;
 452 
 453 typedef union GCfunc {
 454   GCfuncC c;
 455   GCfuncL l;
 456 } GCfunc;
 457 
 458 #define FF_LUA          0
 459 #define FF_C            1
 460 #define isluafunc(fn)   ((fn)->c.ffid == FF_LUA)
 461 #define iscfunc(fn)     ((fn)->c.ffid == FF_C)
 462 #define isffunc(fn)     ((fn)->c.ffid > FF_C)
 463 #define funcproto(fn) \
 464   check_exp(isluafunc(fn), (GCproto *)(mref((fn)->l.pc, char)-sizeof(GCproto)))
 465 #define sizeCfunc(n)    (sizeof(GCfuncC)-sizeof(TValue)+sizeof(TValue)*(n))
 466 #define sizeLfunc(n)    (sizeof(GCfuncL)-sizeof(GCRef)+sizeof(GCRef)*(n))
 467 
 468 /* -- Table object -------------------------------------------------------- */
 469 
 470 /* Hash node. */
 471 typedef struct Node {
 472   TValue val;           /* Value object. Must be first field. */
 473   TValue key;           /* Key object. */
 474   MRef next;            /* Hash chain. */
 475 #if !LJ_GC64
 476   MRef freetop;         /* Top of free elements (stored in t->node[0]). */
 477 #endif
 478 } Node;
 479 
 480 LJ_STATIC_ASSERT(offsetof(Node, val) == 0);
 481 
 482 typedef struct GCtab {
 483   GCHeader;
 484   uint8_t nomm;         /* Negative cache for fast metamethods. */
 485   int8_t colo;          /* Array colocation. */
 486   MRef array;           /* Array part. */
 487   GCRef gclist;
 488   GCRef metatable;      /* Must be at same offset in GCudata. */
 489   MRef node;            /* Hash part. */
 490   uint32_t asize;       /* Size of array part (keys [0, asize-1]). */
 491   uint32_t hmask;       /* Hash part mask (size of hash part - 1). */
 492 #if LJ_GC64
 493   MRef freetop;         /* Top of free elements. */
 494 #endif
 495 } GCtab;
 496 
 497 #define sizetabcolo(n)  ((n)*sizeof(TValue) + sizeof(GCtab))
 498 #define tabref(r)       (&gcref((r))->tab)
 499 #define noderef(r)      (mref((r), Node))
 500 #define nextnode(n)     (mref((n)->next, Node))
 501 #if LJ_GC64
 502 #define getfreetop(t, n)        (noderef((t)->freetop))
 503 #define setfreetop(t, n, v)     (setmref((t)->freetop, (v)))
 504 #else
 505 #define getfreetop(t, n)        (noderef((n)->freetop))
 506 #define setfreetop(t, n, v)     (setmref((n)->freetop, (v)))
 507 #endif
 508 
 509 /* -- State objects ------------------------------------------------------- */
 510 
 511 /* VM states. */
 512 enum {
 513   LJ_VMST_INTERP,       /* Interpreter. */
 514   LJ_VMST_C,            /* C function. */
 515   LJ_VMST_GC,           /* Garbage collector. */
 516   LJ_VMST_EXIT,         /* Trace exit handler. */
 517   LJ_VMST_RECORD,       /* Trace recorder. */
 518   LJ_VMST_OPT,          /* Optimizer. */
 519   LJ_VMST_ASM,          /* Assembler. */
 520   LJ_VMST__MAX
 521 };
 522 
 523 #define setvmstate(g, st)       ((g)->vmstate = ~LJ_VMST_##st)
 524 
 525 /* Metamethods. ORDER MM */
 526 #ifdef LJ_HASFFI
 527 #define MMDEF_FFI(_) _(new)
 528 #else
 529 #define MMDEF_FFI(_)
 530 #endif
 531 
 532 #if LJ_52 || LJ_HASFFI
 533 #define MMDEF_PAIRS(_) _(pairs) _(ipairs)
 534 #else
 535 #define MMDEF_PAIRS(_)
 536 #define MM_pairs        255
 537 #define MM_ipairs       255
 538 #endif
 539 
 540 #define MMDEF(_) \
 541   _(index) _(newindex) _(gc) _(mode) _(eq) _(len) \
 542   /* Only the above (fast) metamethods are negative cached (max. 8). */ \
 543   _(lt) _(le) _(concat) _(call) \
 544   /* The following must be in ORDER ARITH. */ \
 545   _(add) _(sub) _(mul) _(div) _(mod) _(pow) _(unm) \
 546   /* The following are used in the standard libraries. */ \
 547   _(metatable) _(tostring) MMDEF_FFI(_) MMDEF_PAIRS(_)
 548 
 549 typedef enum {
 550 #define MMENUM(name)    MM_##name,
 551 MMDEF(MMENUM)
 552 #undef MMENUM
 553   MM__MAX,
 554   MM____ = MM__MAX,
 555   MM_FAST = MM_len
 556 } MMS;
 557 
 558 /* GC root IDs. */
 559 typedef enum {
 560   GCROOT_MMNAME,        /* Metamethod names. */
 561   GCROOT_MMNAME_LAST = GCROOT_MMNAME + MM__MAX-1,
 562   GCROOT_BASEMT,        /* Metatables for base types. */
 563   GCROOT_BASEMT_NUM = GCROOT_BASEMT + ~LJ_TNUMX,
 564   GCROOT_IO_INPUT,      /* Userdata for default I/O input file. */
 565   GCROOT_IO_OUTPUT,     /* Userdata for default I/O output file. */
 566   GCROOT_MAX
 567 } GCRootID;
 568 
 569 #define basemt_it(g, it)        ((g)->gcroot[GCROOT_BASEMT+~(it)])
 570 #define basemt_obj(g, o)        ((g)->gcroot[GCROOT_BASEMT+itypemap(o)])
 571 #define mmname_str(g, mm)       (strref((g)->gcroot[GCROOT_MMNAME+(mm)]))
 572 
 573 typedef struct GCState {
 574   GCSize total;         /* Memory currently allocated. */
 575   GCSize threshold;     /* Memory threshold. */
 576   uint8_t currentwhite; /* Current white color. */
 577   uint8_t state;        /* GC state. */
 578   uint8_t nocdatafin;   /* No cdata finalizer called. */
 579   uint8_t unused2;
 580   MSize sweepstr;       /* Sweep position in string table. */
 581   GCRef root;           /* List of all collectable objects. */
 582   MRef sweep;           /* Sweep position in root list. */
 583   GCRef gray;           /* List of gray objects. */
 584   GCRef grayagain;      /* List of objects for atomic traversal. */
 585   GCRef weak;           /* List of weak tables (to be cleared). */
 586   GCRef mmudata;        /* List of userdata (to be finalized). */
 587   GCSize debt;          /* Debt (how much GC is behind schedule). */
 588   GCSize estimate;      /* Estimate of memory actually in use. */
 589   MSize stepmul;        /* Incremental GC step granularity. */
 590   MSize pause;          /* Pause between successive GC cycles. */
 591 } GCState;
 592 
 593 /* Global state, shared by all threads of a Lua universe. */
 594 typedef struct global_State {
 595   GCRef *strhash;       /* String hash table (hash chain anchors). */
 596   MSize strmask;        /* String hash mask (size of hash table - 1). */
 597   MSize strnum;         /* Number of strings in hash table. */
 598   lua_Alloc allocf;     /* Memory allocator. */
 599   void *allocd;         /* Memory allocator data. */
 600   GCState gc;           /* Garbage collector. */
 601   volatile int32_t vmstate;  /* VM state or current JIT code trace number. */
 602   SBuf tmpbuf;          /* Temporary string buffer. */
 603   GCstr strempty;       /* Empty string. */
 604   uint8_t stremptyz;    /* Zero terminator of empty string. */
 605   uint8_t hookmask;     /* Hook mask. */
 606   uint8_t dispatchmode; /* Dispatch mode. */
 607   uint8_t vmevmask;     /* VM event mask. */
 608   GCRef mainthref;      /* Link to main thread. */
 609   TValue registrytv;    /* Anchor for registry. */
 610   TValue tmptv, tmptv2; /* Temporary TValues. */
 611   Node nilnode;         /* Fallback 1-element hash part (nil key and value). */
 612   GCupval uvhead;       /* Head of double-linked list of all open upvalues. */
 613   int32_t hookcount;    /* Instruction hook countdown. */
 614   int32_t hookcstart;   /* Start count for instruction hook counter. */
 615   lua_Hook hookf;       /* Hook function. */
 616   lua_CFunction wrapf;  /* Wrapper for C function calls. */
 617   lua_CFunction panic;  /* Called as a last resort for errors. */
 618   BCIns bc_cfunc_int;   /* Bytecode for internal C function calls. */
 619   BCIns bc_cfunc_ext;   /* Bytecode for external C function calls. */
 620   GCRef cur_L;          /* Currently executing lua_State. */
 621   MRef jit_base;        /* Current JIT code L->base or NULL. */
 622   MRef ctype_state;     /* Pointer to C type state. */
 623   GCRef gcroot[GCROOT_MAX];  /* GC roots. */
 624 } global_State;
 625 
 626 #define mainthread(g)   (&gcref(g->mainthref)->th)
 627 #define niltv(L) \
 628   check_exp(tvisnil(&G(L)->nilnode.val), &G(L)->nilnode.val)
 629 #define niltvg(g) \
 630   check_exp(tvisnil(&(g)->nilnode.val), &(g)->nilnode.val)
 631 
 632 /* Hook management. Hook event masks are defined in lua.h. */
 633 #define HOOK_EVENTMASK          0x0f
 634 #define HOOK_ACTIVE             0x10
 635 #define HOOK_ACTIVE_SHIFT       4
 636 #define HOOK_VMEVENT            0x20
 637 #define HOOK_GC                 0x40
 638 #define HOOK_PROFILE            0x80
 639 #define hook_active(g)          ((g)->hookmask & HOOK_ACTIVE)
 640 #define hook_enter(g)           ((g)->hookmask |= HOOK_ACTIVE)
 641 #define hook_entergc(g)         ((g)->hookmask |= (HOOK_ACTIVE|HOOK_GC))
 642 #define hook_vmevent(g)         ((g)->hookmask |= (HOOK_ACTIVE|HOOK_VMEVENT))
 643 #define hook_leave(g)           ((g)->hookmask &= ~HOOK_ACTIVE)
 644 #define hook_save(g)            ((g)->hookmask & ~HOOK_EVENTMASK)
 645 #define hook_restore(g, h) \
 646   ((g)->hookmask = ((g)->hookmask & HOOK_EVENTMASK) | (h))
 647 
 648 /* Per-thread state object. */
 649 struct lua_State {
 650   GCHeader;
 651   uint8_t dummy_ffid;   /* Fake FF_C for curr_funcisL() on dummy frames. */
 652   uint8_t status;       /* Thread status. */
 653   MRef glref;           /* Link to global state. */
 654   GCRef gclist;         /* GC chain. */
 655   TValue *base;         /* Base of currently executing function. */
 656   TValue *top;          /* First free slot in the stack. */
 657   MRef maxstack;        /* Last free slot in the stack. */
 658   MRef stack;           /* Stack base. */
 659   GCRef openupval;      /* List of open upvalues in the stack. */
 660   GCRef env;            /* Thread environment (table of globals). */
 661   void *cframe;         /* End of C stack frame chain. */
 662   MSize stacksize;      /* True stack size (incl. LJ_STACK_EXTRA). */
 663 };
 664 
 665 #define G(L)                    (mref(L->glref, global_State))
 666 #define registry(L)             (&G(L)->registrytv)
 667 
 668 /* Macros to access the currently executing (Lua) function. */
 669 #if LJ_GC64
 670 #define curr_func(L)            (&gcval(L->base-2)->fn)
 671 #elif LJ_FR2
 672 #define curr_func(L)            (&gcref((L->base-2)->gcr)->fn)
 673 #else
 674 #define curr_func(L)            (&gcref((L->base-1)->fr.func)->fn)
 675 #endif
 676 #define curr_funcisL(L)         (isluafunc(curr_func(L)))
 677 #define curr_proto(L)           (funcproto(curr_func(L)))
 678 #define curr_topL(L)            (L->base + curr_proto(L)->framesize)
 679 #define curr_top(L)             (curr_funcisL(L) ? curr_topL(L) : L->top)
 680 
 681 /* -- GC object definition and conversions -------------------------------- */
 682 
 683 /* GC header for generic access to common fields of GC objects. */
 684 typedef struct GChead {
 685   GCHeader;
 686   uint8_t unused1;
 687   uint8_t unused2;
 688   GCRef env;
 689   GCRef gclist;
 690   GCRef metatable;
 691 } GChead;
 692 
 693 /* The env field SHOULD be at the same offset for all GC objects. */
 694 LJ_STATIC_ASSERT(offsetof(GChead, env) == offsetof(GCfuncL, env));
 695 LJ_STATIC_ASSERT(offsetof(GChead, env) == offsetof(GCudata, env));
 696 
 697 /* The metatable field MUST be at the same offset for all GC objects. */
 698 LJ_STATIC_ASSERT(offsetof(GChead, metatable) == offsetof(GCtab, metatable));
 699 LJ_STATIC_ASSERT(offsetof(GChead, metatable) == offsetof(GCudata, metatable));
 700 
 701 /* The gclist field MUST be at the same offset for all GC objects. */
 702 LJ_STATIC_ASSERT(offsetof(GChead, gclist) == offsetof(lua_State, gclist));
 703 LJ_STATIC_ASSERT(offsetof(GChead, gclist) == offsetof(GCproto, gclist));
 704 LJ_STATIC_ASSERT(offsetof(GChead, gclist) == offsetof(GCfuncL, gclist));
 705 LJ_STATIC_ASSERT(offsetof(GChead, gclist) == offsetof(GCtab, gclist));
 706 
 707 typedef union GCobj {
 708   GChead gch;
 709   GCstr str;
 710   GCupval uv;
 711   lua_State th;
 712   GCproto pt;
 713   GCfunc fn;
 714   GCcdata cd;
 715   GCtab tab;
 716   GCudata ud;
 717 } GCobj;
 718 
 719 /* Macros to convert a GCobj pointer into a specific value. */
 720 #define gco2str(o)      check_exp((o)->gch.gct == ~LJ_TSTR, &(o)->str)
 721 #define gco2uv(o)       check_exp((o)->gch.gct == ~LJ_TUPVAL, &(o)->uv)
 722 #define gco2th(o)       check_exp((o)->gch.gct == ~LJ_TTHREAD, &(o)->th)
 723 #define gco2pt(o)       check_exp((o)->gch.gct == ~LJ_TPROTO, &(o)->pt)
 724 #define gco2func(o)     check_exp((o)->gch.gct == ~LJ_TFUNC, &(o)->fn)
 725 #define gco2cd(o)       check_exp((o)->gch.gct == ~LJ_TCDATA, &(o)->cd)
 726 #define gco2tab(o)      check_exp((o)->gch.gct == ~LJ_TTAB, &(o)->tab)
 727 #define gco2ud(o)       check_exp((o)->gch.gct == ~LJ_TUDATA, &(o)->ud)
 728 
 729 /* Macro to convert any collectable object into a GCobj pointer. */
 730 #define obj2gco(v)      ((GCobj *)(v))
 731 
 732 /* -- TValue getters/setters ---------------------------------------------- */
 733 
 734 #ifdef LUA_USE_ASSERT
 735 #include "lj_gc.h"
 736 #endif
 737 
 738 /* Macros to test types. */
 739 #if LJ_GC64
 740 #define itype(o)        ((uint32_t)((o)->it64 >> 47))
 741 #define tvisnil(o)      ((o)->it64 == -1)
 742 #else
 743 #define itype(o)        ((o)->it)
 744 #define tvisnil(o)      (itype(o) == LJ_TNIL)
 745 #endif
 746 #define tvisfalse(o)    (itype(o) == LJ_TFALSE)
 747 #define tvistrue(o)     (itype(o) == LJ_TTRUE)
 748 #define tvisbool(o)     (tvisfalse(o) || tvistrue(o))
 749 #if LJ_64 && !LJ_GC64
 750 #define tvislightud(o)  (((int32_t)itype(o) >> 15) == -2)
 751 #else
 752 #define tvislightud(o)  (itype(o) == LJ_TLIGHTUD)
 753 #endif
 754 #define tvisstr(o)      (itype(o) == LJ_TSTR)
 755 #define tvisfunc(o)     (itype(o) == LJ_TFUNC)
 756 #define tvisthread(o)   (itype(o) == LJ_TTHREAD)
 757 #define tvisproto(o)    (itype(o) == LJ_TPROTO)
 758 #define tviscdata(o)    (itype(o) == LJ_TCDATA)
 759 #define tvistab(o)      (itype(o) == LJ_TTAB)
 760 #define tvisudata(o)    (itype(o) == LJ_TUDATA)
 761 #define tvisnumber(o)   (itype(o) <= LJ_TISNUM)
 762 #define tvisint(o)      (LJ_DUALNUM && itype(o) == LJ_TISNUM)
 763 #define tvisnum(o)      (itype(o) < LJ_TISNUM)
 764 
 765 #define tvistruecond(o) (itype(o) < LJ_TISTRUECOND)
 766 #define tvispri(o)      (itype(o) >= LJ_TISPRI)
 767 #define tvistabud(o)    (itype(o) <= LJ_TISTABUD)  /* && !tvisnum() */
 768 #define tvisgcv(o)      ((itype(o) - LJ_TISGCV) > (LJ_TNUMX - LJ_TISGCV))
 769 
 770 /* Special macros to test numbers for NaN, +0, -0, +1 and raw equality. */
 771 #define tvisnan(o)      ((o)->n != (o)->n)
 772 #if LJ_64
 773 #define tviszero(o)     (((o)->u64 << 1) == 0)
 774 #else
 775 #define tviszero(o)     (((o)->u32.lo | ((o)->u32.hi << 1)) == 0)
 776 #endif
 777 #define tvispzero(o)    ((o)->u64 == 0)
 778 #define tvismzero(o)    ((o)->u64 == U64x(80000000,00000000))
 779 #define tvispone(o)     ((o)->u64 == U64x(3ff00000,00000000))
 780 #define rawnumequal(o1, o2)     ((o1)->u64 == (o2)->u64)
 781 
 782 /* Macros to convert type ids. */
 783 #if LJ_64 && !LJ_GC64
 784 #define itypemap(o) \
 785   (tvisnumber(o) ? ~LJ_TNUMX : tvislightud(o) ? ~LJ_TLIGHTUD : ~itype(o))
 786 #else
 787 #define itypemap(o)     (tvisnumber(o) ? ~LJ_TNUMX : ~itype(o))
 788 #endif
 789 
 790 /* Macros to get tagged values. */
 791 #if LJ_GC64
 792 #define gcval(o)        ((GCobj *)(gcrefu((o)->gcr) & LJ_GCVMASK))
 793 #else
 794 #define gcval(o)        (gcref((o)->gcr))
 795 #endif
 796 #define boolV(o)        check_exp(tvisbool(o), (LJ_TFALSE - itype(o)))
 797 #if LJ_64
 798 #define lightudV(o) \
 799   check_exp(tvislightud(o), (void *)((o)->u64 & U64x(00007fff,ffffffff)))
 800 #else
 801 #define lightudV(o)     check_exp(tvislightud(o), gcrefp((o)->gcr, void))
 802 #endif
 803 #define gcV(o)          check_exp(tvisgcv(o), gcval(o))
 804 #define strV(o)         check_exp(tvisstr(o), &gcval(o)->str)
 805 #define funcV(o)        check_exp(tvisfunc(o), &gcval(o)->fn)
 806 #define threadV(o)      check_exp(tvisthread(o), &gcval(o)->th)
 807 #define protoV(o)       check_exp(tvisproto(o), &gcval(o)->pt)
 808 #define cdataV(o)       check_exp(tviscdata(o), &gcval(o)->cd)
 809 #define tabV(o)         check_exp(tvistab(o), &gcval(o)->tab)
 810 #define udataV(o)       check_exp(tvisudata(o), &gcval(o)->ud)
 811 #define numV(o)         check_exp(tvisnum(o), (o)->n)
 812 #define intV(o)         check_exp(tvisint(o), (int32_t)(o)->i)
 813 
 814 /* Macros to set tagged values. */
 815 #if LJ_GC64
 816 #define setitype(o, i)          ((o)->it = ((i) << 15))
 817 #define setnilV(o)              ((o)->it64 = -1)
 818 #define setpriV(o, x)           ((o)->it64 = (int64_t)~((uint64_t)~(x)<<47))
 819 #define setboolV(o, x)          ((o)->it64 = (int64_t)~((uint64_t)((x)+1)<<47))
 820 #else
 821 #define setitype(o, i)          ((o)->it = (i))
 822 #define setnilV(o)              ((o)->it = LJ_TNIL)
 823 #define setboolV(o, x)          ((o)->it = LJ_TFALSE-(uint32_t)(x))
 824 #define setpriV(o, i)           (setitype((o), (i)))
 825 #endif
 826 
 827 static LJ_AINLINE void setlightudV(TValue *o, void *p)
 828 {
 829 #if LJ_GC64
 830   o->u64 = (uint64_t)p | (((uint64_t)LJ_TLIGHTUD) << 47);
 831 #elif LJ_64
 832   o->u64 = (uint64_t)p | (((uint64_t)0xffff) << 48);
 833 #else
 834   setgcrefp(o->gcr, p); setitype(o, LJ_TLIGHTUD);
 835 #endif
 836 }
 837 
 838 #if LJ_64
 839 #define checklightudptr(L, p) \
 840   (((uint64_t)(p) >> 47) ? (lj_err_msg(L, LJ_ERR_BADLU), NULL) : (p))
 841 #else
 842 #define checklightudptr(L, p)   (p)
 843 #endif
 844 
 845 #if LJ_FR2
 846 #define contptr(f)              ((void *)(f))
 847 #define setcont(o, f)           ((o)->u64 = (uint64_t)(uintptr_t)contptr(f))
 848 #elif LJ_64
 849 #define contptr(f) \
 850   ((void *)(uintptr_t)(uint32_t)((intptr_t)(f) - (intptr_t)lj_vm_asm_begin))
 851 #define setcont(o, f) \
 852   ((o)->u64 = (uint64_t)(void *)(f) - (uint64_t)lj_vm_asm_begin)
 853 #else
 854 #define contptr(f)              ((void *)(f))
 855 #define setcont(o, f)           setlightudV((o), contptr(f))
 856 #endif
 857 
 858 #define tvchecklive(L, o) \
 859   UNUSED(L), lua_assert(!tvisgcv(o) || \
 860   ((~itype(o) == gcval(o)->gch.gct) && !isdead(G(L), gcval(o))))
 861 
 862 static LJ_AINLINE void setgcVraw(TValue *o, GCobj *v, uint32_t itype)
 863 {
 864 #if LJ_GC64
 865   setgcreft(o->gcr, v, itype);
 866 #else
 867   setgcref(o->gcr, v); setitype(o, itype);
 868 #endif
 869 }
 870 
 871 static LJ_AINLINE void setgcV(lua_State *L, TValue *o, GCobj *v, uint32_t it)
 872 {
 873   setgcVraw(o, v, it); tvchecklive(L, o);
 874 }
 875 
 876 #define define_setV(name, type, tag) \
 877 static LJ_AINLINE void name(lua_State *L, TValue *o, type *v) \
 878 { \
 879   setgcV(L, o, obj2gco(v), tag); \
 880 }
 881 define_setV(setstrV, GCstr, LJ_TSTR)
 882 define_setV(setthreadV, lua_State, LJ_TTHREAD)
 883 define_setV(setprotoV, GCproto, LJ_TPROTO)
 884 define_setV(setfuncV, GCfunc, LJ_TFUNC)
 885 define_setV(setcdataV, GCcdata, LJ_TCDATA)
 886 define_setV(settabV, GCtab, LJ_TTAB)
 887 define_setV(setudataV, GCudata, LJ_TUDATA)
 888 
 889 #define setnumV(o, x)           ((o)->n = (x))
 890 #define setnanV(o)              ((o)->u64 = U64x(fff80000,00000000))
 891 #define setpinfV(o)             ((o)->u64 = U64x(7ff00000,00000000))
 892 #define setminfV(o)             ((o)->u64 = U64x(fff00000,00000000))
 893 
 894 static LJ_AINLINE void setintV(TValue *o, int32_t i)
 895 {
 896 #if LJ_DUALNUM
 897   o->i = (uint32_t)i; setitype(o, LJ_TISNUM);
 898 #else
 899   o->n = (lua_Number)i;
 900 #endif
 901 }
 902 
 903 static LJ_AINLINE void setint64V(TValue *o, int64_t i)
 904 {
 905   if (LJ_DUALNUM && LJ_LIKELY(i == (int64_t)(int32_t)i))
 906     setintV(o, (int32_t)i);
 907   else
 908     setnumV(o, (lua_Number)i);
 909 }
 910 
 911 #if LJ_64
 912 #define setintptrV(o, i)        setint64V((o), (i))
 913 #else
 914 #define setintptrV(o, i)        setintV((o), (i))
 915 #endif
 916 
 917 /* Copy tagged values. */
 918 static LJ_AINLINE void copyTV(lua_State *L, TValue *o1, const TValue *o2)
 919 {
 920   *o1 = *o2; tvchecklive(L, o1);
 921 }
 922 
 923 /* -- Number to integer conversion ---------------------------------------- */
 924 
 925 #if LJ_SOFTFP
 926 LJ_ASMF int32_t lj_vm_tobit(double x);
 927 #if LJ_TARGET_MIPS64
 928 LJ_ASMF int32_t lj_vm_tointg(double x);
 929 #endif
 930 #endif
 931 
 932 static LJ_AINLINE int32_t lj_num2bit(lua_Number n)
 933 {
 934 #if LJ_SOFTFP
 935   return lj_vm_tobit(n);
 936 #else
 937   TValue o;
 938   o.n = n + 6755399441055744.0;  /* 2^52 + 2^51 */
 939   return (int32_t)o.u32.lo;
 940 #endif
 941 }
 942 
 943 #define lj_num2int(n)   ((int32_t)(n))
 944 
 945 static LJ_AINLINE uint64_t lj_num2u64(lua_Number n)
 946 {
 947 #ifdef _MSC_VER
 948   if (n >= 9223372036854775808.0)  /* They think it's a feature. */
 949     return (uint64_t)(int64_t)(n - 18446744073709551616.0);
 950   else
 951 #endif
 952     return (uint64_t)n;
 953 }
 954 
 955 static LJ_AINLINE int32_t numberVint(cTValue *o)
 956 {
 957   if (LJ_LIKELY(tvisint(o)))
 958     return intV(o);
 959   else
 960     return lj_num2int(numV(o));
 961 }
 962 
 963 static LJ_AINLINE lua_Number numberVnum(cTValue *o)
 964 {
 965   if (LJ_UNLIKELY(tvisint(o)))
 966     return (lua_Number)intV(o);
 967   else
 968     return numV(o);
 969 }
 970 
 971 /* -- Miscellaneous object handling --------------------------------------- */
 972 
 973 /* Names and maps for internal and external object tags. */
 974 LJ_DATA const char *const lj_obj_typename[1+LUA_TCDATA+1];
 975 LJ_DATA const char *const lj_obj_itypename[~LJ_TNUMX+1];
 976 
 977 #define lj_typename(o)  (lj_obj_itypename[itypemap(o)])
 978 
 979 /* Compare two objects without calling metamethods. */
 980 LJ_FUNC int LJ_FASTCALL lj_obj_equal(cTValue *o1, cTValue *o2);
 981 LJ_FUNC const void * LJ_FASTCALL lj_obj_ptr(cTValue *o);
 982 
 983 #endif

/* [<][>][^][v][top][bottom][index][help] */