diff options
Diffstat (limited to 'src/lj_obj.h')
-rw-r--r-- | src/lj_obj.h | 38 |
1 files changed, 34 insertions, 4 deletions
diff --git a/src/lj_obj.h b/src/lj_obj.h index cbb25675..83e30b6e 100644 --- a/src/lj_obj.h +++ b/src/lj_obj.h | |||
@@ -165,6 +165,7 @@ typedef const TValue cTValue; | |||
165 | /* More external and GCobj tags for internal objects. */ | 165 | /* More external and GCobj tags for internal objects. */ |
166 | #define LAST_TT LUA_TTHREAD | 166 | #define LAST_TT LUA_TTHREAD |
167 | #define LUA_TPROTO (LAST_TT+1) | 167 | #define LUA_TPROTO (LAST_TT+1) |
168 | #define LUA_TCDATA (LAST_TT+2) | ||
168 | 169 | ||
169 | /* Internal object tags. | 170 | /* Internal object tags. |
170 | ** | 171 | ** |
@@ -196,10 +197,11 @@ typedef const TValue cTValue; | |||
196 | #define LJ_TPROTO (~7u) | 197 | #define LJ_TPROTO (~7u) |
197 | #define LJ_TFUNC (~8u) | 198 | #define LJ_TFUNC (~8u) |
198 | #define LJ_TTRACE (~9u) | 199 | #define LJ_TTRACE (~9u) |
199 | #define LJ_TTAB (~10u) | 200 | #define LJ_TCDATA (~10u) |
200 | #define LJ_TUDATA (~11u) | 201 | #define LJ_TTAB (~11u) |
202 | #define LJ_TUDATA (~12u) | ||
201 | /* This is just the canonical number type used in some places. */ | 203 | /* This is just the canonical number type used in some places. */ |
202 | #define LJ_TNUMX (~12u) | 204 | #define LJ_TNUMX (~13u) |
203 | 205 | ||
204 | #if LJ_64 | 206 | #if LJ_64 |
205 | #define LJ_TISNUM 0xfffeffffu | 207 | #define LJ_TISNUM 0xfffeffffu |
@@ -251,6 +253,28 @@ enum { | |||
251 | #define uddata(u) ((void *)((u)+1)) | 253 | #define uddata(u) ((void *)((u)+1)) |
252 | #define sizeudata(u) (sizeof(struct GCudata)+(u)->len) | 254 | #define sizeudata(u) (sizeof(struct GCudata)+(u)->len) |
253 | 255 | ||
256 | /* -- C data object ------------------------------------------------------- */ | ||
257 | |||
258 | /* C data object. Payload follows. */ | ||
259 | typedef struct GCcdata { | ||
260 | GCHeader; | ||
261 | uint16_t typeid; /* C type ID. */ | ||
262 | } GCcdata; | ||
263 | |||
264 | /* Prepended to variable-sized or realigned C data objects. */ | ||
265 | typedef struct GCcdataVar { | ||
266 | uint16_t offset; /* Offset to allocated memory (relative to GCcdata). */ | ||
267 | uint16_t extra; /* Extra space allocated (incl. GCcdata + GCcdatav). */ | ||
268 | MSize len; /* Size of payload. */ | ||
269 | } GCcdataVar; | ||
270 | |||
271 | #define cdataptr(cd) ((void *)((cd)+1)) | ||
272 | #define cdataisv(cd) ((cd)->marked & 0x80) | ||
273 | #define cdatav(cd) ((GCcdataVar *)((char *)(cd) - sizeof(GCcdataVar))) | ||
274 | #define cdatavlen(cd) check_exp(cdataisv(cd), cdatav(cd)->len) | ||
275 | #define sizecdatav(cd) (cdatavlen(cd) + cdatav(cd)->extra) | ||
276 | #define memcdatav(cd) ((void *)((char *)(cd) - cdatav(cd)->offset)) | ||
277 | |||
254 | /* -- Prototype object ---------------------------------------------------- */ | 278 | /* -- Prototype object ---------------------------------------------------- */ |
255 | 279 | ||
256 | #define SCALE_NUM_GCO ((int32_t)sizeof(lua_Number)/sizeof(GCRef)) | 280 | #define SCALE_NUM_GCO ((int32_t)sizeof(lua_Number)/sizeof(GCRef)) |
@@ -498,6 +522,7 @@ typedef struct global_State { | |||
498 | BCIns bc_cfunc_ext; /* Bytecode for external C function calls. */ | 522 | BCIns bc_cfunc_ext; /* Bytecode for external C function calls. */ |
499 | GCRef jit_L; /* Current JIT code lua_State or NULL. */ | 523 | GCRef jit_L; /* Current JIT code lua_State or NULL. */ |
500 | MRef jit_base; /* Current JIT code L->base. */ | 524 | MRef jit_base; /* Current JIT code L->base. */ |
525 | MRef ctype_state; /* Pointer to C type state. */ | ||
501 | GCRef gcroot[GCROOT_MAX]; /* GC roots. */ | 526 | GCRef gcroot[GCROOT_MAX]; /* GC roots. */ |
502 | } global_State; | 527 | } global_State; |
503 | 528 | ||
@@ -582,6 +607,7 @@ typedef union GCobj { | |||
582 | lua_State th; | 607 | lua_State th; |
583 | GCproto pt; | 608 | GCproto pt; |
584 | GCfunc fn; | 609 | GCfunc fn; |
610 | GCcdata cd; | ||
585 | GCtab tab; | 611 | GCtab tab; |
586 | GCudata ud; | 612 | GCudata ud; |
587 | } GCobj; | 613 | } GCobj; |
@@ -592,6 +618,7 @@ typedef union GCobj { | |||
592 | #define gco2th(o) check_exp((o)->gch.gct == ~LJ_TTHREAD, &(o)->th) | 618 | #define gco2th(o) check_exp((o)->gch.gct == ~LJ_TTHREAD, &(o)->th) |
593 | #define gco2pt(o) check_exp((o)->gch.gct == ~LJ_TPROTO, &(o)->pt) | 619 | #define gco2pt(o) check_exp((o)->gch.gct == ~LJ_TPROTO, &(o)->pt) |
594 | #define gco2func(o) check_exp((o)->gch.gct == ~LJ_TFUNC, &(o)->fn) | 620 | #define gco2func(o) check_exp((o)->gch.gct == ~LJ_TFUNC, &(o)->fn) |
621 | #define gco2cd(o) check_exp((o)->gch.gct == ~LJ_TCDATA, &(o)->cd) | ||
595 | #define gco2tab(o) check_exp((o)->gch.gct == ~LJ_TTAB, &(o)->tab) | 622 | #define gco2tab(o) check_exp((o)->gch.gct == ~LJ_TTAB, &(o)->tab) |
596 | #define gco2ud(o) check_exp((o)->gch.gct == ~LJ_TUDATA, &(o)->ud) | 623 | #define gco2ud(o) check_exp((o)->gch.gct == ~LJ_TUDATA, &(o)->ud) |
597 | 624 | ||
@@ -619,6 +646,7 @@ typedef union GCobj { | |||
619 | #define tvisfunc(o) (itype(o) == LJ_TFUNC) | 646 | #define tvisfunc(o) (itype(o) == LJ_TFUNC) |
620 | #define tvisthread(o) (itype(o) == LJ_TTHREAD) | 647 | #define tvisthread(o) (itype(o) == LJ_TTHREAD) |
621 | #define tvisproto(o) (itype(o) == LJ_TPROTO) | 648 | #define tvisproto(o) (itype(o) == LJ_TPROTO) |
649 | #define tviscdata(o) (itype(o) == LJ_TCDATA) | ||
622 | #define tvistab(o) (itype(o) == LJ_TTAB) | 650 | #define tvistab(o) (itype(o) == LJ_TTAB) |
623 | #define tvisudata(o) (itype(o) == LJ_TUDATA) | 651 | #define tvisudata(o) (itype(o) == LJ_TUDATA) |
624 | #define tvisnum(o) (itype(o) <= LJ_TISNUM) | 652 | #define tvisnum(o) (itype(o) <= LJ_TISNUM) |
@@ -657,6 +685,7 @@ typedef union GCobj { | |||
657 | #define funcV(o) check_exp(tvisfunc(o), &gcval(o)->fn) | 685 | #define funcV(o) check_exp(tvisfunc(o), &gcval(o)->fn) |
658 | #define threadV(o) check_exp(tvisthread(o), &gcval(o)->th) | 686 | #define threadV(o) check_exp(tvisthread(o), &gcval(o)->th) |
659 | #define protoV(o) check_exp(tvisproto(o), &gcval(o)->pt) | 687 | #define protoV(o) check_exp(tvisproto(o), &gcval(o)->pt) |
688 | #define cdataV(o) check_exp(tviscdata(o), &gcval(o)->cd) | ||
660 | #define tabV(o) check_exp(tvistab(o), &gcval(o)->tab) | 689 | #define tabV(o) check_exp(tvistab(o), &gcval(o)->tab) |
661 | #define udataV(o) check_exp(tvisudata(o), &gcval(o)->ud) | 690 | #define udataV(o) check_exp(tvisudata(o), &gcval(o)->ud) |
662 | #define numV(o) check_exp(tvisnum(o), (o)->n) | 691 | #define numV(o) check_exp(tvisnum(o), (o)->n) |
@@ -703,6 +732,7 @@ define_setV(setstrV, GCstr, LJ_TSTR) | |||
703 | define_setV(setthreadV, lua_State, LJ_TTHREAD) | 732 | define_setV(setthreadV, lua_State, LJ_TTHREAD) |
704 | define_setV(setprotoV, GCproto, LJ_TPROTO) | 733 | define_setV(setprotoV, GCproto, LJ_TPROTO) |
705 | define_setV(setfuncV, GCfunc, LJ_TFUNC) | 734 | define_setV(setfuncV, GCfunc, LJ_TFUNC) |
735 | define_setV(setcdataV, GCcdata, LJ_TCDATA) | ||
706 | define_setV(settabV, GCtab, LJ_TTAB) | 736 | define_setV(settabV, GCtab, LJ_TTAB) |
707 | define_setV(setudataV, GCudata, LJ_TUDATA) | 737 | define_setV(setudataV, GCudata, LJ_TUDATA) |
708 | 738 | ||
@@ -734,7 +764,7 @@ static LJ_AINLINE int32_t lj_num2bit(lua_Number n) | |||
734 | /* -- Miscellaneous object handling --------------------------------------- */ | 764 | /* -- Miscellaneous object handling --------------------------------------- */ |
735 | 765 | ||
736 | /* Names and maps for internal and external object tags. */ | 766 | /* Names and maps for internal and external object tags. */ |
737 | LJ_DATA const char *const lj_obj_typename[1+LUA_TPROTO+1]; | 767 | LJ_DATA const char *const lj_obj_typename[1+LUA_TCDATA+1]; |
738 | LJ_DATA const char *const lj_obj_itypename[~LJ_TNUMX+1]; | 768 | LJ_DATA const char *const lj_obj_itypename[~LJ_TNUMX+1]; |
739 | 769 | ||
740 | #define typename(o) (lj_obj_itypename[itypemap(o)]) | 770 | #define typename(o) (lj_obj_itypename[itypemap(o)]) |