From 03a38e363ec06e80db6a4b31c4d1d2028915dc1d Mon Sep 17 00:00:00 2001 From: Lourival Vieira Neto Date: Mon, 29 Dec 2025 00:32:41 +0000 Subject: [PATCH] update Lunatik patch to Lua v5.5.0 --- .gitignore | 3 ++ README.md | 7 ++-- lapi.c | 4 +++ lauxlib.c | 12 +++++++ lauxlib.h | 19 +++++++++++ lbaselib.c | 4 +++ lcode.c | 43 ++++++++++++++++++++++++ lcode.h | 4 +++ ldblib.c | 4 +++ ldump.c | 4 +++ linit.c | 4 +++ ljumptab.h | 6 ++++ llex.c | 15 +++++++++ llex.h | 4 +++ lmathlib.c | 28 ++++++++++++++++ loadlib.c | 17 ++++++++++ lobject.c | 30 +++++++++++++++++ lobject.h | 26 +++++++++++++++ lopcodes.c | 6 ++++ lopcodes.h | 6 ++++ lopnames.h | 6 ++++ lparser.c | 10 ++++++ lparser.h | 2 ++ lstring.c | 9 ++++++ lstrlib.c | 26 +++++++++++++++ ltable.c | 14 ++++++++ ltm.c | 7 ++++ ltm.h | 2 ++ lua.h | 27 ++++++++++++++++ luaconf.h | 5 +++ lualib.h | 4 +++ lundump.c | 4 +++ lvm.c | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ lvm.h | 9 ++++++ 34 files changed, 461 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index ae2899e088..d3e70e1654 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,6 @@ testes/libs/all temp lua + +#lunatik +*.o.cmd diff --git a/README.md b/README.md index 5bc0ee77c4..0b8f4fdcc1 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,4 @@ -# Lua +# Lua in Kernel -This is the repository of Lua development code, as seen by the Lua team. It contains the full history of all commits but is mirrored irregularly. For complete information about Lua, visit [Lua.org](https://www.lua.org/). +This is a fork of the Lua repository. For more information about Lua in Kernel, visit the [Lunatik repository](https://github.com/luainkernel/lunatik). -Please **do not** send pull requests. To report issues, post a message to the [Lua mailing list](https://www.lua.org/lua-l.html). - -Download official Lua releases from [Lua.org](https://www.lua.org/download.html). diff --git a/lapi.c b/lapi.c index 27fa524797..e7f4ec8be7 100644 --- a/lapi.c +++ b/lapi.c @@ -386,6 +386,7 @@ LUA_API size_t lua_stringtonumber (lua_State *L, const char *s) { } +#ifndef _KERNEL LUA_API lua_Number lua_tonumberx (lua_State *L, int idx, int *pisnum) { lua_Number n = 0; const TValue *o = index2value(L, idx); @@ -394,6 +395,7 @@ LUA_API lua_Number lua_tonumberx (lua_State *L, int idx, int *pisnum) { *pisnum = isnum; return n; } +#endif /* _KERNEL */ LUA_API lua_Integer lua_tointegerx (lua_State *L, int idx, int *pisnum) { @@ -519,12 +521,14 @@ LUA_API void lua_pushnil (lua_State *L) { } +#ifndef _KERNEL LUA_API void lua_pushnumber (lua_State *L, lua_Number n) { lua_lock(L); setfltvalue(s2v(L->top.p), n); api_incr_top(L); lua_unlock(L); } +#endif /* _KERNEL */ LUA_API void lua_pushinteger (lua_State *L, lua_Integer n) { diff --git a/lauxlib.c b/lauxlib.c index 7cf90cb78a..fdb1b75572 100644 --- a/lauxlib.c +++ b/lauxlib.c @@ -246,6 +246,7 @@ LUALIB_API int luaL_error (lua_State *L, const char *fmt, ...) { } +#ifndef _KERNEL LUALIB_API int luaL_fileresult (lua_State *L, int stat, const char *fname) { int en = errno; /* calls to Lua API may change this value */ if (stat) { @@ -264,6 +265,7 @@ LUALIB_API int luaL_fileresult (lua_State *L, int stat, const char *fname) { return 3; } } +#endif /* _KERNEL */ #if !defined(l_inspectstat) /* { */ @@ -288,6 +290,7 @@ LUALIB_API int luaL_fileresult (lua_State *L, int stat, const char *fname) { #endif /* } */ +#ifndef _KERNEL LUALIB_API int luaL_execresult (lua_State *L, int stat) { if (stat != 0 && errno != 0) /* error with an 'errno'? */ return luaL_fileresult(L, 0, NULL); @@ -303,6 +306,7 @@ LUALIB_API int luaL_execresult (lua_State *L, int stat) { return 3; /* return true/fail,what,code */ } } +#endif /* _KERNEL */ /* }====================================================== */ @@ -437,6 +441,7 @@ LUALIB_API lua_Number luaL_optnumber (lua_State *L, int arg, lua_Number def) { } +#ifndef _KERNEL static void interror (lua_State *L, int arg) { if (lua_isnumber(L, arg)) luaL_argerror(L, arg, "number has no integer representation"); @@ -459,6 +464,7 @@ LUALIB_API lua_Integer luaL_optinteger (lua_State *L, int arg, lua_Integer def) { return luaL_opt(L, luaL_checkinteger, arg, def); } +#endif /* _KERNEL */ /* }====================================================== */ @@ -733,6 +739,7 @@ LUALIB_API void luaL_unref (lua_State *L, int t, int ref) { ** ======================================================= */ +#ifndef _KERNEL typedef struct LoadF { unsigned n; /* number of pre-read characters */ FILE *f; /* file being read */ @@ -846,6 +853,7 @@ LUALIB_API int luaL_loadfilex (lua_State *L, const char *filename, lua_remove(L, fnameindex); return status; } +#endif /* _KERNEL */ typedef struct LoadS { @@ -1196,7 +1204,11 @@ LUALIB_API void luaL_checkversion_ (lua_State *L, lua_Number ver, size_t sz) { if (sz != LUAL_NUMSIZES) /* check numeric types */ luaL_error(L, "core and library have incompatible numeric types"); else if (v != ver) +#ifndef _KERNEL luaL_error(L, "version mismatch: app. needs %f, Lua core provides %f", +#else + luaL_error(L, "version mismatch: app. needs %d, Lua core provides %d", +#endif /* _KERNEL */ (LUAI_UACNUMBER)ver, (LUAI_UACNUMBER)v); } diff --git a/lauxlib.h b/lauxlib.h index 7f1d3ca195..713e00e0ae 100644 --- a/lauxlib.h +++ b/lauxlib.h @@ -59,9 +59,14 @@ LUALIB_API const char *(luaL_optlstring) (lua_State *L, int arg, LUALIB_API lua_Number (luaL_checknumber) (lua_State *L, int arg); LUALIB_API lua_Number (luaL_optnumber) (lua_State *L, int arg, lua_Number def); +#ifndef _KERNEL LUALIB_API lua_Integer (luaL_checkinteger) (lua_State *L, int arg); LUALIB_API lua_Integer (luaL_optinteger) (lua_State *L, int arg, lua_Integer def); +#else /* _KERNEL */ +#define luaL_checkinteger luaL_checknumber +#define luaL_optinteger(L,a,d) luaL_optnumber(L, (a), (lua_Number)(d)) +#endif /* _KERNEL */ LUALIB_API void (luaL_checkstack) (lua_State *L, int sz, const char *msg); LUALIB_API void (luaL_checktype) (lua_State *L, int arg, int t); @@ -78,10 +83,16 @@ LUALIB_API int (luaL_error) (lua_State *L, const char *fmt, ...); LUALIB_API int (luaL_checkoption) (lua_State *L, int arg, const char *def, const char *const lst[]); +#ifndef _KERNEL LUALIB_API int (luaL_fileresult) (lua_State *L, int stat, const char *fname); LUALIB_API int (luaL_execresult) (lua_State *L, int stat); +#endif /* _KERNEL */ +#if !(defined(_KERNEL) && defined(LUNATIK_GENSYMBOLS)) LUALIB_API void *luaL_alloc (void *ud, void *ptr, size_t osize, +#else /* _KERNEL && LUNATIK_GENSYMBOLS */ +LUALIB_API void *(luaL_alloc) (void *ud, void *ptr, size_t osize, +#endif /* _KERNEL && LUNATIK_GENSYMBOLS */ size_t nsize); @@ -92,8 +103,10 @@ LUALIB_API void *luaL_alloc (void *ud, void *ptr, size_t osize, LUALIB_API int (luaL_ref) (lua_State *L, int t); LUALIB_API void (luaL_unref) (lua_State *L, int t, int ref); +#ifndef _KERNEL LUALIB_API int (luaL_loadfilex) (lua_State *L, const char *filename, const char *mode); +#endif /* _KERNEL */ #define luaL_loadfile(L,f) luaL_loadfilex(L,f,NULL) @@ -103,7 +116,11 @@ LUALIB_API int (luaL_loadstring) (lua_State *L, const char *s); LUALIB_API lua_State *(luaL_newstate) (void); +#if !(defined(_KERNEL) && defined(LUNATIK_GENSYMBOLS)) LUALIB_API unsigned luaL_makeseed (lua_State *L); +#else /* _KERNEL && LUNATIK_GENSYMBOLS */ +LUALIB_API unsigned (luaL_makeseed) (lua_State *L); +#endif /* _KERNEL && LUNATIK_GENSYMBOLS */ LUALIB_API lua_Integer (luaL_len) (lua_State *L, int idx); @@ -221,6 +238,7 @@ LUALIB_API char *(luaL_buffinitsize) (lua_State *L, luaL_Buffer *B, size_t sz); +#ifndef _KERNEL /* ** {====================================================== ** File handles for IO library @@ -242,6 +260,7 @@ typedef struct luaL_Stream { } luaL_Stream; /* }====================================================== */ +#endif /* _KERNEL */ /* diff --git a/lbaselib.c b/lbaselib.c index 891bb90f48..3cfe42f05b 100644 --- a/lbaselib.c +++ b/lbaselib.c @@ -211,7 +211,11 @@ static int luaB_collectgarbage (lua_State *L) { int k = lua_gc(L, o); int b = lua_gc(L, LUA_GCCOUNTB); checkvalres(k); +#if !(defined(_KERNEL) && defined(LUNATIK_GCCOUNT)) lua_pushnumber(L, (lua_Number)k + ((lua_Number)b/1024)); +#else /* _KERNEL && LUNATIK_GCCOUNT */ + lua_pushinteger(L, ((lua_Integer)k << 10) + b); +#endif /* _KERNEL && LUNATIK_GCCOUNT */ return 1; } case LUA_GCSTEP: { diff --git a/lcode.c b/lcode.c index 4caa8046f6..1eb398be27 100644 --- a/lcode.c +++ b/lcode.c @@ -61,9 +61,11 @@ static int tonumeral (const expdesc *e, TValue *v) { case VKINT: if (v) setivalue(v, e->u.ival); return 1; +#ifndef _KERNEL case VKFLT: if (v) setfltvalue(v, e->u.nval); return 1; +#endif /* _KERNEL */ default: return 0; } } @@ -602,6 +604,7 @@ static int luaK_intK (FuncState *fs, lua_Integer n) { return k2proto(fs, &o, &o); /* use integer itself as key */ } +#ifndef _KERNEL /* ** Add a float to list of constants and return its index. Floats ** with integral values need a different key, to avoid collision @@ -637,6 +640,7 @@ static int luaK_numberK (FuncState *fs, lua_Number r) { return addk(fs, fs->f, &o); } } +#endif /* _KERNEL */ /* @@ -697,6 +701,7 @@ void luaK_int (FuncState *fs, int reg, lua_Integer i) { } +#ifndef _KERNEL static void luaK_float (FuncState *fs, int reg, lua_Number f) { lua_Integer fi; if (luaV_flttointeger(f, &fi, F2Ieq) && fitsBx(fi)) @@ -704,6 +709,7 @@ static void luaK_float (FuncState *fs, int reg, lua_Number f) { else luaK_codek(fs, reg, luaK_numberK(fs, f)); } +#endif /* _KERNEL */ /* @@ -730,8 +736,10 @@ static void const2exp (TValue *v, expdesc *e) { case LUA_VNUMINT: e->k = VKINT; e->u.ival = ivalue(v); break; +#ifndef _KERNEL case LUA_VNUMFLT: e->k = VKFLT; e->u.nval = fltvalue(v); +#endif /* _KERNEL */ break; case LUA_VFALSE: e->k = VFALSE; @@ -901,10 +909,12 @@ static void discharge2reg (FuncState *fs, expdesc *e, int reg) { luaK_codek(fs, reg, e->u.info); break; } +#ifndef _KERNEL case VKFLT: { luaK_float(fs, reg, e->u.nval); break; } +#endif /* _KERNEL */ case VKINT: { luaK_int(fs, reg, e->u.ival); break; @@ -1060,7 +1070,9 @@ static int luaK_exp2K (FuncState *fs, expdesc *e) { case VFALSE: info = boolF(fs); break; case VNIL: info = nilK(fs); break; case VKINT: info = luaK_intK(fs, e->u.ival); break; +#ifndef _KERNEL case VKFLT: info = luaK_numberK(fs, e->u.nval); break; +#endif /* _KERNEL */ case VKSTR: info = stringK(fs, e->u.strval); break; case VK: info = e->u.info; break; default: return 0; /* not a constant */ @@ -1184,7 +1196,11 @@ void luaK_goiftrue (FuncState *fs, expdesc *e) { pc = e->u.info; /* save jump position */ break; } +#ifndef _KERNEL case VK: case VKFLT: case VKINT: case VKSTR: case VTRUE: { +#else /* _KERNEL */ + case VK: case VKINT: case VKSTR: case VTRUE: { +#endif /* _KERNEL */ pc = NO_JUMP; /* always true; do nothing */ break; } @@ -1234,7 +1250,11 @@ static void codenot (FuncState *fs, expdesc *e) { e->k = VTRUE; /* true == not nil == not false */ break; } +#ifndef _KERNEL case VK: case VKFLT: case VKINT: case VKSTR: case VTRUE: { +#else /* _KERNEL */ + case VK: case VKINT: case VKSTR: case VTRUE: { +#endif /* _KERNEL */ e->k = VFALSE; /* false == not "x" == not 0.5 == not 1 == not true */ break; } @@ -1301,8 +1321,10 @@ static int isSCnumber (expdesc *e, int *pi, int *isfloat) { lua_Integer i; if (e->k == VKINT) i = e->u.ival; +#ifndef _KERNEL else if (e->k == VKFLT && luaV_flttointeger(e->u.nval, &i, F2Ieq)) *isfloat = 1; +#endif /* _KERNEL */ else return 0; /* not a number */ if (!hasjumps(e) && fitsC(i)) { @@ -1404,7 +1426,11 @@ static int validop (int op, TValue *v1, TValue *v2) { return (luaV_tointegerns(v1, &i, LUA_FLOORN2I) && luaV_tointegerns(v2, &i, LUA_FLOORN2I)); } +#ifndef _KERNEL case LUA_OPDIV: case LUA_OPIDIV: case LUA_OPMOD: /* division by 0 */ +#else /* _KERNEL */ + case LUA_OPIDIV: case LUA_OPMOD: /* division by 0 */ +#endif /* _KERNEL */ return (nvalue(v2) != 0); default: return 1; /* everything else is valid */ } @@ -1426,11 +1452,15 @@ static int constfolding (FuncState *fs, int op, expdesc *e1, e1->u.ival = ivalue(&res); } else { /* folds neither NaN nor 0.0 (to avoid problems with -0.0) */ +#ifndef _KERNEL lua_Number n = fltvalue(&res); if (luai_numisnan(n) || n == 0) return 0; e1->k = VKFLT; e1->u.nval = n; +#else /* _KERNEL */ + return 0; /* if it is not integer, we must fail */ +#endif /* _KERNEL */ } return 1; } @@ -1669,7 +1699,11 @@ static void codeeq (FuncState *fs, BinOpr opr, expdesc *e1, expdesc *e2) { int isfloat = 0; /* not needed here, but kept for symmetry */ OpCode op; if (e1->k != VNONRELOC) { +#ifndef _KERNEL lua_assert(e1->k == VK || e1->k == VKINT || e1->k == VKFLT); +#else /* _KERNEL */ + lua_assert(e1->k == VK || e1->k == VKINT); +#endif /* _KERNEL */ swapexps(e1, e2); } r1 = luaK_exp2anyreg(fs, e1); /* 1st expression must be in register */ @@ -1731,8 +1765,13 @@ void luaK_infix (FuncState *fs, BinOpr op, expdesc *v) { break; } case OPR_ADD: case OPR_SUB: +#ifndef _KERNEL case OPR_MUL: case OPR_DIV: case OPR_IDIV: case OPR_MOD: case OPR_POW: +#else /* _KERNEL */ + case OPR_MUL: case OPR_IDIV: + case OPR_MOD: +#endif /* _KERNEL */ case OPR_BAND: case OPR_BOR: case OPR_BXOR: case OPR_SHL: case OPR_SHR: { if (!tonumeral(v, NULL)) @@ -1816,7 +1855,11 @@ void luaK_posfix (FuncState *fs, BinOpr opr, break; /* coded as (r1 + -I) */ /* ELSE */ } /* FALLTHROUGH */ +#ifndef _KERNEL case OPR_DIV: case OPR_IDIV: case OPR_MOD: case OPR_POW: { +#else /* _KERNEL */ + case OPR_IDIV: case OPR_MOD: { +#endif /* _KERNEL */ codearith(fs, opr, e1, e2, 0, line); break; } diff --git a/lcode.h b/lcode.h index 09e5c802b0..f8dcaffa0e 100644 --- a/lcode.h +++ b/lcode.h @@ -25,8 +25,12 @@ */ typedef enum BinOpr { /* arithmetic operators */ +#ifndef _KERNEL OPR_ADD, OPR_SUB, OPR_MUL, OPR_MOD, OPR_POW, OPR_DIV, OPR_IDIV, +#else /* _KERNEL */ + OPR_ADD, OPR_SUB, OPR_MUL, OPR_MOD, OPR_IDIV, +#endif /* _KERNEL */ /* bitwise operators */ OPR_BAND, OPR_BOR, OPR_BXOR, OPR_SHL, OPR_SHR, diff --git a/ldblib.c b/ldblib.c index c7b74812e8..837298f1ed 100644 --- a/ldblib.c +++ b/ldblib.c @@ -420,6 +420,7 @@ static int db_gethook (lua_State *L) { } +#ifndef _KERNEL static int db_debug (lua_State *L) { for (;;) { char buffer[250]; @@ -433,6 +434,7 @@ static int db_debug (lua_State *L) { lua_settop(L, 0); /* remove eventual returns */ } } +#endif /* _KERNEL */ static int db_traceback (lua_State *L) { @@ -450,7 +452,9 @@ static int db_traceback (lua_State *L) { static const luaL_Reg dblib[] = { +#ifndef _KERNEL {"debug", db_debug}, +#endif /* _KERNEL */ {"getuservalue", db_getuservalue}, {"gethook", db_gethook}, {"getinfo", db_getinfo}, diff --git a/ldump.c b/ldump.c index 5795788922..215335537e 100644 --- a/ldump.c +++ b/ldump.c @@ -113,9 +113,11 @@ static void dumpInt (DumpState *D, int x) { } +#ifndef _KERNEL static void dumpNumber (DumpState *D, lua_Number x) { dumpVar(D, x); } +#endif /* _KERNEL */ /* @@ -187,9 +189,11 @@ static void dumpConstants (DumpState *D, const Proto *f) { int tt = ttypetag(o); dumpByte(D, tt); switch (tt) { +#ifndef _KERNEL case LUA_VNUMFLT: dumpNumber(D, fltvalue(o)); break; +#endif /* _KERNEL */ case LUA_VNUMINT: dumpInteger(D, ivalue(o)); break; diff --git a/linit.c b/linit.c index 00d06f7ecb..379c4ae69f 100644 --- a/linit.c +++ b/linit.c @@ -30,9 +30,13 @@ static const luaL_Reg stdlibs[] = { {LUA_LOADLIBNAME, luaopen_package}, {LUA_COLIBNAME, luaopen_coroutine}, {LUA_DBLIBNAME, luaopen_debug}, +#ifndef _KERNEL {LUA_IOLIBNAME, luaopen_io}, +#endif /* _KERNEL */ {LUA_MATHLIBNAME, luaopen_math}, +#ifndef _KERNEL {LUA_OSLIBNAME, luaopen_os}, +#endif /* _KERNEL */ {LUA_STRLIBNAME, luaopen_string}, {LUA_TABLIBNAME, luaopen_table}, {LUA_UTF8LIBNAME, luaopen_utf8}, diff --git a/ljumptab.h b/ljumptab.h index 52fa6d746e..4cba975511 100644 --- a/ljumptab.h +++ b/ljumptab.h @@ -27,7 +27,9 @@ static const void *const disptab[NUM_OPCODES] = { &&L_OP_MOVE, &&L_OP_LOADI, +#ifndef _KERNEL &&L_OP_LOADF, +#endif /* _KERNEL */ &&L_OP_LOADK, &&L_OP_LOADKX, &&L_OP_LOADFALSE, @@ -51,8 +53,10 @@ static const void *const disptab[NUM_OPCODES] = { &&L_OP_SUBK, &&L_OP_MULK, &&L_OP_MODK, +#ifndef _KERNEL &&L_OP_POWK, &&L_OP_DIVK, +#endif /* _KERNEL */ &&L_OP_IDIVK, &&L_OP_BANDK, &&L_OP_BORK, @@ -63,8 +67,10 @@ static const void *const disptab[NUM_OPCODES] = { &&L_OP_SUB, &&L_OP_MUL, &&L_OP_MOD, +#ifndef _KERNEL &&L_OP_POW, &&L_OP_DIV, +#endif /* _KERNEL */ &&L_OP_IDIV, &&L_OP_BAND, &&L_OP_BOR, diff --git a/llex.c b/llex.c index f8bb3ea4b4..bb7fe070fe 100644 --- a/llex.c +++ b/llex.c @@ -104,7 +104,11 @@ const char *luaX_token2str (LexState *ls, int token) { static const char *txtToken (LexState *ls, int token) { switch (token) { case TK_NAME: case TK_STRING: +#ifndef _KERNEL case TK_FLT: case TK_INT: +#else /* _KERNEL */ + case TK_INT: +#endif /* _KERNEL */ save(ls, '\0'); return luaO_pushfstring(ls->L, "'%s'", luaZ_buffer(ls->buff)); default: @@ -250,9 +254,13 @@ static int read_numeral (LexState *ls, SemInfo *seminfo) { if (first == '0' && check_next2(ls, "xX")) /* hexadecimal? */ expo = "Pp"; for (;;) { +#ifndef _KERNEL if (check_next2(ls, expo)) /* exponent mark? */ check_next2(ls, "-+"); /* optional exponent sign */ else if (lisxdigit(ls->current) || ls->current == '.') /* '%x|%.' */ +#else /* _KERNEL */ + if (lisxdigit(ls->current)) /* '%x' */ +#endif /* _KERNEL */ save_and_next(ls); else break; } @@ -260,16 +268,23 @@ static int read_numeral (LexState *ls, SemInfo *seminfo) { save_and_next(ls); /* force an error */ save(ls, '\0'); if (luaO_str2num(luaZ_buffer(ls->buff), &obj) == 0) /* format error? */ +#ifndef _KERNEL lexerror(ls, "malformed number", TK_FLT); if (ttisinteger(&obj)) { +#else /* _KERNEL */ + lexerror(ls, "malformed number", TK_INT); + lua_assert(ttisinteger(&obj)); +#endif /* _KERNEL */ seminfo->i = ivalue(&obj); return TK_INT; +#ifndef _KERNEL } else { lua_assert(ttisfloat(&obj)); seminfo->r = fltvalue(&obj); return TK_FLT; } +#endif /* _KERNEL */ } diff --git a/llex.h b/llex.h index 37016e8a3f..85e2fe57f0 100644 --- a/llex.h +++ b/llex.h @@ -39,7 +39,11 @@ enum RESERVED { TK_IDIV, TK_CONCAT, TK_DOTS, TK_EQ, TK_GE, TK_LE, TK_NE, TK_SHL, TK_SHR, TK_DBCOLON, TK_EOS, +#ifndef _KERNEL TK_FLT, TK_INT, TK_NAME, TK_STRING +#else /* _KERNEL */ + TK_INT, TK_NAME, TK_STRING +#endif /* _KERNEL */ }; /* number of reserved words */ diff --git a/lmathlib.c b/lmathlib.c index a6b13f969c..a723db96d3 100644 --- a/lmathlib.c +++ b/lmathlib.c @@ -23,22 +23,31 @@ #include "llimits.h" +#ifndef _KERNEL #undef PI #define PI (l_mathop(3.141592653589793238462643383279502884)) +#endif /* _KERNEL */ static int math_abs (lua_State *L) { +#ifndef _KERNEL if (lua_isinteger(L, 1)) { lua_Integer n = lua_tointeger(L, 1); +#else /* _KERNEL */ + lua_Integer n = luaL_checkinteger(L, 1); +#endif /* _KERNEL */ if (n < 0) n = (lua_Integer)(0u - (lua_Unsigned)n); lua_pushinteger(L, n); +#ifndef _KERNEL } else lua_pushnumber(L, l_mathop(fabs)(luaL_checknumber(L, 1))); +#endif /* _KERNEL */ return 1; } +#ifndef _KERNEL static int math_sin (lua_State *L) { lua_pushnumber(L, l_mathop(sin)(luaL_checknumber(L, 1))); return 1; @@ -75,6 +84,7 @@ static int math_atan (lua_State *L) { lua_pushnumber(L, l_mathop(atan2)(y, x)); return 1; } +#endif /* _KERNEL */ static int math_toint (lua_State *L) { @@ -90,6 +100,7 @@ static int math_toint (lua_State *L) { } +#ifndef _KERNEL static void pushnumint (lua_State *L, lua_Number d) { lua_Integer n; if (lua_numbertointeger(d, &n)) /* does 'd' fit in an integer? */ @@ -164,6 +175,7 @@ static int math_sqrt (lua_State *L) { lua_pushnumber(L, l_mathop(sqrt)(luaL_checknumber(L, 1))); return 1; } +#endif /* _KERNEL */ static int math_ult (lua_State *L) { @@ -174,6 +186,7 @@ static int math_ult (lua_State *L) { } +#ifndef _KERNEL static int math_log (lua_State *L) { lua_Number x = luaL_checknumber(L, 1); lua_Number res; @@ -229,6 +242,7 @@ static int math_ldexp (lua_State *L) { lua_pushnumber(L, l_mathop(ldexp)(x, ep)); return 1; } +#endif /* _KERNEL */ static int math_min (lua_State *L) { @@ -259,6 +273,7 @@ static int math_max (lua_State *L) { } +#ifndef _KERNEL static int math_type (lua_State *L) { if (lua_type(L, 1) == LUA_TNUMBER) lua_pushstring(L, (lua_isinteger(L, 1)) ? "integer" : "float"); @@ -700,11 +715,13 @@ static int math_log10 (lua_State *L) { #endif /* }================================================================== */ +#endif /* _KERNEL */ static const luaL_Reg mathlib[] = { {"abs", math_abs}, +#ifndef _KERNEL {"acos", math_acos}, {"asin", math_asin}, {"atan", math_atan}, @@ -712,15 +729,21 @@ static const luaL_Reg mathlib[] = { {"cos", math_cos}, {"deg", math_deg}, {"exp", math_exp}, +#endif /* _KERNEL */ {"tointeger", math_toint}, +#ifndef _KERNEL {"floor", math_floor}, {"fmod", math_fmod}, {"frexp", math_frexp}, +#endif /* _KERNEL */ {"ult", math_ult}, +#ifndef _KERNEL {"ldexp", math_ldexp}, {"log", math_log}, +#endif /* _KERNEL */ {"max", math_max}, {"min", math_min}, +#ifndef _KERNEL {"modf", math_modf}, {"rad", math_rad}, {"sin", math_sin}, @@ -740,6 +763,7 @@ static const luaL_Reg mathlib[] = { {"randomseed", NULL}, {"pi", NULL}, {"huge", NULL}, +#endif /* _KERNEL */ {"maxinteger", NULL}, {"mininteger", NULL}, {NULL, NULL} @@ -751,15 +775,19 @@ static const luaL_Reg mathlib[] = { */ LUAMOD_API int luaopen_math (lua_State *L) { luaL_newlib(L, mathlib); +#ifndef _KERNEL lua_pushnumber(L, PI); lua_setfield(L, -2, "pi"); lua_pushnumber(L, (lua_Number)HUGE_VAL); lua_setfield(L, -2, "huge"); +#endif /* _KERNEL */ lua_pushinteger(L, LUA_MAXINTEGER); lua_setfield(L, -2, "maxinteger"); lua_pushinteger(L, LUA_MININTEGER); lua_setfield(L, -2, "mininteger"); +#ifndef _KERNEL setrandfunc(L); +#endif /* _KERNEL */ return 1; } diff --git a/loadlib.c b/loadlib.c index 8d2e68e261..988b23c498 100644 --- a/loadlib.c +++ b/loadlib.c @@ -63,6 +63,7 @@ static const char *const CLIBS = "_CLIBS"; #define cast_Lfunc(p) cast(lua_CFunction, cast_func(p)) +#ifndef _KERNEL /* ** system-dependent functions */ @@ -233,6 +234,7 @@ static lua_CFunction lsys_sym (lua_State *L, void *lib, const char *sym) { /* }====================================================== */ #endif /* } */ +#endif /* _KERNEL */ /* @@ -382,6 +384,9 @@ static void addtoclib (lua_State *L, const char *path, void *plib) { ** errors, return an error code with an error message in the stack. */ static int lookforfunc (lua_State *L, const char *path, const char *sym) { +#ifdef _KERNEL + path = sym; /* loading only already linked kernel modules */ +#endif /* _KERNEL */ void *reg = checkclib(L, path); /* check loaded C libraries */ if (reg == NULL) { /* must load library? */ reg = lsys_load(L, path, *sym == '*'); /* global symbols if 'sym'=='*' */ @@ -573,12 +578,17 @@ static int loadfunc (lua_State *L, const char *filename, const char *modname) { static int searcher_C (lua_State *L) { const char *name = luaL_checkstring(L, 1); +#ifndef _KERNEL const char *filename = findfile(L, name, "cpath", LUA_CSUBSEP); if (filename == NULL) return 1; /* module not found in this path */ +#else + const char *filename = name; +#endif /* _KERNEL */ return checkload(L, (loadfunc(L, filename, name) == 0), filename); } +#ifndef _KERNEL static int searcher_Croot (lua_State *L) { const char *filename; const char *name = luaL_checkstring(L, 1); @@ -599,6 +609,7 @@ static int searcher_Croot (lua_State *L) { lua_pushstring(L, filename); /* will be 2nd argument to module */ return 2; } +#endif /* _KERNEL */ static int searcher_preload (lua_State *L) { @@ -686,7 +697,9 @@ static const luaL_Reg pk_funcs[] = { {"searchpath", ll_searchpath}, /* placeholders */ {"preload", NULL}, +#ifndef _KERNEL {"cpath", NULL}, +#endif /* _KERNEL */ {"path", NULL}, {"searchers", NULL}, {"loaded", NULL}, @@ -705,7 +718,9 @@ static void createsearcherstable (lua_State *L) { searcher_preload, searcher_Lua, searcher_C, +#ifndef _KERNEL searcher_Croot, +#endif /* _KERNEL */ NULL }; int i; @@ -728,7 +743,9 @@ LUAMOD_API int luaopen_package (lua_State *L) { createsearcherstable(L); /* set paths */ setpath(L, "path", LUA_PATH_VAR, LUA_PATH_DEFAULT); +#ifndef _KERNEL setpath(L, "cpath", LUA_CPATH_VAR, LUA_CPATH_DEFAULT); +#endif /* _KERNEL */ /* store config information */ lua_pushliteral(L, LUA_DIRSEP "\n" LUA_PATH_SEP "\n" LUA_PATH_MARK "\n" LUA_EXEC_DIR "\n" LUA_IGMARK "\n"); diff --git a/lobject.c b/lobject.c index 763b484609..0a6e2e0ec6 100644 --- a/lobject.c +++ b/lobject.c @@ -132,6 +132,7 @@ static lua_Integer intarith (lua_State *L, int op, lua_Integer v1, } +#ifndef _KERNEL static lua_Number numarith (lua_State *L, int op, lua_Number v1, lua_Number v2) { switch (op) { @@ -146,6 +147,7 @@ static lua_Number numarith (lua_State *L, int op, lua_Number v1, default: lua_assert(0); return 0; } } +#endif /* _KERNEL */ int luaO_rawarith (lua_State *L, int op, const TValue *p1, const TValue *p2, @@ -161,6 +163,7 @@ int luaO_rawarith (lua_State *L, int op, const TValue *p1, const TValue *p2, } else return 0; /* fail */ } +#ifndef _KERNEL case LUA_OPDIV: case LUA_OPPOW: { /* operate only on floats */ lua_Number n1; lua_Number n2; if (tonumberns(p1, n1) && tonumberns(p2, n2)) { @@ -169,7 +172,9 @@ int luaO_rawarith (lua_State *L, int op, const TValue *p1, const TValue *p2, } else return 0; /* fail */ } +#endif /* _KERNEL */ default: { /* other operations */ +#ifndef _KERNEL lua_Number n1; lua_Number n2; if (ttisinteger(p1) && ttisinteger(p2)) { setivalue(res, intarith(L, op, ivalue(p1), ivalue(p2))); @@ -179,6 +184,13 @@ int luaO_rawarith (lua_State *L, int op, const TValue *p1, const TValue *p2, setfltvalue(res, numarith(L, op, n1, n2)); return 1; } +#else /* _KERNEL */ + lua_Integer i1; lua_Integer i2; + if (tointeger(p1, &i1) && tointeger(p2, &i2)) { + setivalue(res, intarith(L, op, i1, i2)); + return 1; + } +#endif /* _KERNEL */ else return 0; /* fail */ } } @@ -209,6 +221,7 @@ static int isneg (const char **s) { +#ifndef _KERNEL /* ** {================================================================== ** Lua's implementation for 'lua_strx2number' @@ -331,6 +344,7 @@ static const char *l_str2d (const char *s, lua_Number *result) { } return endptr; } +#endif /* _KERNEL */ #define MAXBY10 cast(lua_Unsigned, LUA_MAXINTEGER / 10) @@ -369,14 +383,20 @@ static const char *l_str2int (const char *s, lua_Integer *result) { size_t luaO_str2num (const char *s, TValue *o) { +#ifndef _KERNEL lua_Integer i; lua_Number n; +#else /* _KERNEL */ + lua_Integer i; +#endif /* _KERNEL */ const char *e; if ((e = l_str2int(s, &i)) != NULL) { /* try as an integer */ setivalue(o, i); } +#ifndef _KERNEL else if ((e = l_str2d(s, &n)) != NULL) { /* else try as a float */ setfltvalue(o, n); } +#endif /* _KERNEL */ else return 0; /* conversion failed */ return ct_diff2sz(e - s) + 1; /* success; return string size */ @@ -401,6 +421,7 @@ int luaO_utf8esc (char *buff, l_uint32 x) { } +#ifndef _KERNEL /* ** The size of the buffer for the conversion of a number to a string ** 'LUA_N2SBUFFSZ' must be enough to accommodate both LUA_INTEGER_FMT @@ -441,6 +462,7 @@ static int tostringbuffFloat (lua_Number n, char *buff) { } return len; } +#endif /* _KERNEL */ /* @@ -448,11 +470,17 @@ static int tostringbuffFloat (lua_Number n, char *buff) { */ unsigned luaO_tostringbuff (const TValue *obj, char *buff) { int len; +#ifndef _KERNEL lua_assert(ttisnumber(obj)); if (ttisinteger(obj)) +#else /* _KERNEL */ + lua_assert(ttisinteger(obj)); +#endif /* _KERNEL */ len = lua_integer2str(buff, LUA_N2SBUFFSZ, ivalue(obj)); +#ifndef _KERNEL else len = tostringbuffFloat(fltvalue(obj), buff); +#endif /* _KERNEL */ lua_assert(len < LUA_N2SBUFFSZ); return cast_uint(len); } @@ -623,12 +651,14 @@ const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) { addnum2buff(&buff, &num); break; } +#ifndef _KERNEL case 'f': { /* a 'lua_Number' */ TValue num; setfltvalue(&num, cast_num(va_arg(argp, l_uacNumber))); addnum2buff(&buff, &num); break; } +#endif /* _KERNEL */ case 'p': { /* a pointer */ char bf[LUA_N2SBUFFSZ]; /* enough space for '%p' */ void *p = va_arg(argp, void *); diff --git a/lobject.h b/lobject.h index 156c942f01..76c13d9829 100644 --- a/lobject.h +++ b/lobject.h @@ -51,7 +51,9 @@ typedef union Value { void *p; /* light userdata */ lua_CFunction f; /* light C functions */ lua_Integer i; /* integer numbers */ +#ifndef _KERNEL lua_Number n; /* float numbers */ +#endif /* _KERNEL */ /* not used, but may avoid warnings for uninitialized value */ lu_byte ub; } Value; @@ -334,25 +336,37 @@ typedef struct GCObject { /* Variant tags for numbers */ #define LUA_VNUMINT makevariant(LUA_TNUMBER, 0) /* integer numbers */ +#ifndef _KERNEL #define LUA_VNUMFLT makevariant(LUA_TNUMBER, 1) /* float numbers */ +#endif /* _KERNEL */ #define ttisnumber(o) checktype((o), LUA_TNUMBER) +#ifndef _KERNEL #define ttisfloat(o) checktag((o), LUA_VNUMFLT) +#endif /* _KERNEL */ #define ttisinteger(o) checktag((o), LUA_VNUMINT) +#ifndef _KERNEL #define nvalue(o) check_exp(ttisnumber(o), \ (ttisinteger(o) ? cast_num(ivalue(o)) : fltvalue(o))) #define fltvalue(o) check_exp(ttisfloat(o), val_(o).n) +#else /* _KERNEL */ +#define nvalue(o) check_exp(ttisnumber(o), cast_num(ivalue(o))) +#endif /* _KERNEL */ #define ivalue(o) check_exp(ttisinteger(o), val_(o).i) +#ifndef _KERNEL #define fltvalueraw(v) ((v).n) +#endif /* _KERNEL */ #define ivalueraw(v) ((v).i) +#ifndef _KERNEL #define setfltvalue(obj,x) \ { TValue *io=(obj); val_(io).n=(x); settt_(io, LUA_VNUMFLT); } #define chgfltvalue(obj,x) \ { TValue *io=(obj); lua_assert(ttisfloat(io)); val_(io).n=(x); } +#endif /* _KERNEL */ #define setivalue(obj,x) \ { TValue *io=(obj); val_(io).i=(x); settt_(io, LUA_VNUMINT); } @@ -494,7 +508,11 @@ typedef struct Udata { size_t len; /* number of bytes */ struct Table *metatable; GCObject *gclist; +#if !(defined(_KERNEL) && defined(CONFIG_UBSAN_BOUNDS)) UValue uv[1]; /* user values */ +#else /* _KERNEL && CONFIG_UBSAN_BOUNDS */ + UValue uv[]; /* user values */ +#endif /* _KERNEL && CONFIG_UBSAN_BOUNDS */ } Udata; @@ -699,14 +717,22 @@ typedef struct UpVal { typedef struct CClosure { ClosureHeader; lua_CFunction f; +#if !(defined(_KERNEL) && defined(CONFIG_UBSAN_BOUNDS)) TValue upvalue[1]; /* list of upvalues */ +#else /* _KERNEL && CONFIG_UBSAN_BOUNDS */ + TValue upvalue[]; /* list of upvalues */ +#endif /* _KERNEL && CONFIG_UBSAN_BOUNDS */ } CClosure; typedef struct LClosure { ClosureHeader; struct Proto *p; +#if !(defined(_KERNEL) && defined(CONFIG_UBSAN_BOUNDS)) UpVal *upvals[1]; /* list of upvalues */ +#else /* _KERNEL && CONFIG_UBSAN_BOUNDS */ + UpVal *upvals[]; /* list of upvalues */ +#endif /* _KERNEL && CONFIG_UBSAN_BOUNDS */ } LClosure; diff --git a/lopcodes.c b/lopcodes.c index 7e182315bc..5449e3910b 100644 --- a/lopcodes.c +++ b/lopcodes.c @@ -23,7 +23,9 @@ LUAI_DDEF const lu_byte luaP_opmodes[NUM_OPCODES] = { /* MM OT IT T A mode opcode */ opmode(0, 0, 0, 0, 1, iABC) /* OP_MOVE */ ,opmode(0, 0, 0, 0, 1, iAsBx) /* OP_LOADI */ +#ifndef _KERNEL ,opmode(0, 0, 0, 0, 1, iAsBx) /* OP_LOADF */ +#endif /* _KERNEL */ ,opmode(0, 0, 0, 0, 1, iABx) /* OP_LOADK */ ,opmode(0, 0, 0, 0, 1, iABx) /* OP_LOADKX */ ,opmode(0, 0, 0, 0, 1, iABC) /* OP_LOADFALSE */ @@ -47,8 +49,10 @@ LUAI_DDEF const lu_byte luaP_opmodes[NUM_OPCODES] = { ,opmode(0, 0, 0, 0, 1, iABC) /* OP_SUBK */ ,opmode(0, 0, 0, 0, 1, iABC) /* OP_MULK */ ,opmode(0, 0, 0, 0, 1, iABC) /* OP_MODK */ +#ifndef _KERNEL ,opmode(0, 0, 0, 0, 1, iABC) /* OP_POWK */ ,opmode(0, 0, 0, 0, 1, iABC) /* OP_DIVK */ +#endif /* _KERNEL */ ,opmode(0, 0, 0, 0, 1, iABC) /* OP_IDIVK */ ,opmode(0, 0, 0, 0, 1, iABC) /* OP_BANDK */ ,opmode(0, 0, 0, 0, 1, iABC) /* OP_BORK */ @@ -59,8 +63,10 @@ LUAI_DDEF const lu_byte luaP_opmodes[NUM_OPCODES] = { ,opmode(0, 0, 0, 0, 1, iABC) /* OP_SUB */ ,opmode(0, 0, 0, 0, 1, iABC) /* OP_MUL */ ,opmode(0, 0, 0, 0, 1, iABC) /* OP_MOD */ +#ifndef _KERNEL ,opmode(0, 0, 0, 0, 1, iABC) /* OP_POW */ ,opmode(0, 0, 0, 0, 1, iABC) /* OP_DIV */ +#endif /* _KERNEL */ ,opmode(0, 0, 0, 0, 1, iABC) /* OP_IDIV */ ,opmode(0, 0, 0, 0, 1, iABC) /* OP_BAND */ ,opmode(0, 0, 0, 0, 1, iABC) /* OP_BOR */ diff --git a/lopcodes.h b/lopcodes.h index b6bd182ea2..4c9ac77c18 100644 --- a/lopcodes.h +++ b/lopcodes.h @@ -234,7 +234,9 @@ typedef enum { ------------------------------------------------------------------------*/ OP_MOVE,/* A B R[A] := R[B] */ OP_LOADI,/* A sBx R[A] := sBx */ +#ifndef _KERNEL OP_LOADF,/* A sBx R[A] := (lua_Number)sBx */ +#endif /* _KERNEL */ OP_LOADK,/* A Bx R[A] := K[Bx] */ OP_LOADKX,/* A R[A] := K[extra arg] */ OP_LOADFALSE,/* A R[A] := false */ @@ -264,8 +266,10 @@ OP_ADDK,/* A B C R[A] := R[B] + K[C]:number */ OP_SUBK,/* A B C R[A] := R[B] - K[C]:number */ OP_MULK,/* A B C R[A] := R[B] * K[C]:number */ OP_MODK,/* A B C R[A] := R[B] % K[C]:number */ +#ifndef _KERNEL OP_POWK,/* A B C R[A] := R[B] ^ K[C]:number */ OP_DIVK,/* A B C R[A] := R[B] / K[C]:number */ +#endif /* _KERNEL */ OP_IDIVK,/* A B C R[A] := R[B] // K[C]:number */ OP_BANDK,/* A B C R[A] := R[B] & K[C]:integer */ @@ -279,8 +283,10 @@ OP_ADD,/* A B C R[A] := R[B] + R[C] */ OP_SUB,/* A B C R[A] := R[B] - R[C] */ OP_MUL,/* A B C R[A] := R[B] * R[C] */ OP_MOD,/* A B C R[A] := R[B] % R[C] */ +#ifndef _KERNEL OP_POW,/* A B C R[A] := R[B] ^ R[C] */ OP_DIV,/* A B C R[A] := R[B] / R[C] */ +#endif /* _KERNEL */ OP_IDIV,/* A B C R[A] := R[B] // R[C] */ OP_BAND,/* A B C R[A] := R[B] & R[C] */ diff --git a/lopnames.h b/lopnames.h index 0554a2e9a1..11f660331a 100644 --- a/lopnames.h +++ b/lopnames.h @@ -15,7 +15,9 @@ static const char *const opnames[] = { "MOVE", "LOADI", +#ifndef _KERNEL "LOADF", +#endif /* _KERNEL */ "LOADK", "LOADKX", "LOADFALSE", @@ -39,8 +41,10 @@ static const char *const opnames[] = { "SUBK", "MULK", "MODK", +#ifndef _KERNEL "POWK", "DIVK", +#endif /* _KERNEL */ "IDIVK", "BANDK", "BORK", @@ -51,8 +55,10 @@ static const char *const opnames[] = { "SUB", "MUL", "MOD", +#ifndef _KERNEL "POW", "DIV", +#endif /* _KERNEL */ "IDIV", "BAND", "BOR", diff --git a/lparser.c b/lparser.c index b3855d4cb6..90d3ca4da7 100644 --- a/lparser.c +++ b/lparser.c @@ -1255,11 +1255,13 @@ static void simpleexp (LexState *ls, expdesc *v) { /* simpleexp -> FLT | INT | STRING | NIL | TRUE | FALSE | ... | constructor | FUNCTION body | suffixedexp */ switch (ls->t.token) { +#ifndef _KERNEL case TK_FLT: { init_exp(v, VKFLT, 0); v->u.nval = ls->t.seminfo.r; break; } +#endif /* _KERNEL */ case TK_INT: { init_exp(v, VKINT, 0); v->u.ival = ls->t.seminfo.i; @@ -1323,8 +1325,12 @@ static BinOpr getbinopr (int op) { case '-': return OPR_SUB; case '*': return OPR_MUL; case '%': return OPR_MOD; +#ifndef _KERNEL case '^': return OPR_POW; case '/': return OPR_DIV; +#else /* _KERNEL */ + case '/': return OPR_IDIV; +#endif /* _KERNEL */ case TK_IDIV: return OPR_IDIV; case '&': return OPR_BAND; case '|': return OPR_BOR; @@ -1354,8 +1360,12 @@ static const struct { } priority[] = { /* ORDER OPR */ {10, 10}, {10, 10}, /* '+' '-' */ {11, 11}, {11, 11}, /* '*' '%' */ +#ifndef _KERNEL {14, 13}, /* '^' (right associative) */ {11, 11}, {11, 11}, /* '/' '//' */ +#else /* _KERNEL */ + {11, 11}, /* '//' */ +#endif /* _KERNEL */ {6, 6}, {4, 4}, {5, 5}, /* '&' '|' '~' */ {7, 7}, {7, 7}, /* '<<' '>>' */ {9, 8}, /* '..' (right associative) */ diff --git a/lparser.h b/lparser.h index a30df04f77..53f847c6cd 100644 --- a/lparser.h +++ b/lparser.h @@ -29,7 +29,9 @@ typedef enum { VTRUE, /* constant true */ VFALSE, /* constant false */ VK, /* constant in 'k'; info = index of constant in 'k' */ +#ifndef _KERNEL VKFLT, /* floating constant; nval = numerical float value */ +#endif VKINT, /* integer constant; ival = numerical integer value */ VKSTR, /* string constant; strval = TString address; (string is fixed by the scanner) */ diff --git a/lstring.c b/lstring.c index 75635142e9..098d87a983 100644 --- a/lstring.c +++ b/lstring.c @@ -50,7 +50,11 @@ int luaS_eqstr (TString *a, TString *b) { } +#if !(defined(_KERNEL) && defined(LUNATIK_RUNTIME)) static unsigned luaS_hash (const char *str, size_t l, unsigned seed) { +#else /* _KERNEL && LUNATIK_RUNTIME */ +unsigned luaS_hash (const char *str, size_t l, unsigned seed) { +#endif /* _KERNEL && LUNATIK_RUNTIME */ unsigned int h = seed ^ cast_uint(l); for (; l > 0; l--) h ^= ((h<<5) + (h>>2) + cast_byte(str[l - 1])); @@ -235,7 +239,12 @@ static TString *internshrstr (lua_State *L, const char *str, size_t l) { ts = createstrobj(L, sizestrshr(l), LUA_VSHRSTR, h); ts->shrlen = cast(ls_byte, l); getshrstr(ts)[l] = '\0'; /* ending 0 */ +#if !(defined(_KERNEL) && defined(CONFIG_FORTIFY_SOURCE)) memcpy(getshrstr(ts), str, l * sizeof(char)); +#else /* _KERNEL && CONFIG_FORTIFY_SOURCE */ + unsafe_memcpy(getshrstr(ts), str, l * sizeof(char), + "bounds checked by luaS_newlstr and luaS_normstr"); +#endif /* _KERNEL && CONFIG_FORTIFY_SOURCE */ ts->u.hnext = *list; *list = ts; tb->nuse++; diff --git a/lstrlib.c b/lstrlib.c index 23df839ea0..c698d50a52 100644 --- a/lstrlib.c +++ b/lstrlib.c @@ -312,6 +312,7 @@ static int arith_mod (lua_State *L) { return arith(L, LUA_OPMOD, "__mod"); } +#ifndef _KERNEL static int arith_pow (lua_State *L) { return arith(L, LUA_OPPOW, "__pow"); } @@ -319,6 +320,7 @@ static int arith_pow (lua_State *L) { static int arith_div (lua_State *L) { return arith(L, LUA_OPDIV, "__div"); } +#endif /* _KERNEL */ static int arith_idiv (lua_State *L) { return arith(L, LUA_OPIDIV, "__idiv"); @@ -334,8 +336,10 @@ static const luaL_Reg stringmetamethods[] = { {"__sub", arith_sub}, {"__mul", arith_mul}, {"__mod", arith_mod}, +#ifndef _KERNEL {"__pow", arith_pow}, {"__div", arith_div}, +#endif /* _KERNEL */ {"__idiv", arith_idiv}, {"__unm", arith_unm}, {"__index", NULL}, /* placeholder */ @@ -990,6 +994,7 @@ static int str_gsub (lua_State *L) { +#ifndef _KERNEL /* ** {====================================================== ** STRING FORMAT @@ -1080,6 +1085,7 @@ static int lua_number2strx (lua_State *L, char *buff, unsigned sz, ** is maximum exponent + 1). (99+3+1, adding some extra, 110) */ #define MAX_ITEMF (110 + l_floatatt(MAX_10_EXP)) +#endif /* _KERNEL */ /* @@ -1146,6 +1152,7 @@ static void addquoted (luaL_Buffer *b, const char *s, size_t len) { } +#ifndef _KERNEL /* ** Serialize a floating-point number in such a way that it can be ** scanned back by Lua. Use hexadecimal format for "common" numbers @@ -1174,6 +1181,7 @@ static int quotefloat (lua_State *L, char *buff, lua_Number n) { /* for the fixed representations */ return l_sprintf(buff, MAX_ITEM, "%s", s); } +#endif /* _KERNEL */ static void addliteral (lua_State *L, luaL_Buffer *b, int arg) { @@ -1187,15 +1195,19 @@ static void addliteral (lua_State *L, luaL_Buffer *b, int arg) { case LUA_TNUMBER: { char *buff = luaL_prepbuffsize(b, MAX_ITEM); int nb; +#ifndef _KERNEL if (!lua_isinteger(L, arg)) /* float? */ nb = quotefloat(L, buff, lua_tonumber(L, arg)); else { /* integers */ +#endif /* _KERNEL */ lua_Integer n = lua_tointeger(L, arg); const char *format = (n == LUA_MININTEGER) /* corner case? */ ? "0x%" LUA_INTEGER_FRMLEN "x" /* use hex */ : LUA_INTEGER_FMT; /* else use default format */ nb = l_sprintf(buff, MAX_ITEM, format, (LUAI_UACINT)n); +#ifndef _KERNEL } +#endif /* _KERNEL */ luaL_addsize(b, cast_uint(nb)); break; } @@ -1317,6 +1329,7 @@ static int str_format (lua_State *L) { nb = l_sprintf(buff, maxitem, form, (LUAI_UACINT)n); break; } +#ifndef _KERNEL case 'a': case 'A': checkformat(L, form, L_FMTFLAGSF, 1); addlenmod(form, LUA_NUMBER_FRMLEN); @@ -1344,6 +1357,7 @@ static int str_format (lua_State *L) { nb = l_sprintf(buff, maxitem, form, p); break; } +#endif /* _KERNEL */ case 'q': { if (form[2] != '\0') /* modifiers? */ return luaL_error(L, "specifier '%%q' cannot have modifiers"); @@ -1432,9 +1446,11 @@ typedef struct Header { typedef enum KOption { Kint, /* signed integers */ Kuint, /* unsigned integers */ +#ifndef _KERNEL Kfloat, /* single-precision floating-point numbers */ Knumber, /* Lua "native" floating-point numbers */ Kdouble, /* double-precision floating-point numbers */ +#endif /* _KERNEL */ Kchar, /* fixed-length strings */ Kstring, /* strings with prefixed length */ Kzstr, /* zero-terminated strings */ @@ -1504,9 +1520,13 @@ static KOption getoption (Header *h, const char **fmt, size_t *size) { case 'j': *size = sizeof(lua_Integer); return Kint; case 'J': *size = sizeof(lua_Integer); return Kuint; case 'T': *size = sizeof(size_t); return Kuint; +#ifndef _KERNEL case 'f': *size = sizeof(float); return Kfloat; case 'n': *size = sizeof(lua_Number); return Knumber; case 'd': *size = sizeof(double); return Kdouble; +#else /* _KERNEL */ + case 'n': *size = sizeof(lua_Number); return Kint; +#endif /* _KERNEL */ case 'i': *size = getnumlimit(h, fmt, sizeof(int)); return Kint; case 'I': *size = getnumlimit(h, fmt, sizeof(int)); return Kuint; case 's': *size = getnumlimit(h, fmt, sizeof(size_t)); return Kstring; @@ -1592,6 +1612,7 @@ static void packint (luaL_Buffer *b, lua_Unsigned n, } +#ifndef _KERNEL /* ** Copy 'size' bytes from 'src' to 'dest', correcting endianness if ** given 'islittle' is different from native endianness. @@ -1606,6 +1627,7 @@ static void copywithendian (char *dest, const char *src, *(dest--) = *(src++); } } +#endif /* _KERNEL */ static int str_pack (lua_State *L) { @@ -1645,6 +1667,7 @@ static int str_pack (lua_State *L) { packint(&b, (lua_Unsigned)n, h.islittle, cast_uint(size), 0); break; } +#ifndef _KERNEL case Kfloat: { /* C float */ float f = (float)luaL_checknumber(L, arg); /* get argument */ char *buff = luaL_prepbuffsize(&b, sizeof(f)); @@ -1669,6 +1692,7 @@ static int str_pack (lua_State *L) { luaL_addsize(&b, size); break; } +#endif /* _KERNEL */ case Kchar: { /* fixed-size string */ size_t len; const char *s = luaL_checklstring(L, arg, &len); @@ -1796,6 +1820,7 @@ static int str_unpack (lua_State *L) { lua_pushinteger(L, res); break; } +#ifndef _KERNEL case Kfloat: { float f; copywithendian((char *)&f, data + pos, sizeof(f), h.islittle); @@ -1814,6 +1839,7 @@ static int str_unpack (lua_State *L) { lua_pushnumber(L, (lua_Number)f); break; } +#endif /* _KERNEL */ case Kchar: { lua_pushlstring(L, data + pos, size); break; diff --git a/ltable.c b/ltable.c index b7f88f6ffe..43244d2d00 100644 --- a/ltable.c +++ b/ltable.c @@ -151,6 +151,7 @@ static Node *hashint (const Table *t, lua_Integer i) { } +#ifndef _KERNEL /* ** Hash for floating-point numbers. ** The main computation should be just @@ -179,6 +180,7 @@ static unsigned l_hashfloat (lua_Number n) { } } #endif +#endif /* _KERNEL */ /* @@ -191,10 +193,12 @@ static Node *mainpositionTV (const Table *t, const TValue *key) { lua_Integer i = ivalue(key); return hashint(t, i); } +#ifndef _KERNEL case LUA_VNUMFLT: { lua_Number n = fltvalue(key); return hashmod(t, l_hashfloat(n)); } +#endif /* _KERNEL */ case LUA_VSHRSTR: { TString *ts = tsvalue(key); return hashstr(t, ts); @@ -268,8 +272,10 @@ static int equalkey (const TValue *k1, const Node *n2, int deadok) { return 1; case LUA_VNUMINT: return (ivalue(k1) == keyival(n2)); +#ifndef _KERNEL case LUA_VNUMFLT: return luai_numeq(fltvalue(k1), fltvalueraw(keyval(n2))); +#endif /* _KERNEL */ case LUA_VLIGHTUSERDATA: return pvalue(k1) == pvalueraw(keyval(n2)); case LUA_VLCF: @@ -1028,12 +1034,14 @@ lu_byte luaH_get (Table *t, const TValue *key, TValue *res) { case LUA_VNIL: slot = &absentkey; break; +#ifndef _KERNEL case LUA_VNUMFLT: { lua_Integer k; if (luaV_flttointeger(fltvalue(key), &k, F2Ieq)) /* integral index? */ return luaH_getint(t, k, res); /* use specialized version */ /* else... */ } /* FALLTHROUGH */ +#endif /* _KERNEL */ default: slot = getgeneric(t, key, 0); break; @@ -1134,12 +1142,14 @@ int luaH_pset (Table *t, const TValue *key, TValue *val) { case LUA_VSHRSTR: return luaH_psetshortstr(t, tsvalue(key), val); case LUA_VNUMINT: return psetint(t, ivalue(key), val); case LUA_VNIL: return HNOTFOUND; +#ifndef _KERNEL case LUA_VNUMFLT: { lua_Integer k; if (luaV_flttointeger(fltvalue(key), &k, F2Ieq)) /* integral index? */ return psetint(t, k, val); /* use specialized version */ /* else... */ } /* FALLTHROUGH */ +#endif /* _KERNEL */ default: return finishnodeset(t, getgeneric(t, key, 0), val); } @@ -1155,9 +1165,12 @@ void luaH_finishset (lua_State *L, Table *t, const TValue *key, TValue *value, int hres) { lua_assert(hres != HOK); if (hres == HNOTFOUND) { +#ifndef _KERNEL TValue aux; +#endif /* _KERNEL */ if (l_unlikely(ttisnil(key))) luaG_runerror(L, "table index is nil"); +#ifndef _KERNEL else if (ttisfloat(key)) { lua_Number f = fltvalue(key); lua_Integer k; @@ -1168,6 +1181,7 @@ void luaH_finishset (lua_State *L, Table *t, const TValue *key, else if (l_unlikely(luai_numisnan(f))) luaG_runerror(L, "table index is NaN"); } +#endif /* _KERNEL */ else if (isextstr(key)) { /* external string? */ /* If string is short, must internalize it to be used as table key */ TString *ts = luaS_normstr(L, tsvalue(key)); diff --git a/ltm.c b/ltm.c index f2a373f86c..45984449f0 100644 --- a/ltm.c +++ b/ltm.c @@ -39,8 +39,13 @@ void luaT_init (lua_State *L) { static const char *const luaT_eventname[] = { /* ORDER TM */ "__index", "__newindex", "__gc", "__mode", "__len", "__eq", +#ifndef _KERNEL "__add", "__sub", "__mul", "__mod", "__pow", "__div", "__idiv", +#else /* _KERNEL */ + "__add", "__sub", "__mul", "__mod", + "__idiv", +#endif /* _KERNEL */ "__band", "__bor", "__bxor", "__shl", "__shr", "__unm", "__bnot", "__lt", "__le", "__concat", "__call", "__close" @@ -210,10 +215,12 @@ int luaT_callorderTM (lua_State *L, const TValue *p1, const TValue *p2, int luaT_callorderiTM (lua_State *L, const TValue *p1, int v2, int flip, int isfloat, TMS event) { TValue aux; const TValue *p2; +#ifndef _KERNEL if (isfloat) { setfltvalue(&aux, cast_num(v2)); } else +#endif /* _KERNEL */ setivalue(&aux, v2); if (flip) { /* arguments were exchanged? */ p2 = p1; p1 = &aux; /* correct them */ diff --git a/ltm.h b/ltm.h index 07fc8c1c98..55674e93f8 100644 --- a/ltm.h +++ b/ltm.h @@ -26,8 +26,10 @@ typedef enum { TM_SUB, TM_MUL, TM_MOD, +#ifndef _KERNEL TM_POW, TM_DIV, +#endif /* _KERNEL */ TM_IDIV, TM_BAND, TM_BOR, diff --git a/lua.h b/lua.h index ab473dc3e4..c1ea369eb3 100644 --- a/lua.h +++ b/lua.h @@ -197,7 +197,11 @@ LUA_API int (lua_isuserdata) (lua_State *L, int idx); LUA_API int (lua_type) (lua_State *L, int idx); LUA_API const char *(lua_typename) (lua_State *L, int tp); +#ifndef _KERNEL LUA_API lua_Number (lua_tonumberx) (lua_State *L, int idx, int *isnum); +#else /* _KERNEL */ +#define lua_tonumberx lua_tointegerx +#endif /* _KERNEL */ LUA_API lua_Integer (lua_tointegerx) (lua_State *L, int idx, int *isnum); LUA_API int (lua_toboolean) (lua_State *L, int idx); LUA_API const char *(lua_tolstring) (lua_State *L, int idx, size_t *len); @@ -216,6 +220,7 @@ LUA_API const void *(lua_topointer) (lua_State *L, int idx); #define LUA_OPSUB 1 #define LUA_OPMUL 2 #define LUA_OPMOD 3 +#ifndef _KERNEL #define LUA_OPPOW 4 #define LUA_OPDIV 5 #define LUA_OPIDIV 6 @@ -226,6 +231,16 @@ LUA_API const void *(lua_topointer) (lua_State *L, int idx); #define LUA_OPSHR 11 #define LUA_OPUNM 12 #define LUA_OPBNOT 13 +#else /* _KERNEL */ +#define LUA_OPIDIV 4 +#define LUA_OPBAND 5 +#define LUA_OPBOR 6 +#define LUA_OPBXOR 7 +#define LUA_OPSHL 8 +#define LUA_OPSHR 9 +#define LUA_OPUNM 10 +#define LUA_OPBNOT 11 +#endif /* _KERNEL */ LUA_API void (lua_arith) (lua_State *L, int op); @@ -241,7 +256,11 @@ LUA_API int (lua_compare) (lua_State *L, int idx1, int idx2, int op); ** push functions (C -> stack) */ LUA_API void (lua_pushnil) (lua_State *L); +#ifndef _KERNEL LUA_API void (lua_pushnumber) (lua_State *L, lua_Number n); +#else /* _KERNEL */ +#define lua_pushnumber(L, n) lua_pushinteger(L, (lua_Integer)(n)) +#endif /* _KERNEL */ LUA_API void (lua_pushinteger) (lua_State *L, lua_Integer n); LUA_API const char *(lua_pushlstring) (lua_State *L, const char *s, size_t len); LUA_API const char *(lua_pushexternalstring) (lua_State *L, @@ -516,11 +535,19 @@ struct lua_Debug { #define LUA_VERSION_MINOR LUAI_TOSTR(LUA_VERSION_MINOR_N) #define LUA_VERSION_RELEASE LUAI_TOSTR(LUA_VERSION_RELEASE_N) +#ifndef _KERNEL #define LUA_VERSION "Lua " LUA_VERSION_MAJOR "." LUA_VERSION_MINOR +#else /* _KERNEL */ +#define LUA_VERSION "Lua " LUA_VERSION_MAJOR "." LUA_VERSION_MINOR "-kernel" +#endif /* _KERNEL */ #define LUA_RELEASE LUA_VERSION "." LUA_VERSION_RELEASE /****************************************************************************** +#ifdef _KERNEL +* Copyright (C) 2020-2026 Ring Zero Desenvolvimento de Software LTDA. +* Copyright (C) 2016-2016 Lourival Vieira Neto . +#endif * Copyright (C) 1994-2025 Lua.org, PUC-Rio. * * Permission is hereby granted, free of charge, to any person obtaining diff --git a/luaconf.h b/luaconf.h index 96a77802b9..939369e554 100644 --- a/luaconf.h +++ b/luaconf.h @@ -377,6 +377,7 @@ ** =================================================================== */ +#ifndef _KERNEL /* @@ LUAI_UACNUMBER is the result of a 'default argument promotion' @@ over a floating number. @@ -457,6 +458,7 @@ #error "numeric float type not defined" #endif /* } */ +#endif /*_KERNEL */ @@ -739,6 +741,9 @@ ** without modifying the main part of the file. */ +#ifdef _KERNEL +#include +#endif /* _KERNEL */ #endif diff --git a/lualib.h b/lualib.h index 068f60ab3b..84dcdafbda 100644 --- a/lualib.h +++ b/lualib.h @@ -30,17 +30,21 @@ LUAMOD_API int (luaopen_coroutine) (lua_State *L); #define LUA_DBLIBK (LUA_COLIBK << 1) LUAMOD_API int (luaopen_debug) (lua_State *L); +#ifndef _KERNEL #define LUA_IOLIBNAME "io" #define LUA_IOLIBK (LUA_DBLIBK << 1) LUAMOD_API int (luaopen_io) (lua_State *L); +#endif /* _KERNEL */ #define LUA_MATHLIBNAME "math" #define LUA_MATHLIBK (LUA_IOLIBK << 1) LUAMOD_API int (luaopen_math) (lua_State *L); +#ifndef _KERNEL #define LUA_OSLIBNAME "os" #define LUA_OSLIBK (LUA_MATHLIBK << 1) LUAMOD_API int (luaopen_os) (lua_State *L); +#endif /* _KERNEL */ #define LUA_STRLIBNAME "string" #define LUA_STRLIBK (LUA_OSLIBK << 1) diff --git a/lundump.c b/lundump.c index 3b61cc8cbb..f4e01a7300 100644 --- a/lundump.c +++ b/lundump.c @@ -119,11 +119,13 @@ static int loadInt (LoadState *S) { +#ifndef _KERNEL static lua_Number loadNumber (LoadState *S) { lua_Number x; loadVar(S, x); return x; } +#endif /* _KERNEL */ static lua_Integer loadInteger (LoadState *S) { @@ -222,9 +224,11 @@ static void loadConstants (LoadState *S, Proto *f) { case LUA_VTRUE: setbtvalue(o); break; +#ifndef _KERNEL case LUA_VNUMFLT: setfltvalue(o, loadNumber(S)); break; +#endif /* _KERNEL */ case LUA_VNUMINT: setivalue(o, loadInteger(S)); break; diff --git a/lvm.c b/lvm.c index c70e2b8a8a..f60fe31b3e 100644 --- a/lvm.c +++ b/lvm.c @@ -50,6 +50,7 @@ #define MAXTAGLOOP 2000 +#ifndef _KERNEL /* ** 'l_intfitsf' checks whether a given integer is in the range that ** can be converted to a float without rounding. Used in comparisons. @@ -79,6 +80,7 @@ #define l_intfitsf(i) 1 #endif +#endif /* _KERNEL */ /* @@ -120,6 +122,7 @@ int luaV_tonumber_ (const TValue *obj, lua_Number *n) { } +#ifndef _KERNEL /* ** try to convert a float to an integer, rounding according to 'mode'. */ @@ -132,6 +135,7 @@ int luaV_flttointeger (lua_Number n, lua_Integer *p, F2Imod mode) { } return lua_numbertointeger(f, p); } +#endif /* _KERNEL */ /* @@ -140,9 +144,14 @@ int luaV_flttointeger (lua_Number n, lua_Integer *p, F2Imod mode) { ** ("Fast track" handled by macro 'tointegerns'.) */ int luaV_tointegerns (const TValue *obj, lua_Integer *p, F2Imod mode) { +#ifndef _KERNEL if (ttisfloat(obj)) return luaV_flttointeger(fltvalue(obj), p, mode); else if (ttisinteger(obj)) { +#else + if (ttisinteger(obj)) { + UNUSED(mode); +#endif /* _KERNEL */ *p = ivalue(obj); return 1; } @@ -215,10 +224,21 @@ static int forprep (lua_State *L, StkId ra) { TValue *pinit = s2v(ra); TValue *plimit = s2v(ra + 1); TValue *pstep = s2v(ra + 2); +#ifndef _KERNEL if (ttisinteger(pinit) && ttisinteger(pstep)) { /* integer loop? */ lua_Integer init = ivalue(pinit); lua_Integer step = ivalue(pstep); lua_Integer limit; +#else /* _KERNEL */ + /* try making all values integers */ + lua_Integer init; lua_Integer limit; lua_Integer step; + if (l_unlikely(!tointeger(plimit, &limit))) + luaG_forerror(L, plimit, "limit"); + if (l_unlikely(!tointeger(pstep, &step))) + luaG_forerror(L, pstep, "step"); + if (l_unlikely(!tointeger(pinit, &init))) + luaG_forerror(L, pinit, "initial value"); +#endif /* _KERNEL */ if (step == 0) luaG_runerror(L, "'for' step is zero"); if (forlimit(L, init, plimit, &limit, step)) @@ -240,6 +260,7 @@ static int forprep (lua_State *L, StkId ra) { setivalue(s2v(ra + 1), step); /* change limit to step */ chgivalue(s2v(ra + 2), init); /* change step to init */ } +#ifndef _KERNEL } else { /* try making all values floats */ lua_Number init; lua_Number limit; lua_Number step; @@ -261,10 +282,12 @@ static int forprep (lua_State *L, StkId ra) { setfltvalue(s2v(ra + 2), init); /* control variable */ } } +#endif /* _KERNEL */ return 0; } +#ifndef _KERNEL /* ** Execute a step of a float numerical for loop, returning ** true iff the loop must continue. (The integer case is @@ -283,6 +306,7 @@ static int floatforloop (StkId ra) { else return 0; /* finish the loop */ } +#endif /* _KERNEL */ /* @@ -412,6 +436,7 @@ static int l_strcmp (const TString *ts1, const TString *ts2) { } +#ifndef _KERNEL /* ** Check whether integer 'i' is less than float 'f'. If 'i' has an ** exact representation as a float ('l_intfitsf'), compare numbers as @@ -485,6 +510,7 @@ l_sinline int LEfloatint (lua_Number f, lua_Integer i) { return f < 0; /* less? */ } } +#endif /* _KERNEL */ /* @@ -492,6 +518,7 @@ l_sinline int LEfloatint (lua_Number f, lua_Integer i) { */ l_sinline int LTnum (const TValue *l, const TValue *r) { lua_assert(ttisnumber(l) && ttisnumber(r)); +#ifndef _KERNEL if (ttisinteger(l)) { lua_Integer li = ivalue(l); if (ttisinteger(r)) @@ -506,6 +533,10 @@ l_sinline int LTnum (const TValue *l, const TValue *r) { else /* 'l' is float and 'r' is int */ return LTfloatint(lf, ivalue(r)); } +#else /* _KERNEL */ + lua_assert(ttisinteger(l) && ttisinteger(r)); + return (ivalue(l) < ivalue(r)); +#endif /* _KERNEL */ } @@ -514,6 +545,7 @@ l_sinline int LTnum (const TValue *l, const TValue *r) { */ l_sinline int LEnum (const TValue *l, const TValue *r) { lua_assert(ttisnumber(l) && ttisnumber(r)); +#ifndef _KERNEL if (ttisinteger(l)) { lua_Integer li = ivalue(l); if (ttisinteger(r)) @@ -528,6 +560,10 @@ l_sinline int LEnum (const TValue *l, const TValue *r) { else /* 'l' is float and 'r' is int */ return LEfloatint(lf, ivalue(r)); } +#else /* _KERNEL */ + lua_assert(ttisinteger(l) && ttisinteger(r)); + return (ivalue(l) <= ivalue(r)); +#endif /* _KERNEL */ } @@ -585,6 +621,7 @@ int luaV_equalobj (lua_State *L, const TValue *t1, const TValue *t2) { return 0; else if (ttypetag(t1) != ttypetag(t2)) { switch (ttypetag(t1)) { +#ifndef _KERNEL case LUA_VNUMINT: { /* integer == float? */ /* integer and float can only be equal if float has an integer value equal to the integer */ @@ -597,6 +634,7 @@ int luaV_equalobj (lua_State *L, const TValue *t1, const TValue *t2) { return (luaV_flttointeger(fltvalue(t1), &i1, F2Ieq) && i1 == ivalue(t2)); } +#endif /* _KERNEL */ case LUA_VSHRSTR: case LUA_VLNGSTR: { /* compare two strings with different variants: they can be equal when one string is a short string and the other is @@ -615,8 +653,10 @@ int luaV_equalobj (lua_State *L, const TValue *t1, const TValue *t2) { return 1; case LUA_VNUMINT: return (ivalue(t1) == ivalue(t2)); +#ifndef _KERNEL case LUA_VNUMFLT: return (fltvalue(t1) == fltvalue(t2)); +#endif /* _KERNEL */ case LUA_VLIGHTUSERDATA: return pvalue(t1) == pvalue(t2); case LUA_VSHRSTR: return eqshrstr(tsvalue(t1), tsvalue(t2)); @@ -798,6 +838,7 @@ lua_Integer luaV_mod (lua_State *L, lua_Integer m, lua_Integer n) { } +#ifndef _KERNEL /* ** Float modulus */ @@ -806,6 +847,7 @@ lua_Number luaV_modf (lua_State *L, lua_Number m, lua_Number n) { luai_nummod(L, m, n, r); return r; } +#endif /* _KERNEL */ /* number of bits in an integer */ @@ -941,6 +983,7 @@ void luaV_finishOp (lua_State *L) { ** Arithmetic operations with immediate operands. 'iop' is the integer ** operation, 'fop' is the float operation. */ +#ifndef _KERNEL #define op_arithI(L,iop,fop) { \ TValue *ra = vRA(i); \ TValue *v1 = vRB(i); \ @@ -954,8 +997,19 @@ void luaV_finishOp (lua_State *L) { lua_Number fimm = cast_num(imm); \ pc++; setfltvalue(ra, fop(L, nb, fimm)); \ }} +#else /* _KERNEL */ +#define op_arithI(L,iop,fop) { \ + TValue *ra = vRA(i); \ + TValue *v1 = vRB(i); \ + int imm = GETARG_sC(i); \ + if (ttisinteger(v1)) { \ + lua_Integer iv1 = ivalue(v1); \ + pc++; setivalue(ra, iop(L, iv1, imm)); \ + }} +#endif /* _KERNEL */ +#ifndef _KERNEL /* ** Auxiliary function for arithmetic operations over floats and others ** with two operands. @@ -984,11 +1038,13 @@ void luaV_finishOp (lua_State *L) { TValue *v1 = vRB(i); \ TValue *v2 = KC(i); lua_assert(ttisnumber(v2)); \ op_arithf_aux(L, v1, v2, fop); } +#endif /* _KERNEL */ /* ** Arithmetic operations over integers and floats. */ +#ifndef _KERNEL #define op_arith_aux(L,v1,v2,iop,fop) { \ if (ttisinteger(v1) && ttisinteger(v2)) { \ StkId ra = RA(i); \ @@ -996,6 +1052,14 @@ void luaV_finishOp (lua_State *L) { pc++; setivalue(s2v(ra), iop(L, i1, i2)); \ } \ else op_arithf_aux(L, v1, v2, fop); } +#else /* _KERNEL */ +#define op_arith_aux(L,v1,v2,iop,fop) { \ + if (ttisinteger(v1) && ttisinteger(v2)) { \ + StkId ra = RA(i); \ + lua_Integer i1 = ivalue(v1); lua_Integer i2 = ivalue(v2); \ + pc++; setivalue(s2v(ra), iop(L, i1, i2)); \ + }} +#endif /* _KERNEL */ /* @@ -1068,6 +1132,7 @@ void luaV_finishOp (lua_State *L) { ** Order operations with immediate operand. (Immediate operand is ** always small enough to have an exact representation as a float.) */ +#ifndef _KERNEL #define op_orderI(L,opi,opf,inv,tm) { \ TValue *ra = vRA(i); \ int cond; \ @@ -1084,6 +1149,19 @@ void luaV_finishOp (lua_State *L) { Protect(cond = luaT_callorderiTM(L, ra, im, inv, isf, tm)); \ } \ docondjump(); } +#else /* _KERNEL */ +#define op_orderI(L,opi,opf,inv,tm) { \ + TValue *ra = vRA(i); \ + int cond; \ + int im = GETARG_sB(i); \ + if (ttisinteger(ra)) \ + cond = opi(ivalue(ra), im); \ + else { \ + int isf = GETARG_C(i); \ + Protect(cond = luaT_callorderiTM(L, ra, im, inv, isf, tm)); \ + } \ + docondjump(); } +#endif /* _KERNEL */ /* }================================================================== */ @@ -1241,12 +1319,14 @@ void luaV_execute (lua_State *L, CallInfo *ci) { setivalue(s2v(ra), b); vmbreak; } +#ifndef _KERNEL vmcase(OP_LOADF) { StkId ra = RA(i); int b = GETARG_sBx(i); setfltvalue(s2v(ra), cast_num(b)); vmbreak; } +#endif /* _KERNEL */ vmcase(OP_LOADK) { StkId ra = RA(i); TValue *rb = k + GETARG_Bx(i); @@ -1458,6 +1538,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) { op_arithK(L, luaV_mod, luaV_modf); vmbreak; } +#ifndef _KERNEL vmcase(OP_POWK) { op_arithfK(L, luai_numpow); vmbreak; @@ -1466,6 +1547,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) { op_arithfK(L, luai_numdiv); vmbreak; } +#endif /* _KERNEL */ vmcase(OP_IDIVK) { savestate(L, ci); /* in case of division by 0 */ op_arithK(L, luaV_idiv, luai_numidiv); @@ -1520,6 +1602,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) { op_arith(L, luaV_mod, luaV_modf); vmbreak; } +#ifndef _KERNEL vmcase(OP_POW) { op_arithf(L, luai_numpow); vmbreak; @@ -1528,6 +1611,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) { op_arithf(L, luai_numdiv); vmbreak; } +#endif /* _KERNEL */ vmcase(OP_IDIV) { /* floor division */ savestate(L, ci); /* in case of division by 0 */ op_arith(L, luaV_idiv, luai_numidiv); @@ -1586,6 +1670,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) { vmcase(OP_UNM) { StkId ra = RA(i); TValue *rb = vRB(i); +#ifndef _KERNEL lua_Number nb; if (ttisinteger(rb)) { lua_Integer ib = ivalue(rb); @@ -1594,8 +1679,14 @@ void luaV_execute (lua_State *L, CallInfo *ci) { else if (tonumberns(rb, nb)) { setfltvalue(s2v(ra), luai_numunm(L, nb)); } +#else /* _KERNEL */ + lua_Integer ib; + if (tointeger(rb, &ib)) { + setivalue(s2v(ra), intop(-, 0, ib)); + } else Protect(luaT_trybinTM(L, rb, rb, ra, TM_UNM)); +#endif /* _KERNEL */ vmbreak; } vmcase(OP_BNOT) { @@ -1677,8 +1768,10 @@ void luaV_execute (lua_State *L, CallInfo *ci) { int im = GETARG_sB(i); if (ttisinteger(s2v(ra))) cond = (ivalue(s2v(ra)) == im); +#ifndef _KERNEL else if (ttisfloat(s2v(ra))) cond = luai_numeq(fltvalue(s2v(ra)), cast_num(im)); +#endif /* _KERNEL */ else cond = 0; /* other types cannot be equal to a number */ docondjump(); @@ -1841,8 +1934,10 @@ void luaV_execute (lua_State *L, CallInfo *ci) { pc -= GETARG_Bx(i); /* jump back */ } } +#ifndef _KERNEL else if (floatforloop(ra)) /* float loop */ pc -= GETARG_Bx(i); /* jump back */ +#endif /* _KERNEL */ updatetrap(ci); /* allows a signal to break the loop */ vmbreak; } diff --git a/lvm.h b/lvm.h index be7b9cb0ea..6f26b5841d 100644 --- a/lvm.h +++ b/lvm.h @@ -48,14 +48,23 @@ typedef enum { /* convert an object to a float (including string coercion) */ +#ifndef _KERNEL #define tonumber(o,n) \ (ttisfloat(o) ? (*(n) = fltvalue(o), 1) : luaV_tonumber_(o,n)) +#else /* _KERNEL */ +#define tonumber tointeger +#endif /* _KERNEL */ /* convert an object to a float (without string coercion) */ +#ifndef _KERNEL #define tonumberns(o,n) \ (ttisfloat(o) ? ((n) = fltvalue(o), 1) : \ (ttisinteger(o) ? ((n) = cast_num(ivalue(o)), 1) : 0)) +#else /* _KERNEL */ +#define tonumberns(o,n) \ + (l_likely(ttisinteger(o)) ? ((n) = cast_num(ivalue(o)), 1) : 0) +#endif /* _KERNEL */ /* convert an object to an integer (including string coercion) */