15 #include "llimits.h" |
15 #include "llimits.h" |
16 #include "lua.h" |
16 #include "lua.h" |
17 |
17 |
18 |
18 |
19 /* tags for values visible from Lua */ |
19 /* tags for values visible from Lua */ |
20 #define LAST_TAG LUA_TTHREAD |
20 #define LAST_TAG LUA_TTHREAD |
21 |
21 |
22 #define NUM_TAGS (LAST_TAG+1) |
22 #define NUM_TAGS (LAST_TAG+1) |
23 |
23 |
24 |
24 |
25 /* |
25 /* |
26 ** Extra tags for non-values |
26 ** Extra tags for non-values |
27 */ |
27 */ |
28 #define LUA_TPROTO (LAST_TAG+1) |
28 #define LUA_TPROTO (LAST_TAG+1) |
29 #define LUA_TUPVAL (LAST_TAG+2) |
29 #define LUA_TUPVAL (LAST_TAG+2) |
30 #define LUA_TDEADKEY (LAST_TAG+3) |
30 #define LUA_TDEADKEY (LAST_TAG+3) |
31 |
31 |
32 |
32 |
33 /* |
33 /* |
34 ** Union of all collectable objects |
34 ** Union of all collectable objects |
35 */ |
35 */ |
66 |
66 |
67 /* |
67 /* |
68 ** Tagged Values |
68 ** Tagged Values |
69 */ |
69 */ |
70 |
70 |
71 #define TValuefields Value value; int tt |
71 #define TValuefields Value value; int tt |
72 |
72 |
73 typedef struct lua_TValue { |
73 typedef struct lua_TValue { |
74 TValuefields; |
74 TValuefields; |
75 } TValue; |
75 } TValue; |
76 |
76 |
77 |
77 |
78 /* Macros to test type */ |
78 /* Macros to test type */ |
79 #define ttisnil(o) (ttype(o) == LUA_TNIL) |
79 #define ttisnil(o) (ttype(o) == LUA_TNIL) |
80 #define ttisnumber(o) (ttype(o) == LUA_TNUMBER) |
80 #define ttisnumber(o) (ttype(o) == LUA_TNUMBER) |
81 #define ttisstring(o) (ttype(o) == LUA_TSTRING) |
81 #define ttisstring(o) (ttype(o) == LUA_TSTRING) |
82 #define ttistable(o) (ttype(o) == LUA_TTABLE) |
82 #define ttistable(o) (ttype(o) == LUA_TTABLE) |
83 #define ttisfunction(o) (ttype(o) == LUA_TFUNCTION) |
83 #define ttisfunction(o) (ttype(o) == LUA_TFUNCTION) |
84 #define ttisboolean(o) (ttype(o) == LUA_TBOOLEAN) |
84 #define ttisboolean(o) (ttype(o) == LUA_TBOOLEAN) |
85 #define ttisuserdata(o) (ttype(o) == LUA_TUSERDATA) |
85 #define ttisuserdata(o) (ttype(o) == LUA_TUSERDATA) |
86 #define ttisthread(o) (ttype(o) == LUA_TTHREAD) |
86 #define ttisthread(o) (ttype(o) == LUA_TTHREAD) |
87 #define ttislightuserdata(o) (ttype(o) == LUA_TLIGHTUSERDATA) |
87 #define ttislightuserdata(o) (ttype(o) == LUA_TLIGHTUSERDATA) |
88 |
88 |
89 /* Macros to access values */ |
89 /* Macros to access values */ |
90 #define ttype(o) ((o)->tt) |
90 #define ttype(o) ((o)->tt) |
91 #define gcvalue(o) check_exp(iscollectable(o), (o)->value.gc) |
91 #define gcvalue(o) check_exp(iscollectable(o), (o)->value.gc) |
92 #define pvalue(o) check_exp(ttislightuserdata(o), (o)->value.p) |
92 #define pvalue(o) check_exp(ttislightuserdata(o), (o)->value.p) |
93 #define nvalue(o) check_exp(ttisnumber(o), (o)->value.n) |
93 #define nvalue(o) check_exp(ttisnumber(o), (o)->value.n) |
94 #define rawtsvalue(o) check_exp(ttisstring(o), &(o)->value.gc->ts) |
94 #define rawtsvalue(o) check_exp(ttisstring(o), &(o)->value.gc->ts) |
95 #define tsvalue(o) (&rawtsvalue(o)->tsv) |
95 #define tsvalue(o) (&rawtsvalue(o)->tsv) |
96 #define rawuvalue(o) check_exp(ttisuserdata(o), &(o)->value.gc->u) |
96 #define rawuvalue(o) check_exp(ttisuserdata(o), &(o)->value.gc->u) |
97 #define uvalue(o) (&rawuvalue(o)->uv) |
97 #define uvalue(o) (&rawuvalue(o)->uv) |
98 #define clvalue(o) check_exp(ttisfunction(o), &(o)->value.gc->cl) |
98 #define clvalue(o) check_exp(ttisfunction(o), &(o)->value.gc->cl) |
99 #define hvalue(o) check_exp(ttistable(o), &(o)->value.gc->h) |
99 #define hvalue(o) check_exp(ttistable(o), &(o)->value.gc->h) |
100 #define bvalue(o) check_exp(ttisboolean(o), (o)->value.b) |
100 #define bvalue(o) check_exp(ttisboolean(o), (o)->value.b) |
101 #define thvalue(o) check_exp(ttisthread(o), &(o)->value.gc->th) |
101 #define thvalue(o) check_exp(ttisthread(o), &(o)->value.gc->th) |
102 |
102 |
103 #define l_isfalse(o) (ttisnil(o) || (ttisboolean(o) && bvalue(o) == 0)) |
103 #define l_isfalse(o) (ttisnil(o) || (ttisboolean(o) && bvalue(o) == 0)) |
104 |
104 |
105 /* |
105 /* |
106 ** for internal debug only |
106 ** for internal debug only |
107 */ |
107 */ |
108 #define checkconsistency(obj) \ |
108 #define checkconsistency(obj) \ |
167 /* |
167 /* |
168 ** different types of sets, according to destination |
168 ** different types of sets, according to destination |
169 */ |
169 */ |
170 |
170 |
171 /* from stack to (same) stack */ |
171 /* from stack to (same) stack */ |
172 #define setobjs2s setobj |
172 #define setobjs2s setobj |
173 /* to stack (not from same stack) */ |
173 /* to stack (not from same stack) */ |
174 #define setobj2s setobj |
174 #define setobj2s setobj |
175 #define setsvalue2s setsvalue |
175 #define setsvalue2s setsvalue |
176 #define sethvalue2s sethvalue |
176 #define sethvalue2s sethvalue |
177 #define setptvalue2s setptvalue |
177 #define setptvalue2s setptvalue |
178 /* from table to same table */ |
178 /* from table to same table */ |
179 #define setobjt2t setobj |
179 #define setobjt2t setobj |
180 /* to table */ |
180 /* to table */ |
181 #define setobj2t setobj |
181 #define setobj2t setobj |
182 /* to new object */ |
182 /* to new object */ |
183 #define setobj2n setobj |
183 #define setobj2n setobj |
184 #define setsvalue2n setsvalue |
184 #define setsvalue2n setsvalue |
185 |
185 |
186 #define setttype(obj, tt) (ttype(obj) = (tt)) |
186 #define setttype(obj, tt) (ttype(obj) = (tt)) |
187 |
187 |
188 |
188 |
189 #define iscollectable(o) (ttype(o) >= LUA_TSTRING) |
189 #define iscollectable(o) (ttype(o) >= LUA_TSTRING) |
190 |
190 |
191 |
191 |
192 |
192 |
193 typedef TValue *StkId; /* index to stack elements */ |
193 typedef TValue *StkId; /* index to stack elements */ |
194 |
194 |
351 |
351 |
352 /* |
352 /* |
353 ** `module' operation for hashing (size is always a power of 2) |
353 ** `module' operation for hashing (size is always a power of 2) |
354 */ |
354 */ |
355 #define lmod(s,size) \ |
355 #define lmod(s,size) \ |
356 (check_exp((size&(size-1))==0, (cast(int, (s) & ((size)-1))))) |
356 (check_exp((size&(size-1))==0, (cast(int, (s) & ((size)-1))))) |
357 |
357 |
358 |
358 |
359 #define twoto(x) (1<<(x)) |
359 #define twoto(x) (1<<(x)) |
360 #define sizenode(t) (twoto((t)->lsizenode)) |
360 #define sizenode(t) (twoto((t)->lsizenode)) |
361 |
361 |
362 |
362 |
363 #define luaO_nilobject (&luaO_nilobject_) |
363 #define luaO_nilobject (&luaO_nilobject_) |
364 |
364 |
365 LUAI_DATA const TValue luaO_nilobject_; |
365 LUAI_DATA const TValue luaO_nilobject_; |
366 |
366 |
367 #define ceillog2(x) (luaO_log2((x)-1) + 1) |
367 #define ceillog2(x) (luaO_log2((x)-1) + 1) |
368 |
368 |
369 LUAI_FUNC int luaO_log2 (unsigned int x); |
369 LUAI_FUNC int luaO_log2 (unsigned int x); |
370 LUAI_FUNC int luaO_int2fb (unsigned int x); |
370 LUAI_FUNC int luaO_int2fb (unsigned int x); |
371 LUAI_FUNC int luaO_fb2int (int x); |
371 LUAI_FUNC int luaO_fb2int (int x); |
372 LUAI_FUNC int luaO_rawequalObj (const TValue *t1, const TValue *t2); |
372 LUAI_FUNC int luaO_rawequalObj (const TValue *t1, const TValue *t2); |