aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Pall <mike>2012-09-24 17:13:53 +0200
committerMike Pall <mike>2012-09-24 17:13:53 +0200
commit4c7c2c831992c836cbdfd0bbad1dcc26fbd007cc (patch)
tree32f43cafd7bd030689f7b84265fd068f94689d17
parentd9c5eba1bb0ad59a40f4d79fd331cdf1f9f4b81e (diff)
downloadluajit-4c7c2c831992c836cbdfd0bbad1dcc26fbd007cc.tar.gz
luajit-4c7c2c831992c836cbdfd0bbad1dcc26fbd007cc.tar.bz2
luajit-4c7c2c831992c836cbdfd0bbad1dcc26fbd007cc.zip
Rearrange library functions to get a fixed FF_next.
-rw-r--r--src/lib_base.c100
-rw-r--r--src/lj_bc.h2
2 files changed, 51 insertions, 51 deletions
diff --git a/src/lib_base.c b/src/lib_base.c
index 1d736b24..d63c9803 100644
--- a/src/lib_base.c
+++ b/src/lib_base.c
@@ -68,6 +68,56 @@ LJLIB_PUSH("number")
68LJLIB_ASM_(type) LJLIB_REC(.) 68LJLIB_ASM_(type) LJLIB_REC(.)
69/* Recycle the lj_lib_checkany(L, 1) from assert. */ 69/* Recycle the lj_lib_checkany(L, 1) from assert. */
70 70
71/* -- Base library: iterators --------------------------------------------- */
72
73/* This solves a circular dependency problem -- change FF_next_N as needed. */
74LJ_STATIC_ASSERT((int)FF_next == FF_next_N);
75
76LJLIB_ASM(next)
77{
78 lj_lib_checktab(L, 1);
79 return FFH_UNREACHABLE;
80}
81
82#if LJ_52 || LJ_HASFFI
83static int ffh_pairs(lua_State *L, MMS mm)
84{
85 TValue *o = lj_lib_checkany(L, 1);
86 cTValue *mo = lj_meta_lookup(L, o, mm);
87 if ((LJ_52 || tviscdata(o)) && !tvisnil(mo)) {
88 L->top = o+1; /* Only keep one argument. */
89 copyTV(L, L->base-1, mo); /* Replace callable. */
90 return FFH_TAILCALL;
91 } else {
92 if (!tvistab(o)) lj_err_argt(L, 1, LUA_TTABLE);
93 setfuncV(L, o-1, funcV(lj_lib_upvalue(L, 1)));
94 if (mm == MM_pairs) setnilV(o+1); else setintV(o+1, 0);
95 return FFH_RES(3);
96 }
97}
98#else
99#define ffh_pairs(L, mm) (lj_lib_checktab(L, 1), FFH_UNREACHABLE)
100#endif
101
102LJLIB_PUSH(lastcl)
103LJLIB_ASM(pairs)
104{
105 return ffh_pairs(L, MM_pairs);
106}
107
108LJLIB_NOREGUV LJLIB_ASM(ipairs_aux) LJLIB_REC(.)
109{
110 lj_lib_checktab(L, 1);
111 lj_lib_checkint(L, 2);
112 return FFH_UNREACHABLE;
113}
114
115LJLIB_PUSH(lastcl)
116LJLIB_ASM(ipairs) LJLIB_REC(.)
117{
118 return ffh_pairs(L, MM_ipairs);
119}
120
71/* -- Base library: getters and setters ----------------------------------- */ 121/* -- Base library: getters and setters ----------------------------------- */
72 122
73LJLIB_ASM_(getmetatable) LJLIB_REC(.) 123LJLIB_ASM_(getmetatable) LJLIB_REC(.)
@@ -267,56 +317,6 @@ LJLIB_ASM(tostring) LJLIB_REC(.)
267 } 317 }
268} 318}
269 319
270/* -- Base library: iterators --------------------------------------------- */
271
272/* This solves a circular dependency problem -- change FF_next_N as needed. */
273LJ_STATIC_ASSERT((int)FF_next == FF_next_N);
274
275LJLIB_ASM(next)
276{
277 lj_lib_checktab(L, 1);
278 return FFH_UNREACHABLE;
279}
280
281#if LJ_52 || LJ_HASFFI
282static int ffh_pairs(lua_State *L, MMS mm)
283{
284 TValue *o = lj_lib_checkany(L, 1);
285 cTValue *mo = lj_meta_lookup(L, o, mm);
286 if ((LJ_52 || tviscdata(o)) && !tvisnil(mo)) {
287 L->top = o+1; /* Only keep one argument. */
288 copyTV(L, L->base-1, mo); /* Replace callable. */
289 return FFH_TAILCALL;
290 } else {
291 if (!tvistab(o)) lj_err_argt(L, 1, LUA_TTABLE);
292 setfuncV(L, o-1, funcV(lj_lib_upvalue(L, 1)));
293 if (mm == MM_pairs) setnilV(o+1); else setintV(o+1, 0);
294 return FFH_RES(3);
295 }
296}
297#else
298#define ffh_pairs(L, mm) (lj_lib_checktab(L, 1), FFH_UNREACHABLE)
299#endif
300
301LJLIB_PUSH(lastcl)
302LJLIB_ASM(pairs)
303{
304 return ffh_pairs(L, MM_pairs);
305}
306
307LJLIB_NOREGUV LJLIB_ASM(ipairs_aux) LJLIB_REC(.)
308{
309 lj_lib_checktab(L, 1);
310 lj_lib_checkint(L, 2);
311 return FFH_UNREACHABLE;
312}
313
314LJLIB_PUSH(lastcl)
315LJLIB_ASM(ipairs) LJLIB_REC(.)
316{
317 return ffh_pairs(L, MM_ipairs);
318}
319
320/* -- Base library: throw and catch errors -------------------------------- */ 320/* -- Base library: throw and catch errors -------------------------------- */
321 321
322LJLIB_CF(error) 322LJLIB_CF(error)
diff --git a/src/lj_bc.h b/src/lj_bc.h
index 0a82c9d4..5edff707 100644
--- a/src/lj_bc.h
+++ b/src/lj_bc.h
@@ -224,7 +224,7 @@ LJ_STATIC_ASSERT((int)BC_FUNCV + 1 == (int)BC_IFUNCV);
224LJ_STATIC_ASSERT((int)BC_FUNCV + 2 == (int)BC_JFUNCV); 224LJ_STATIC_ASSERT((int)BC_FUNCV + 2 == (int)BC_JFUNCV);
225 225
226/* This solves a circular dependency problem, change as needed. */ 226/* This solves a circular dependency problem, change as needed. */
227#define FF_next_N 15 227#define FF_next_N 4
228 228
229/* Stack slots used by FORI/FORL, relative to operand A. */ 229/* Stack slots used by FORI/FORL, relative to operand A. */
230enum { 230enum {