|
@@ -30,6 +30,10 @@
|
|
|
#include "ltm.h"
|
|
|
#include "lvm.h"
|
|
|
|
|
|
+/*
|
|
|
+** We use ifdefs to clearly mark the parts that we had to change
|
|
|
+*/
|
|
|
+#define LUAOT 1
|
|
|
|
|
|
/*
|
|
|
** By default, use jump tables in the main interpreter loop on gcc
|
|
@@ -100,6 +104,7 @@ static int l_strton (const TValue *obj, TValue *result) {
|
|
|
** Try to convert a value to a float. The float case is already handled
|
|
|
** by the macro 'tonumber'.
|
|
|
*/
|
|
|
+#ifndef LUAOT_IS_MODULE
|
|
|
int luaV_tonumber_ (const TValue *obj, lua_Number *n) {
|
|
|
TValue v;
|
|
|
if (ttisinteger(obj)) {
|
|
@@ -113,11 +118,13 @@ int luaV_tonumber_ (const TValue *obj, lua_Number *n) {
|
|
|
else
|
|
|
return 0; /* conversion failed */
|
|
|
}
|
|
|
+#endif
|
|
|
|
|
|
|
|
|
/*
|
|
|
** try to convert a float to an integer, rounding according to 'mode'.
|
|
|
*/
|
|
|
+#ifndef LUAOT_IS_MODULE
|
|
|
int luaV_flttointeger (lua_Number n, lua_Integer *p, F2Imod mode) {
|
|
|
lua_Number f = l_floor(n);
|
|
|
if (n != f) { /* not an integral value? */
|
|
@@ -127,6 +134,7 @@ int luaV_flttointeger (lua_Number n, lua_Integer *p, F2Imod mode) {
|
|
|
}
|
|
|
return lua_numbertointeger(f, p);
|
|
|
}
|
|
|
+#endif
|
|
|
|
|
|
|
|
|
/*
|
|
@@ -134,6 +142,7 @@ int luaV_flttointeger (lua_Number n, lua_Integer *p, F2Imod mode) {
|
|
|
** without string coercion.
|
|
|
** ("Fast track" handled by macro 'tointegerns'.)
|
|
|
*/
|
|
|
+#ifndef LUAOT_IS_MODULE
|
|
|
int luaV_tointegerns (const TValue *obj, lua_Integer *p, F2Imod mode) {
|
|
|
if (ttisfloat(obj))
|
|
|
return luaV_flttointeger(fltvalue(obj), p, mode);
|
|
@@ -144,17 +153,20 @@ int luaV_tointegerns (const TValue *obj, lua_Integer *p, F2Imod mode) {
|
|
|
else
|
|
|
return 0;
|
|
|
}
|
|
|
+#endif
|
|
|
|
|
|
|
|
|
/*
|
|
|
** try to convert a value to an integer.
|
|
|
*/
|
|
|
+#ifndef LUAOT_IS_MODULE
|
|
|
int luaV_tointeger (const TValue *obj, lua_Integer *p, F2Imod mode) {
|
|
|
TValue v;
|
|
|
if (l_strton(obj, &v)) /* does 'obj' point to a numerical string? */
|
|
|
obj = &v; /* change it to point to its corresponding number */
|
|
|
return luaV_tointegerns(obj, p, mode);
|
|
|
}
|
|
|
+#endif
|
|
|
|
|
|
|
|
|
/*
|
|
@@ -284,6 +296,7 @@ static int floatforloop (StkId ra) {
|
|
|
** if 'slot' is NULL, 't' is not a table; otherwise, 'slot' points to
|
|
|
** t[k] entry (which must be empty).
|
|
|
*/
|
|
|
+#ifndef LUAOT_IS_MODULE
|
|
|
void luaV_finishget (lua_State *L, const TValue *t, TValue *key, StkId val,
|
|
|
const TValue *slot) {
|
|
|
int loop; /* counter to avoid infinite loops */
|
|
@@ -318,6 +331,7 @@ void luaV_finishget (lua_State *L, const TValue *t, TValue *key, StkId val,
|
|
|
}
|
|
|
luaG_runerror(L, "'__index' chain too long; possible loop");
|
|
|
}
|
|
|
+#endif
|
|
|
|
|
|
|
|
|
/*
|
|
@@ -327,6 +341,7 @@ void luaV_finishget (lua_State *L, const TValue *t, TValue *key, StkId val,
|
|
|
** is no such entry. (The value at 'slot' must be empty, otherwise
|
|
|
** 'luaV_fastget' would have done the job.)
|
|
|
*/
|
|
|
+#ifndef LUAOT_IS_MODULE
|
|
|
void luaV_finishset (lua_State *L, const TValue *t, TValue *key,
|
|
|
TValue *val, const TValue *slot) {
|
|
|
int loop; /* counter to avoid infinite loops */
|
|
@@ -363,6 +378,7 @@ void luaV_finishset (lua_State *L, const TValue *t, TValue *key,
|
|
|
}
|
|
|
luaG_runerror(L, "'__newindex' chain too long; possible loop");
|
|
|
}
|
|
|
+#endif
|
|
|
|
|
|
|
|
|
/*
|
|
@@ -529,11 +545,13 @@ static int lessthanothers (lua_State *L, const TValue *l, const TValue *r) {
|
|
|
/*
|
|
|
** Main operation less than; return 'l < r'.
|
|
|
*/
|
|
|
+#ifndef LUAOT_IS_MODULE
|
|
|
int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r) {
|
|
|
if (ttisnumber(l) && ttisnumber(r)) /* both operands are numbers? */
|
|
|
return LTnum(l, r);
|
|
|
else return lessthanothers(L, l, r);
|
|
|
}
|
|
|
+#endif
|
|
|
|
|
|
|
|
|
/*
|
|
@@ -551,17 +569,20 @@ static int lessequalothers (lua_State *L, const TValue *l, const TValue *r) {
|
|
|
/*
|
|
|
** Main operation less than or equal to; return 'l <= r'.
|
|
|
*/
|
|
|
+#ifndef LUAOT_IS_MODULE
|
|
|
int luaV_lessequal (lua_State *L, const TValue *l, const TValue *r) {
|
|
|
if (ttisnumber(l) && ttisnumber(r)) /* both operands are numbers? */
|
|
|
return LEnum(l, r);
|
|
|
else return lessequalothers(L, l, r);
|
|
|
}
|
|
|
+#endif
|
|
|
|
|
|
|
|
|
/*
|
|
|
** Main operation for equality of Lua values; return 't1 == t2'.
|
|
|
** L == NULL means raw equality (no metamethods)
|
|
|
*/
|
|
|
+#ifndef LUAOT_IS_MODULE
|
|
|
int luaV_equalobj (lua_State *L, const TValue *t1, const TValue *t2) {
|
|
|
const TValue *tm;
|
|
|
if (ttypetag(t1) != ttypetag(t2)) { /* not the same variant? */
|
|
@@ -612,6 +633,7 @@ int luaV_equalobj (lua_State *L, const TValue *t1, const TValue *t2) {
|
|
|
return !l_isfalse(s2v(L->top.p));
|
|
|
}
|
|
|
}
|
|
|
+#endif
|
|
|
|
|
|
|
|
|
/* macro used by 'luaV_concat' to ensure that element at 'o' is a string */
|
|
@@ -635,6 +657,7 @@ static void copy2buff (StkId top, int n, char *buff) {
|
|
|
** Main operation for concatenation: concat 'total' values in the stack,
|
|
|
** from 'L->top.p - total' up to 'L->top.p - 1'.
|
|
|
*/
|
|
|
+#ifndef LUAOT_IS_MODULE
|
|
|
void luaV_concat (lua_State *L, int total) {
|
|
|
if (total == 1)
|
|
|
return; /* "all" values already concatenated */
|
|
@@ -677,11 +700,13 @@ void luaV_concat (lua_State *L, int total) {
|
|
|
L->top.p -= n - 1; /* popped 'n' strings and pushed one */
|
|
|
} while (total > 1); /* repeat until only 1 result left */
|
|
|
}
|
|
|
+#endif
|
|
|
|
|
|
|
|
|
/*
|
|
|
** Main operation 'ra = #rb'.
|
|
|
*/
|
|
|
+#ifndef LUAOT_IS_MODULE
|
|
|
void luaV_objlen (lua_State *L, StkId ra, const TValue *rb) {
|
|
|
const TValue *tm;
|
|
|
switch (ttypetag(rb)) {
|
|
@@ -709,6 +734,7 @@ void luaV_objlen (lua_State *L, StkId ra, const TValue *rb) {
|
|
|
}
|
|
|
luaT_callTMres(L, tm, rb, rb, ra);
|
|
|
}
|
|
|
+#endif
|
|
|
|
|
|
|
|
|
/*
|
|
@@ -717,6 +743,7 @@ void luaV_objlen (lua_State *L, StkId ra, const TValue *rb) {
|
|
|
** 'floor(q) == trunc(q)' when 'q >= 0' or when 'q' is integer,
|
|
|
** otherwise 'floor(q) == trunc(q) - 1'.
|
|
|
*/
|
|
|
+#ifndef LUAOT_IS_MODULE
|
|
|
lua_Integer luaV_idiv (lua_State *L, lua_Integer m, lua_Integer n) {
|
|
|
if (l_unlikely(l_castS2U(n) + 1u <= 1u)) { /* special cases: -1 or 0 */
|
|
|
if (n == 0)
|
|
@@ -730,6 +757,7 @@ lua_Integer luaV_idiv (lua_State *L, lua_Integer m, lua_Integer n) {
|
|
|
return q;
|
|
|
}
|
|
|
}
|
|
|
+#endif
|
|
|
|
|
|
|
|
|
/*
|
|
@@ -737,6 +765,7 @@ lua_Integer luaV_idiv (lua_State *L, lua_Integer m, lua_Integer n) {
|
|
|
** negative operands follows C99 behavior. See previous comment
|
|
|
** about luaV_idiv.)
|
|
|
*/
|
|
|
+#ifndef LUAOT_IS_MODULE
|
|
|
lua_Integer luaV_mod (lua_State *L, lua_Integer m, lua_Integer n) {
|
|
|
if (l_unlikely(l_castS2U(n) + 1u <= 1u)) { /* special cases: -1 or 0 */
|
|
|
if (n == 0)
|
|
@@ -750,16 +779,19 @@ lua_Integer luaV_mod (lua_State *L, lua_Integer m, lua_Integer n) {
|
|
|
return r;
|
|
|
}
|
|
|
}
|
|
|
+#endif
|
|
|
|
|
|
|
|
|
/*
|
|
|
** Float modulus
|
|
|
*/
|
|
|
+#ifndef LUAOT_IS_MODULE
|
|
|
lua_Number luaV_modf (lua_State *L, lua_Number m, lua_Number n) {
|
|
|
lua_Number r;
|
|
|
luai_nummod(L, m, n, r);
|
|
|
return r;
|
|
|
}
|
|
|
+#endif
|
|
|
|
|
|
|
|
|
/* number of bits in an integer */
|
|
@@ -769,6 +801,7 @@ lua_Number luaV_modf (lua_State *L, lua_Number m, lua_Number n) {
|
|
|
/*
|
|
|
** Shift left operation. (Shift right just negates 'y'.)
|
|
|
*/
|
|
|
+#ifndef LUAOT_IS_MODULE
|
|
|
lua_Integer luaV_shiftl (lua_Integer x, lua_Integer y) {
|
|
|
if (y < 0) { /* shift right? */
|
|
|
if (y <= -NBITS) return 0;
|
|
@@ -779,6 +812,7 @@ lua_Integer luaV_shiftl (lua_Integer x, lua_Integer y) {
|
|
|
else return intop(<<, x, y);
|
|
|
}
|
|
|
}
|
|
|
+#endif
|
|
|
|
|
|
|
|
|
/*
|
|
@@ -806,6 +840,7 @@ static void pushclosure (lua_State *L, Proto *p, UpVal **encup, StkId base,
|
|
|
/*
|
|
|
** finish execution of an opcode interrupted by a yield
|
|
|
*/
|
|
|
+#ifndef LUAOT_IS_MODULE
|
|
|
void luaV_finishOp (lua_State *L) {
|
|
|
CallInfo *ci = L->ci;
|
|
|
StkId base = ci->func.p + 1;
|
|
@@ -870,6 +905,7 @@ void luaV_finishOp (lua_State *L) {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+#endif
|
|
|
|
|
|
|
|
|
|
|
@@ -1143,7 +1179,7 @@ void luaV_finishOp (lua_State *L) {
|
|
|
#define vmbreak break
|
|
|
|
|
|
|
|
|
-void luaV_execute (lua_State *L, CallInfo *ci) {
|
|
|
+static CallInfo *luaV_execute_(lua_State *L, CallInfo *ci)
|
|
|
LClosure *cl;
|
|
|
TValue *k;
|
|
|
StkId base;
|
|
@@ -1156,6 +1192,11 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
|
|
|
trap = L->hookmask;
|
|
|
returning: /* trap already set */
|
|
|
cl = clLvalue(s2v(ci->func.p));
|
|
|
+#if LUAOT
|
|
|
+ if (cl->p->aot_implementation) {
|
|
|
+ return ci;
|
|
|
+ }
|
|
|
+#endif
|
|
|
k = cl->p->k;
|
|
|
pc = ci->u.l.savedpc;
|
|
|
if (l_unlikely(trap)) {
|
|
@@ -1777,7 +1818,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
|
|
|
}
|
|
|
ret: /* return from a Lua function */
|
|
|
if (ci->callstatus & CIST_FRESH)
|
|
|
- return; /* end this frame */
|
|
|
+ return NULL; /* end this frame */
|
|
|
else {
|
|
|
ci = ci->previous;
|
|
|
goto returning; /* continue running caller in this frame */
|
|
@@ -1898,4 +1939,17 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+#ifndef LUAOT_IS_MODULE
|
|
|
+void luaV_execute (lua_State *L, CallInfo *ci) {
|
|
|
+ do {
|
|
|
+ LClosure *cl = clLvalue(s2v(ci->func));
|
|
|
+ if (cl->p->aot_implementation) {
|
|
|
+ ci = cl->p->aot_implementation(L, ci);
|
|
|
+ } else {
|
|
|
+ ci = luaV_execute_(L, ci);
|
|
|
+ }
|
|
|
+ } while (ci);
|
|
|
+}
|
|
|
+#endif
|
|
|
+
|
|
|
/* }================================================================== */
|