19 typedef uint32_t MSize;
26 #define mref(r, t) ((t *)(void *)(uintptr_t)(r).ptr32) 28 #define setmref(r, p) ((r).ptr32 = (uint32_t)(uintptr_t)(void *)(p)) 29 #define setmrefr(r, v) ((r).ptr32 = (v).ptr32) 39 #define GCHeader GCRef nextgc; uint8_t marked; uint8_t gct 42 #define gcref(r) ((GCobj *)(uintptr_t)(r).gcptr32) 43 #define gcrefp(r, t) ((t *)(void *)(uintptr_t)(r).gcptr32) 44 #define gcrefu(r) ((r).gcptr32) 45 #define gcrefi(r) ((int32_t)(r).gcptr32) 46 #define gcrefeq(r1, r2) ((r1).gcptr32 == (r2).gcptr32) 47 #define gcnext(gc) (gcref((gc)->gch.nextgc)) 49 #define setgcref(r, gc) ((r).gcptr32 = (uint32_t)(uintptr_t)&(gc)->gch) 50 #define setgcrefi(r, i) ((r).gcptr32 = (uint32_t)(i)) 51 #define setgcrefp(r, p) ((r).gcptr32 = (uint32_t)(uintptr_t)(p)) 52 #define setgcrefnull(r) ((r).gcptr32 = 0) 53 #define setgcrefr(r, v) ((r).gcptr32 = (v).gcptr32) 114 typedef uint32_t BCIns;
115 typedef uint32_t BCPos;
116 typedef uint32_t BCReg;
117 typedef int32_t BCLine;
120 typedef void (*ASMFunction)(void);
138 typedef LJ_ALIGN(8)
union TValue {
166 #define tvref(r) (mref(r, TValue)) 169 #define LAST_TT LUA_TTHREAD 170 #define LUA_TPROTO (LAST_TT+1) 171 #define LUA_TCDATA (LAST_TT+2) 194 #define LJ_TNIL (~0u) 195 #define LJ_TFALSE (~1u) 196 #define LJ_TTRUE (~2u) 197 #define LJ_TLIGHTUD (~3u) 198 #define LJ_TSTR (~4u) 199 #define LJ_TUPVAL (~5u) 200 #define LJ_TTHREAD (~6u) 201 #define LJ_TPROTO (~7u) 202 #define LJ_TFUNC (~8u) 203 #define LJ_TTRACE (~9u) 204 #define LJ_TCDATA (~10u) 205 #define LJ_TTAB (~11u) 206 #define LJ_TUDATA (~12u) 208 #define LJ_TNUMX (~13u) 212 #define LJ_TISNUM 0xfffeffffu 214 #define LJ_TISNUM LJ_TNUMX 216 #define LJ_TISTRUECOND LJ_TFALSE 217 #define LJ_TISPRI LJ_TTRUE 218 #define LJ_TISGCV (LJ_TSTR+1) 219 #define LJ_TISTABUD LJ_TTAB 232 #define strref(r) (&gcref((r))->str) 233 #define strdata(s) ((const char *)((s)+1)) 234 #define strdatawr(s) ((char *)((s)+1)) 235 #define strVdata(o) strdata(strV(o)) 236 #define sizestring(s) (sizeof(struct GCstr)+(s)->len+1) 259 #define uddata(u) ((void *)((u)+1)) 260 #define sizeudata(u) (sizeof(struct GCudata)+(u)->len) 277 #define cdataptr(cd) ((void *)((cd)+1)) 278 #define cdataisv(cd) ((cd)->marked & 0x80) 279 #define cdatav(cd) ((GCcdataVar *)((char *)(cd) - sizeof(GCcdataVar))) 280 #define cdatavlen(cd) check_exp(cdataisv(cd), cdatav(cd)->len) 281 #define sizecdatav(cd) (cdatavlen(cd) + cdatav(cd)->extra) 282 #define memcdatav(cd) ((void *)((char *)(cd) - cdatav(cd)->offset)) 286 #define SCALE_NUM_GCO ((int32_t)sizeof(lua_Number)/sizeof(GCRef)) 287 #define round_nkgc(n) (((n) + SCALE_NUM_GCO-1) & ~(SCALE_NUM_GCO-1)) 313 #define PROTO_CHILD 0x01 314 #define PROTO_VARARG 0x02 315 #define PROTO_FFI 0x04 316 #define PROTO_NOJIT 0x08 317 #define PROTO_ILOOP 0x10 319 #define PROTO_HAS_RETURN 0x20 320 #define PROTO_FIXUP_RETURN 0x40 322 #define PROTO_CLCOUNT 0x20 323 #define PROTO_CLC_BITS 3 324 #define PROTO_CLC_POLY (3*PROTO_CLCOUNT) 326 #define PROTO_UV_LOCAL 0x8000 327 #define PROTO_UV_IMMUTABLE 0x4000 329 #define proto_kgc(pt, idx) \ 330 check_exp((uintptr_t)(intptr_t)(idx) >= (uintptr_t)-(intptr_t)(pt)->sizekgc, \ 331 gcref(mref((pt)->k, GCRef)[(idx)])) 332 #define proto_knumtv(pt, idx) \ 333 check_exp((uintptr_t)(idx) < (pt)->sizekn, &mref((pt)->k, TValue)[(idx)]) 334 #define proto_bc(pt) ((BCIns *)((char *)(pt) + sizeof(GCproto))) 335 #define proto_bcpos(pt, pc) ((BCPos)((pc) - proto_bc(pt))) 336 #define proto_uv(pt) (mref((pt)->uv, uint16_t)) 338 #define proto_chunkname(pt) (strref((pt)->chunkname)) 339 #define proto_chunknamestr(pt) (strdata(proto_chunkname((pt)))) 340 #define proto_lineinfo(pt) (mref((pt)->lineinfo, const void)) 341 #define proto_uvinfo(pt) (mref((pt)->uvinfo, const uint8_t)) 342 #define proto_varinfo(pt) (mref((pt)->varinfo, const uint8_t)) 361 #define uvprev(uv_) (&gcref((uv_)->prev)->uv) 362 #define uvnext(uv_) (&gcref((uv_)->next)->uv) 363 #define uvval(uv_) (mref((uv_)->v, TValue)) 368 #define GCfuncHeader \ 369 GCHeader; uint8_t ffid; uint8_t nupvalues; \ 370 GCRef env; GCRef gclist; MRef pc 390 #define isluafunc(fn) ((fn)->c.ffid == FF_LUA) 391 #define iscfunc(fn) ((fn)->c.ffid == FF_C) 392 #define isffunc(fn) ((fn)->c.ffid > FF_C) 393 #define funcproto(fn) \ 394 check_exp(isluafunc(fn), (GCproto *)(mref((fn)->l.pc, char)-sizeof(GCproto))) 395 #define sizeCfunc(n) (sizeof(GCfuncC)-sizeof(TValue)+sizeof(TValue)*(n)) 396 #define sizeLfunc(n) (sizeof(GCfuncL)-sizeof(GCRef)+sizeof(GCRef)*(n)) 401 typedef struct Node {
408 LJ_STATIC_ASSERT(offsetof(
Node, val) == 0);
422 #define sizetabcolo(n) ((n)*sizeof(TValue) + sizeof(GCtab)) 423 #define tabref(r) (&gcref((r))->tab) 424 #define noderef(r) (mref((r), Node)) 425 #define nextnode(n) (mref((n)->next, Node)) 441 #define setvmstate(g, st) ((g)->vmstate = ~LJ_VMST_##st) 445 #define MMDEF_FFI(_) _(new) 450 #if LJ_52 || LJ_HASFFI 451 #define MMDEF_PAIRS(_) _(pairs) _(ipairs) 453 #define MMDEF_PAIRS(_) 455 #define MM_ipairs 255 459 _(index) _(newindex) _(gc) _(mode) _(eq) _(len) \ 461 _(lt) _(le) _(concat) _(call) \ 463 _(add) _(sub) _(mul) _(div) _(mod) _(pow) _(unm) \ 465 _(metatable) _(tostring) MMDEF_FFI(_) MMDEF_PAIRS(_) 468 #define MMENUM(name) MM_##name, 479 GCROOT_MMNAME_LAST = GCROOT_MMNAME + MM__MAX-1,
481 GCROOT_BASEMT_NUM = GCROOT_BASEMT + ~LJ_TNUMX,
487 #define basemt_it(g, it) ((g)->gcroot[GCROOT_BASEMT+~(it)]) 488 #define basemt_obj(g, o) ((g)->gcroot[GCROOT_BASEMT+itypemap(o)]) 489 #define mmname_str(g, mm) (strref((g)->gcroot[GCROOT_MMNAME+(mm)])) 494 uint8_t currentwhite;
524 uint8_t dispatchmode;
535 volatile int32_t vmstate;
541 GCRef gcroot[GCROOT_MAX];
544 #define mainthread(g) (&gcref(g->mainthref)->th) 546 check_exp(tvisnil(&G(L)->nilnode.val), &G(L)->nilnode.val) 548 check_exp(tvisnil(&(g)->nilnode.val), &(g)->nilnode.val) 551 #define HOOK_EVENTMASK 0x0f 552 #define HOOK_ACTIVE 0x10 553 #define HOOK_ACTIVE_SHIFT 4 554 #define HOOK_VMEVENT 0x20 556 #define hook_active(g) ((g)->hookmask & HOOK_ACTIVE) 557 #define hook_enter(g) ((g)->hookmask |= HOOK_ACTIVE) 558 #define hook_entergc(g) ((g)->hookmask |= (HOOK_ACTIVE|HOOK_GC)) 559 #define hook_vmevent(g) ((g)->hookmask |= (HOOK_ACTIVE|HOOK_VMEVENT)) 560 #define hook_leave(g) ((g)->hookmask &= ~HOOK_ACTIVE) 561 #define hook_save(g) ((g)->hookmask & ~HOOK_EVENTMASK) 562 #define hook_restore(g, h) \ 563 ((g)->hookmask = ((g)->hookmask & HOOK_EVENTMASK) | (h)) 582 #define G(L) (mref(L->glref, global_State)) 583 #define registry(L) (&G(L)->registrytv) 586 #define curr_func(L) (&gcref((L->base-1)->fr.func)->fn) 587 #define curr_funcisL(L) (isluafunc(curr_func(L))) 588 #define curr_proto(L) (funcproto(curr_func(L))) 589 #define curr_topL(L) (L->base + curr_proto(L)->framesize) 590 #define curr_top(L) (curr_funcisL(L) ? curr_topL(L) : L->top) 605 LJ_STATIC_ASSERT(offsetof(
GChead, env) == offsetof(
GCfuncL, env));
606 LJ_STATIC_ASSERT(offsetof(
GChead, env) == offsetof(
GCudata, env));
609 LJ_STATIC_ASSERT(offsetof(
GChead, metatable) == offsetof(
GCtab, metatable));
610 LJ_STATIC_ASSERT(offsetof(
GChead, metatable) == offsetof(
GCudata, metatable));
613 LJ_STATIC_ASSERT(offsetof(
GChead, gclist) == offsetof(
lua_State, gclist));
614 LJ_STATIC_ASSERT(offsetof(
GChead, gclist) == offsetof(
GCproto, gclist));
615 LJ_STATIC_ASSERT(offsetof(
GChead, gclist) == offsetof(
GCfuncL, gclist));
616 LJ_STATIC_ASSERT(offsetof(
GChead, gclist) == offsetof(
GCtab, gclist));
631 #define gco2str(o) check_exp((o)->gch.gct == ~LJ_TSTR, &(o)->str) 632 #define gco2uv(o) check_exp((o)->gch.gct == ~LJ_TUPVAL, &(o)->uv) 633 #define gco2th(o) check_exp((o)->gch.gct == ~LJ_TTHREAD, &(o)->th) 634 #define gco2pt(o) check_exp((o)->gch.gct == ~LJ_TPROTO, &(o)->pt) 635 #define gco2func(o) check_exp((o)->gch.gct == ~LJ_TFUNC, &(o)->fn) 636 #define gco2cd(o) check_exp((o)->gch.gct == ~LJ_TCDATA, &(o)->cd) 637 #define gco2tab(o) check_exp((o)->gch.gct == ~LJ_TTAB, &(o)->tab) 638 #define gco2ud(o) check_exp((o)->gch.gct == ~LJ_TUDATA, &(o)->ud) 641 #define obj2gco(v) ((GCobj *)(v)) 645 #ifdef LUA_USE_ASSERT 650 #define itype(o) ((o)->it) 651 #define tvisnil(o) (itype(o) == LJ_TNIL) 652 #define tvisfalse(o) (itype(o) == LJ_TFALSE) 653 #define tvistrue(o) (itype(o) == LJ_TTRUE) 654 #define tvisbool(o) (tvisfalse(o) || tvistrue(o)) 656 #define tvislightud(o) (((int32_t)itype(o) >> 15) == -2) 658 #define tvislightud(o) (itype(o) == LJ_TLIGHTUD) 660 #define tvisstr(o) (itype(o) == LJ_TSTR) 661 #define tvisfunc(o) (itype(o) == LJ_TFUNC) 662 #define tvisthread(o) (itype(o) == LJ_TTHREAD) 663 #define tvisproto(o) (itype(o) == LJ_TPROTO) 664 #define tviscdata(o) (itype(o) == LJ_TCDATA) 665 #define tvistab(o) (itype(o) == LJ_TTAB) 666 #define tvisudata(o) (itype(o) == LJ_TUDATA) 667 #define tvisnumber(o) (itype(o) <= LJ_TISNUM) 668 #define tvisint(o) (LJ_DUALNUM && itype(o) == LJ_TISNUM) 669 #define tvisnum(o) (itype(o) < LJ_TISNUM) 671 #define tvistruecond(o) (itype(o) < LJ_TISTRUECOND) 672 #define tvispri(o) (itype(o) >= LJ_TISPRI) 673 #define tvistabud(o) (itype(o) <= LJ_TISTABUD) 674 #define tvisgcv(o) ((itype(o) - LJ_TISGCV) > (LJ_TNUMX - LJ_TISGCV)) 677 #define tvisnan(o) ((o)->n != (o)->n) 679 #define tviszero(o) (((o)->u64 << 1) == 0) 681 #define tviszero(o) (((o)->u32.lo | ((o)->u32.hi << 1)) == 0) 683 #define tvispzero(o) ((o)->u64 == 0) 684 #define tvismzero(o) ((o)->u64 == U64x(80000000,00000000)) 685 #define tvispone(o) ((o)->u64 == U64x(3ff00000,00000000)) 686 #define rawnumequal(o1, o2) ((o1)->u64 == (o2)->u64) 690 #define itypemap(o) \ 691 (tvisnumber(o) ? ~LJ_TNUMX : tvislightud(o) ? ~LJ_TLIGHTUD : ~itype(o)) 693 #define itypemap(o) (tvisnumber(o) ? ~LJ_TNUMX : ~itype(o)) 697 #define gcval(o) (gcref((o)->gcr)) 698 #define boolV(o) check_exp(tvisbool(o), (LJ_TFALSE - (o)->it)) 700 #define lightudV(o) \ 701 check_exp(tvislightud(o), (void *)((o)->u64 & U64x(00007fff,ffffffff))) 703 #define lightudV(o) check_exp(tvislightud(o), gcrefp((o)->gcr, void)) 705 #define gcV(o) check_exp(tvisgcv(o), gcval(o)) 706 #define strV(o) check_exp(tvisstr(o), &gcval(o)->str) 707 #define funcV(o) check_exp(tvisfunc(o), &gcval(o)->fn) 708 #define threadV(o) check_exp(tvisthread(o), &gcval(o)->th) 709 #define protoV(o) check_exp(tvisproto(o), &gcval(o)->pt) 710 #define cdataV(o) check_exp(tviscdata(o), &gcval(o)->cd) 711 #define tabV(o) check_exp(tvistab(o), &gcval(o)->tab) 712 #define udataV(o) check_exp(tvisudata(o), &gcval(o)->ud) 713 #define numV(o) check_exp(tvisnum(o), (o)->n) 714 #define intV(o) check_exp(tvisint(o), (int32_t)(o)->i) 717 #define setitype(o, i) ((o)->it = (i)) 718 #define setnilV(o) ((o)->it = LJ_TNIL) 719 #define setboolV(o, x) ((o)->it = LJ_TFALSE-(uint32_t)(x)) 721 static LJ_AINLINE
void setlightudV(
TValue *o,
void *p)
724 o->u64 = (uint64_t)p | (((uint64_t)0xffff) << 48);
726 setgcrefp(o->gcr, p); setitype(o, LJ_TLIGHTUD);
731 #define checklightudptr(L, p) \ 732 (((uint64_t)(p) >> 47) ? (lj_err_msg(L, LJ_ERR_BADLU), NULL) : (p)) 733 #define setcont(o, f) \ 734 ((o)->u64 = (uint64_t)(void *)(f) - (uint64_t)lj_vm_asm_begin) 736 #define checklightudptr(L, p) (p) 737 #define setcont(o, f) setlightudV((o), (void *)(f)) 740 #define tvchecklive(L, o) \ 741 UNUSED(L), lua_assert(!tvisgcv(o) || \ 742 ((~itype(o) == gcval(o)->gch.gct) && !isdead(G(L), gcval(o)))) 746 setgcref(o->gcr, v); setitype(o, itype); tvchecklive(L, o);
749 #define define_setV(name, type, tag) \ 750 static LJ_AINLINE void name(lua_State *L, TValue *o, type *v) \ 752 setgcV(L, o, obj2gco(v), tag); \ 754 define_setV(setstrV,
GCstr, LJ_TSTR)
755 define_setV(setthreadV,
lua_State, LJ_TTHREAD)
756 define_setV(setprotoV,
GCproto, LJ_TPROTO)
757 define_setV(setfuncV,
GCfunc, LJ_TFUNC)
758 define_setV(setcdataV,
GCcdata, LJ_TCDATA)
759 define_setV(settabV,
GCtab, LJ_TTAB)
760 define_setV(setudataV,
GCudata, LJ_TUDATA)
762 #define setnumV(o, x) ((o)->n = (x)) 763 #define setnanV(o) ((o)->u64 = U64x(fff80000,00000000)) 764 #define setpinfV(o) ((o)->u64 = U64x(7ff00000,00000000)) 765 #define setminfV(o) ((o)->u64 = U64x(fff00000,00000000)) 767 static LJ_AINLINE
void setintV(
TValue *o, int32_t i)
770 o->i = (uint32_t)i; setitype(o, LJ_TISNUM);
772 o->n = (lua_Number)i;
776 static LJ_AINLINE
void setint64V(
TValue *o, int64_t i)
778 if (LJ_DUALNUM && LJ_LIKELY(i == (int64_t)(int32_t)i))
779 setintV(o, (int32_t)i);
781 setnumV(o, (lua_Number)i);
785 #define setintptrV(o, i) setint64V((o), (i)) 787 #define setintptrV(o, i) setintV((o), (i)) 793 *o1 = *o2; tvchecklive(L, o1);
799 LJ_ASMF int32_t lj_vm_tobit(
double x);
802 static LJ_AINLINE int32_t lj_num2bit(lua_Number n)
805 return lj_vm_tobit(n);
808 o.n = n + 6755399441055744.0;
809 return (int32_t)o.u32.lo;
813 #if LJ_TARGET_X86 && !defined(__SSE2__) 814 #define lj_num2int(n) lj_num2bit((n)) 816 #define lj_num2int(n) ((int32_t)(n)) 819 static LJ_AINLINE uint64_t lj_num2u64(lua_Number n)
822 if (n >= 9223372036854775808.0)
823 return (uint64_t)(int64_t)(n - 18446744073709551616.0);
829 static LJ_AINLINE int32_t numberVint(
cTValue *o)
831 if (LJ_LIKELY(tvisint(o)))
834 return lj_num2int(numV(o));
837 static LJ_AINLINE lua_Number numberVnum(
cTValue *o)
839 if (LJ_UNLIKELY(tvisint(o)))
840 return (lua_Number)intV(o);
848 LJ_DATA
const char *
const lj_obj_typename[1+LUA_TCDATA+1];
849 LJ_DATA
const char *
const lj_obj_itypename[~LJ_TNUMX+1];
851 #define lj_typename(o) (lj_obj_itypename[itypemap(o)])
Definition: minilua.c:352
Definition: minilua.c:461
Definition: minilua.c:231
Definition: minilua.c:434