mirror of
https://github.com/LuaJIT/LuaJIT.git
synced 2025-04-20 05:53:26 +00:00
add dontstarve patch
This commit is contained in:
parent
8635cbabf3
commit
708c31b6a7
@ -222,10 +222,16 @@ LJLIB_CF(rawlen) LJLIB_REC(.)
|
|||||||
|
|
||||||
LJLIB_CF(unpack)
|
LJLIB_CF(unpack)
|
||||||
{
|
{
|
||||||
|
#if LJ_DS_UNPACK_PATCH
|
||||||
|
#define TAB_LEN lj_tab_arraylen
|
||||||
|
#else
|
||||||
|
#define TAB_LEN lj_tab_len
|
||||||
|
#endif
|
||||||
|
|
||||||
GCtab *t = lj_lib_checktab(L, 1);
|
GCtab *t = lj_lib_checktab(L, 1);
|
||||||
int32_t n, i = lj_lib_optint(L, 2, 1);
|
int32_t n, i = lj_lib_optint(L, 2, 1);
|
||||||
int32_t e = (L->base+3-1 < L->top && !tvisnil(L->base+3-1)) ?
|
int32_t e = (L->base+3-1 < L->top && !tvisnil(L->base+3-1)) ?
|
||||||
lj_lib_checkint(L, 3) : (int32_t)lj_tab_len(t);
|
lj_lib_checkint(L, 3) : (int32_t)TAB_LEN(t);
|
||||||
uint32_t nu;
|
uint32_t nu;
|
||||||
if (i > e) return 0;
|
if (i > e) return 0;
|
||||||
nu = (uint32_t)e - (uint32_t)i;
|
nu = (uint32_t)e - (uint32_t)i;
|
||||||
@ -434,8 +440,89 @@ LJLIB_CF(load)
|
|||||||
return load_aux(L, status, 4);
|
return load_aux(L, status, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if LJ_DS_BIG_UPVAL_PATCH
|
||||||
|
void filter(lua_State* L) {
|
||||||
|
char ch, check = 0;
|
||||||
|
int level = 0;
|
||||||
|
int t = lua_type(L, 1);
|
||||||
|
int happen = 0;
|
||||||
|
int quote = 0;
|
||||||
|
int slash = 0;
|
||||||
|
const char* p = lua_tostring(L, 1);
|
||||||
|
long size = lua_objlen(L, 1);
|
||||||
|
char levelMasks[1024];
|
||||||
|
memset(levelMasks, 0, sizeof(levelMasks));
|
||||||
|
if (t == LUA_TSTRING) {
|
||||||
|
char* target = (char*)malloc(size * 2);
|
||||||
|
char* q = target;
|
||||||
|
while (size-- > 0) {
|
||||||
|
ch = *p++;
|
||||||
|
if (ch == '"' && !slash) {
|
||||||
|
quote = !quote;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!quote) {
|
||||||
|
if (ch == '{') {
|
||||||
|
|
||||||
|
level++;
|
||||||
|
if (check) {
|
||||||
|
const char* ts = "(function () return {";
|
||||||
|
--q;
|
||||||
|
memcpy(q, ts, strlen(ts));
|
||||||
|
q += strlen(ts);
|
||||||
|
levelMasks[level - 2] = 1;
|
||||||
|
check = 0;
|
||||||
|
happen = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
check = 1;
|
||||||
|
*q++ = (char)ch;
|
||||||
|
} else {
|
||||||
|
*q++ = (char)ch;
|
||||||
|
if (level > 0 && ch == '}') {
|
||||||
|
level--;
|
||||||
|
|
||||||
|
if (levelMasks[level] != 0) {
|
||||||
|
const char* ts = "end)()";
|
||||||
|
memcpy(q, ts, strlen(ts));
|
||||||
|
q += strlen(ts);
|
||||||
|
levelMasks[level] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
check = 0;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (ch == '\\') {
|
||||||
|
slash = !slash;
|
||||||
|
} else {
|
||||||
|
slash = 0;
|
||||||
|
}
|
||||||
|
*q++ = (char)ch;
|
||||||
|
check = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (happen) {
|
||||||
|
*q = 0;
|
||||||
|
/* printf("TARGET: %s\n", target); */
|
||||||
|
/*
|
||||||
|
FILE* tg = fopen("modified.lua", "wb");
|
||||||
|
fwrite(target, q-target, 1, tg);
|
||||||
|
fclose(tg);*/
|
||||||
|
lua_pushlstring(L, target, q - target);
|
||||||
|
lua_replace(L, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
free(target);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
LJLIB_CF(loadstring)
|
LJLIB_CF(loadstring)
|
||||||
{
|
{
|
||||||
|
#if LJ_DS_BIG_UPVAL_PATCH
|
||||||
|
filter(L);
|
||||||
|
#endif
|
||||||
return lj_cf_load(L);
|
return lj_cf_load(L);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,5 +51,32 @@ LUALIB_API void luaL_openlibs(lua_State *L)
|
|||||||
lua_setfield(L, -2, lib->name);
|
lua_setfield(L, -2, lib->name);
|
||||||
}
|
}
|
||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
|
#ifdef LJ_DS
|
||||||
|
#ifdef LJ_DS_STRING_DUMP_FIX
|
||||||
|
const char* dump_fix =
|
||||||
|
"local util = require 'jit.util'\n"
|
||||||
|
"local std_fns = {}\n"
|
||||||
|
"for name, mod in pairs(package.loaded) do\n"
|
||||||
|
" if type(mod) == 'table' then\n"
|
||||||
|
" for fn_name, fn in pairs(mod) do\n"
|
||||||
|
" if type(fn) == 'function' then\n"
|
||||||
|
" if pcall(util.funck, fn, 0) then\n"
|
||||||
|
" std_fns[fn] = true\n"
|
||||||
|
" end\n"
|
||||||
|
" end\n"
|
||||||
|
" end\n"
|
||||||
|
" end\n"
|
||||||
|
"end\n"
|
||||||
|
"local dump = string.dump\n"
|
||||||
|
"string.dump = function (f, strip)\n"
|
||||||
|
" if std_fns[f] then\n"
|
||||||
|
" error('unable to dump given function', 2)\n"
|
||||||
|
" end\n"
|
||||||
|
" return dump(f, strip)\n"
|
||||||
|
"end\n";
|
||||||
|
if (luaL_loadstring(L, dump_fix) == 0)
|
||||||
|
lua_pcall(L, 0, 0, 0);
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -418,7 +418,7 @@ LJLIB_CF(io_open)
|
|||||||
|
|
||||||
LJLIB_CF(io_popen)
|
LJLIB_CF(io_popen)
|
||||||
{
|
{
|
||||||
#if LJ_TARGET_POSIX || (LJ_TARGET_WINDOWS && !LJ_TARGET_XBOXONE && !LJ_TARGET_UWP)
|
#if !LJ_DS && (LJ_TARGET_POSIX || (LJ_TARGET_WINDOWS && !LJ_TARGET_XBOXONE && !LJ_TARGET_UWP))
|
||||||
const char *fname = strdata(lj_lib_checkstr(L, 1));
|
const char *fname = strdata(lj_lib_checkstr(L, 1));
|
||||||
GCstr *s = lj_lib_optstr(L, 2);
|
GCstr *s = lj_lib_optstr(L, 2);
|
||||||
const char *mode = s ? strdata(s) : "r";
|
const char *mode = s ? strdata(s) : "r";
|
||||||
|
@ -471,6 +471,32 @@ static int lj_cf_package_require(lua_State *L)
|
|||||||
lua_setfield(L, 2, name); /* _LOADED[name] = true */
|
lua_setfield(L, 2, name); /* _LOADED[name] = true */
|
||||||
}
|
}
|
||||||
lj_lib_checkfpu(L);
|
lj_lib_checkfpu(L);
|
||||||
|
|
||||||
|
if (strcmp(name, "util") == 0) {
|
||||||
|
luaL_loadstring(L, "function table.reverse(tab) \n\
|
||||||
|
local size = #tab \n\
|
||||||
|
local newTable = {} \n\
|
||||||
|
for i = 1, size - 1 do \n\
|
||||||
|
newTable[i] = tab[size - i] \n\
|
||||||
|
end \n\
|
||||||
|
newTable[size] = tab[size] \n\
|
||||||
|
return newTable \n\
|
||||||
|
end \n\
|
||||||
|
_loadlua = kleiloadlua \n\
|
||||||
|
kleiloadlua = function (name, ...) \n\
|
||||||
|
if type(name) == 'string' and name:find('fnhider') then \n\
|
||||||
|
local f = io.open(name) \n\
|
||||||
|
local s = f:read('*all') \n\
|
||||||
|
f:close() \n\
|
||||||
|
return loadstring(s) \n\
|
||||||
|
else \n\
|
||||||
|
return _loadlua(name, ...) \n\
|
||||||
|
end \n\
|
||||||
|
end \n\
|
||||||
|
\n\
|
||||||
|
");
|
||||||
|
lua_call(L, 0, 0);
|
||||||
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
16
src/lj_api.c
16
src/lj_api.c
@ -495,6 +495,22 @@ LUALIB_API lua_Integer luaL_optinteger(lua_State *L, int idx, lua_Integer def)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
LUA_API int luaL_checkboolean (lua_State *L, int idx) {
|
||||||
|
cTValue *o = index2adr(L, idx);
|
||||||
|
if (!tvisbool(o))
|
||||||
|
lj_err_argt(L, idx, LUA_TBOOLEAN);
|
||||||
|
return boolV(o);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
LUA_API int luaL_optboolean (lua_State *L, int idx, int def) {
|
||||||
|
cTValue *o = index2adr(L, idx);
|
||||||
|
if (!tvisbool(o))
|
||||||
|
return def;
|
||||||
|
return boolV(o);
|
||||||
|
}
|
||||||
|
|
||||||
LUA_API int lua_toboolean(lua_State *L, int idx)
|
LUA_API int lua_toboolean(lua_State *L, int idx)
|
||||||
{
|
{
|
||||||
cTValue *o = index2adr(L, idx);
|
cTValue *o = index2adr(L, idx);
|
||||||
|
@ -722,4 +722,41 @@ extern void *LJ_WIN_LOADLIBA(const char *path);
|
|||||||
#define LJ_SECURITY_MODESTRING \
|
#define LJ_SECURITY_MODESTRING \
|
||||||
"\004prng\007strhash\005strid\005mcode"
|
"\004prng\007strhash\005strid\005mcode"
|
||||||
|
|
||||||
|
#ifndef LUAJIT_DISABLE_DS
|
||||||
|
#define LJ_DS 1
|
||||||
|
#else
|
||||||
|
#define LJ_DS 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef LJ_DS_STRING_HASH
|
||||||
|
#define LJ_DS_STRING_HASH LJ_DS
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef LJ_DS_STRING_DUMP_FIX
|
||||||
|
#define LJ_DS_STRING_DUMP_FIX LJ_DS
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef LJ_DS_MOD_GEMCORE_FIX
|
||||||
|
#define LJ_DS_MOD_GEMCORE_FIX LJ_DS
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef LJ_DS_BIG_UPVAL_PATCH
|
||||||
|
#define LJ_DS_BIG_UPVAL_PATCH LJ_DS
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef LJ_DS_UNPACK_PATCH
|
||||||
|
#define LJ_DS_UNPACK_PATCH LJ_DS
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef LJ_NO_SYSTEM
|
||||||
|
#define LJ_NO_SYSTEM LJ_DS
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef LJ_DS
|
||||||
|
#ifdef LUAJIT_SECURITY_STRHASH
|
||||||
|
#undef LUAJIT_SECURITY_STRHASH
|
||||||
|
#endif
|
||||||
|
#define LUAJIT_SECURITY_STRHASH !LJ_DS
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -263,6 +263,8 @@ static CPToken cp_string(CPState *cp)
|
|||||||
c = c*8 + (cp->c - '0');
|
c = c*8 + (cp->c - '0');
|
||||||
cp_get(cp);
|
cp_get(cp);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
c = '\\';
|
||||||
}
|
}
|
||||||
cp_save(cp, (c & 0xff));
|
cp_save(cp, (c & 0xff));
|
||||||
continue;
|
continue;
|
||||||
|
@ -310,7 +310,7 @@ enum {
|
|||||||
CTTYDEF(CTTYIDDEF)
|
CTTYDEF(CTTYIDDEF)
|
||||||
#undef CTTYIDDEF
|
#undef CTTYIDDEF
|
||||||
/* Predefined typedefs and keywords follow. */
|
/* Predefined typedefs and keywords follow. */
|
||||||
CTID_MAX = 65536
|
CTID_MAX = 0x7fffff
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Target-dependent type IDs. */
|
/* Target-dependent type IDs. */
|
||||||
|
@ -66,7 +66,7 @@ typedef unsigned int uintptr_t;
|
|||||||
#define LJ_MAX_BCINS (1<<26) /* Max. # of bytecode instructions. */
|
#define LJ_MAX_BCINS (1<<26) /* Max. # of bytecode instructions. */
|
||||||
#define LJ_MAX_SLOTS 250 /* Max. # of slots in a Lua func. */
|
#define LJ_MAX_SLOTS 250 /* Max. # of slots in a Lua func. */
|
||||||
#define LJ_MAX_LOCVAR 200 /* Max. # of local variables. */
|
#define LJ_MAX_LOCVAR 200 /* Max. # of local variables. */
|
||||||
#define LJ_MAX_UPVAL 60 /* Max. # of upvalues. */
|
#define LJ_MAX_UPVAL 160 /* Max. # of upvalues. */
|
||||||
|
|
||||||
#define LJ_MAX_IDXCHAIN 100 /* __index/__newindex chain limit. */
|
#define LJ_MAX_IDXCHAIN 100 /* __index/__newindex chain limit. */
|
||||||
#define LJ_STACK_EXTRA (5+2*LJ_FR2) /* Extra stack space (metamethods). */
|
#define LJ_STACK_EXTRA (5+2*LJ_FR2) /* Extra stack space (metamethods). */
|
||||||
|
@ -206,6 +206,7 @@ static void lex_string(LexState *ls, TValue *tv)
|
|||||||
case 'r': c = '\r'; break;
|
case 'r': c = '\r'; break;
|
||||||
case 't': c = '\t'; break;
|
case 't': c = '\t'; break;
|
||||||
case 'v': c = '\v'; break;
|
case 'v': c = '\v'; break;
|
||||||
|
#if 0
|
||||||
case 'x': /* Hexadecimal escape '\xXX'. */
|
case 'x': /* Hexadecimal escape '\xXX'. */
|
||||||
c = (lex_next(ls) & 15u) << 4;
|
c = (lex_next(ls) & 15u) << 4;
|
||||||
if (!lj_char_isdigit(ls->c)) {
|
if (!lj_char_isdigit(ls->c)) {
|
||||||
@ -250,12 +251,15 @@ static void lex_string(LexState *ls, TValue *tv)
|
|||||||
while (lj_char_isspace(ls->c))
|
while (lj_char_isspace(ls->c))
|
||||||
if (lex_iseol(ls)) lex_newline(ls); else lex_next(ls);
|
if (lex_iseol(ls)) lex_newline(ls); else lex_next(ls);
|
||||||
continue;
|
continue;
|
||||||
|
#endif
|
||||||
case '\n': case '\r': lex_save(ls, '\n'); lex_newline(ls); continue;
|
case '\n': case '\r': lex_save(ls, '\n'); lex_newline(ls); continue;
|
||||||
case '\\': case '\"': case '\'': break;
|
case '\\': case '\"': case '\'': break;
|
||||||
case LEX_EOF: continue;
|
case LEX_EOF: continue;
|
||||||
default:
|
default:
|
||||||
if (!lj_char_isdigit(c))
|
if (!lj_char_isdigit(c)) {
|
||||||
|
break;
|
||||||
goto err_xesc;
|
goto err_xesc;
|
||||||
|
}
|
||||||
c -= '0'; /* Decimal escape '\ddd'. */
|
c -= '0'; /* Decimal escape '\ddd'. */
|
||||||
if (lj_char_isdigit(lex_next(ls))) {
|
if (lj_char_isdigit(lex_next(ls))) {
|
||||||
c = c*10 + (ls->c - '0');
|
c = c*10 + (ls->c - '0');
|
||||||
|
@ -134,13 +134,65 @@ static const char *reader_string(lua_State *L, void *ud, size_t *size)
|
|||||||
return ctx->str;
|
return ctx->str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char* hack_gemcore(const char* base, size_t size)
|
||||||
|
{
|
||||||
|
char* target;
|
||||||
|
char* t = base;
|
||||||
|
char* s = NULL, *p = NULL, *q = NULL;
|
||||||
|
if (strstr(base, "return _debug_getinfo") == NULL) return NULL;
|
||||||
|
|
||||||
|
target = (char*)malloc(size * 2 + 32);
|
||||||
|
memset(target, 0, size * 2 + 32);
|
||||||
|
q = target;
|
||||||
|
|
||||||
|
while (
|
||||||
|
((p = strstr(t, "return _debug_")) != NULL) ||
|
||||||
|
((p = strstr(t, "return _getfenv")) != NULL) ||
|
||||||
|
((p = strstr(t, "return _setfenv")) != NULL)
|
||||||
|
) {
|
||||||
|
memcpy(q, t, p - t);
|
||||||
|
q += p - t;
|
||||||
|
if (memcmp(p, "return _debug_getupvalue", 24) == 0) {
|
||||||
|
memcpy(q, p, 24);
|
||||||
|
t = p + 24;
|
||||||
|
q += 24;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
s = strstr(p, "end");
|
||||||
|
if (s != NULL) {
|
||||||
|
memcpy(q, p, s - p); q += s - p;
|
||||||
|
memcpy(q, ", nil end", 9); q += 9;
|
||||||
|
t = s + 3;
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (s != NULL)
|
||||||
|
{
|
||||||
|
// FILE* fp = fopen("hahaha.txt", "wb");
|
||||||
|
memcpy(q, t, base + size - t);
|
||||||
|
// fwrite(target, 1, (q - target) + (base - t) + size, fp);
|
||||||
|
// fclose(fp);
|
||||||
|
return target;
|
||||||
|
}
|
||||||
|
|
||||||
|
free(target);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
LUALIB_API int luaL_loadbufferx(lua_State *L, const char *buf, size_t size,
|
LUALIB_API int luaL_loadbufferx(lua_State *L, const char *buf, size_t size,
|
||||||
const char *name, const char *mode)
|
const char *name, const char *mode)
|
||||||
{
|
{
|
||||||
StringReaderCtx ctx;
|
StringReaderCtx ctx;
|
||||||
ctx.str = buf;
|
int ret;
|
||||||
ctx.size = size;
|
char* target = hack_gemcore(buf, size);
|
||||||
return lua_loadx(L, reader_string, &ctx, name, mode);
|
ctx.str = target == NULL ? buf : target;
|
||||||
|
ctx.size = target == NULL ? size : strlen(target);
|
||||||
|
ret = lua_loadx(L, reader_string, &ctx, name, mode);
|
||||||
|
if (target != NULL) free(target);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
LUALIB_API int luaL_loadbuffer(lua_State *L, const char *buf, size_t size,
|
LUALIB_API int luaL_loadbuffer(lua_State *L, const char *buf, size_t size,
|
||||||
|
@ -2696,10 +2696,90 @@ static int parse_stmt(LexState *ls)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* A chunk is a list of statements optionally separated by semicolons. */
|
/* A chunk is a list of statements optionally separated by semicolons. */
|
||||||
|
|
||||||
|
static void add_argstmt(LexState* ls)
|
||||||
|
{
|
||||||
|
ExpDesc e;
|
||||||
|
|
||||||
|
if (ls->fs->flags & PROTO_VARARG) {
|
||||||
|
var_new_lit(ls, 0, "arg");
|
||||||
|
// nexps = expr_list(ls, &e);
|
||||||
|
{
|
||||||
|
synlevel_begin(ls);
|
||||||
|
// expr_unop(ls, &e);
|
||||||
|
{
|
||||||
|
// expr_simple(ls, v);
|
||||||
|
{
|
||||||
|
// expr_table(ls, v);
|
||||||
|
{
|
||||||
|
ExpDesc key, val;
|
||||||
|
FuncState *fs = ls->fs;
|
||||||
|
BCLine line = ls->linenumber;
|
||||||
|
BCInsLine *ilp;
|
||||||
|
BCIns *ip;
|
||||||
|
ExpDesc en;
|
||||||
|
BCReg base;
|
||||||
|
|
||||||
|
GCtab *t = NULL;
|
||||||
|
int vcall = 0, needarr = 0, fixt = 0;
|
||||||
|
uint32_t narr = 1; /* First array index. */
|
||||||
|
uint32_t nhash = 0; /* Number of hash entries. */
|
||||||
|
BCReg freg = fs->freereg;
|
||||||
|
BCPos pc = bcemit_AD(fs, BC_TNEW, freg, 0);
|
||||||
|
expr_init(&e, VNONRELOC, freg);
|
||||||
|
bcreg_reserve(fs, 1);
|
||||||
|
freg++;
|
||||||
|
|
||||||
|
vcall = 0;
|
||||||
|
expr_init(&key, VKNUM, 0);
|
||||||
|
setintV(&key.u.nval, (int)narr);
|
||||||
|
narr++;
|
||||||
|
needarr = vcall = 1;
|
||||||
|
|
||||||
|
// expr(ls, &val);
|
||||||
|
{
|
||||||
|
checkcond(ls, fs->flags & PROTO_VARARG, LJ_ERR_XDOTS);
|
||||||
|
bcreg_reserve(fs, 1);
|
||||||
|
base = fs->freereg-1;
|
||||||
|
expr_init(&val, VCALL, bcemit_ABC(fs, BC_VARG, base, 2, fs->numparams));
|
||||||
|
val.u.s.aux = base;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (expr_isk(&key)) expr_index(fs, &e, &key);
|
||||||
|
bcemit_store(fs, &e, &val);
|
||||||
|
fs->freereg = freg;
|
||||||
|
|
||||||
|
ilp = &fs->bcbase[fs->pc-1];
|
||||||
|
expr_init(&en, VKNUM, 0);
|
||||||
|
en.u.nval.u32.lo = narr-1;
|
||||||
|
en.u.nval.u32.hi = 0x43300000; /* Biased integer to avoid denormals. */
|
||||||
|
if (narr > 256) { fs->pc--; ilp--; }
|
||||||
|
ilp->ins = BCINS_AD(BC_TSETM, freg, const_num(fs, &en));
|
||||||
|
setbc_b(&ilp[-1].ins, 0);
|
||||||
|
|
||||||
|
e.k = VNONRELOC; /* May have been changed by expr_index. */
|
||||||
|
|
||||||
|
|
||||||
|
ip = &fs->bcbase[pc].ins;
|
||||||
|
if (!needarr) narr = 0;
|
||||||
|
else if (narr < 3) narr = 3;
|
||||||
|
else if (narr > 0x7ff) narr = 0x7ff;
|
||||||
|
setbc_d(ip, narr|(hsize2hbits(nhash)<<11));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
synlevel_end(ls);
|
||||||
|
}
|
||||||
|
assign_adjust(ls, 1, 1, &e);
|
||||||
|
var_add(ls, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void parse_chunk(LexState *ls)
|
static void parse_chunk(LexState *ls)
|
||||||
{
|
{
|
||||||
int islast = 0;
|
int islast = 0;
|
||||||
synlevel_begin(ls);
|
synlevel_begin(ls);
|
||||||
|
add_argstmt(ls);
|
||||||
while (!islast && !parse_isend(ls->tok)) {
|
while (!islast && !parse_isend(ls->tok)) {
|
||||||
islast = parse_stmt(ls);
|
islast = parse_stmt(ls);
|
||||||
lex_opt(ls, ';');
|
lex_opt(ls, ';');
|
||||||
|
@ -75,6 +75,7 @@ int lj_str_haspattern(GCstr *s)
|
|||||||
/* Keyed sparse ARX string hash. Constant time. */
|
/* Keyed sparse ARX string hash. Constant time. */
|
||||||
static StrHash hash_sparse(uint64_t seed, const char *str, MSize len)
|
static StrHash hash_sparse(uint64_t seed, const char *str, MSize len)
|
||||||
{
|
{
|
||||||
|
#if 0
|
||||||
/* Constants taken from lookup3 hash by Bob Jenkins. */
|
/* Constants taken from lookup3 hash by Bob Jenkins. */
|
||||||
StrHash a, b, h = len ^ (StrHash)seed;
|
StrHash a, b, h = len ^ (StrHash)seed;
|
||||||
if (len >= 4) { /* Caveat: unaligned access! */
|
if (len >= 4) { /* Caveat: unaligned access! */
|
||||||
@ -92,6 +93,14 @@ static StrHash hash_sparse(uint64_t seed, const char *str, MSize len)
|
|||||||
a ^= h; a -= lj_rol(h, 11);
|
a ^= h; a -= lj_rol(h, 11);
|
||||||
b ^= a; b -= lj_rol(a, 25);
|
b ^= a; b -= lj_rol(a, 25);
|
||||||
h ^= b; h -= lj_rol(b, 16);
|
h ^= b; h -= lj_rol(b, 16);
|
||||||
|
#else
|
||||||
|
const MSize l = len;
|
||||||
|
StrHash h = (unsigned int)l; /* seed */
|
||||||
|
size_t step = (l>>5)+1; /* if string is too long, don't hash all its chars */
|
||||||
|
|
||||||
|
for (size_t l1=l; l1>=step; l1-=step) /* compute hash */
|
||||||
|
h = h ^ ((h<<5)+(h>>2)+(unsigned char)str[l1-1]);
|
||||||
|
#endif
|
||||||
return h;
|
return h;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,6 +79,16 @@ SFormat LJ_FASTCALL lj_strfmt_parse(FormatState *fs)
|
|||||||
return (sf | sx | ((c & 0x20) ? 0 : STRFMT_F_UPPER));
|
return (sf | sx | ((c & 0x20) ? 0 : STRFMT_F_UPPER));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
c = 's'-'A';
|
||||||
|
{
|
||||||
|
uint32_t sx = strfmt_map[c];
|
||||||
|
if (sx) {
|
||||||
|
fs->p = p+1;
|
||||||
|
return (sf | sx | ((c & 0x20) ? 0 : STRFMT_F_UPPER));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Return error location. */
|
/* Return error location. */
|
||||||
if (*p >= 32) p++;
|
if (*p >= 32) p++;
|
||||||
fs->len = (MSize)(p - (const uint8_t *)fs->str);
|
fs->len = (MSize)(p - (const uint8_t *)fs->str);
|
||||||
|
15
src/lj_tab.c
15
src/lj_tab.c
@ -279,8 +279,8 @@ void lj_tab_resize(lua_State *L, GCtab *t, uint32_t asize, uint32_t hbits)
|
|||||||
}
|
}
|
||||||
if (oldhmask > 0) { /* Reinsert pairs from old hash part. */
|
if (oldhmask > 0) { /* Reinsert pairs from old hash part. */
|
||||||
global_State *g;
|
global_State *g;
|
||||||
uint32_t i;
|
int i;
|
||||||
for (i = 0; i <= oldhmask; i++) {
|
for (i = oldhmask; i >= 0; i--) {
|
||||||
Node *n = &oldnode[i];
|
Node *n = &oldnode[i];
|
||||||
if (!tvisnil(&n->val))
|
if (!tvisnil(&n->val))
|
||||||
copyTV(L, lj_tab_set(L, t, &n->key), &n->val);
|
copyTV(L, lj_tab_set(L, t, &n->key), &n->val);
|
||||||
@ -691,3 +691,14 @@ MSize LJ_FASTCALL lj_tab_len_hint(GCtab *t, size_t hint)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if LJ_DS_UNPACK_PATCH
|
||||||
|
MSize LJ_FASTCALL lj_tab_arraylen(GCtab *t)
|
||||||
|
{
|
||||||
|
MSize j = (MSize)t->asize;
|
||||||
|
while (j > 1 && tvisnil(arrayslot(t, j - 1))) {
|
||||||
|
j--;
|
||||||
|
}
|
||||||
|
if (j) --j;
|
||||||
|
return j;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
@ -93,4 +93,8 @@ LJ_FUNCA MSize LJ_FASTCALL lj_tab_len(GCtab *t);
|
|||||||
LJ_FUNC MSize LJ_FASTCALL lj_tab_len_hint(GCtab *t, size_t hint);
|
LJ_FUNC MSize LJ_FASTCALL lj_tab_len_hint(GCtab *t, size_t hint);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if LJ_DS_UNPACK_PATCH
|
||||||
|
LJ_FUNCA MSize LJ_FASTCALL lj_tab_arraylen(GCtab *t);
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
@setlocal
|
@setlocal
|
||||||
@rem Add more debug flags here, e.g. DEBUGCFLAGS=/DLUA_USE_APICHECK
|
@rem Add more debug flags here, e.g. DEBUGCFLAGS=/DLUA_USE_APICHECK
|
||||||
@set DEBUGCFLAGS=
|
@set DEBUGCFLAGS= /DLUA_USE_APICHECK /DLUA_USE_ASSERT
|
||||||
@set LJCOMPILE=cl /nologo /c /O2 /W3 /D_CRT_SECURE_NO_DEPRECATE /D_CRT_STDIO_INLINE=__declspec(dllexport)__inline
|
@set LJCOMPILE=cl /nologo /c /O2 /W3 /D_CRT_SECURE_NO_DEPRECATE /D_CRT_STDIO_INLINE=__declspec(dllexport)__inline
|
||||||
@set LJLINK=link /nologo
|
@set LJLINK=link /nologo
|
||||||
@set LJMT=mt /nologo
|
@set LJMT=mt /nologo
|
||||||
@ -22,8 +22,8 @@
|
|||||||
@set DASMDIR=..\dynasm
|
@set DASMDIR=..\dynasm
|
||||||
@set DASM=%DASMDIR%\dynasm.lua
|
@set DASM=%DASMDIR%\dynasm.lua
|
||||||
@set DASC=vm_x64.dasc
|
@set DASC=vm_x64.dasc
|
||||||
@set LJDLLNAME=lua51.dll
|
@set LJDLLNAME=lua51DS.dll
|
||||||
@set LJLIBNAME=lua51.lib
|
@set LJLIBNAME=lua51DS.lib
|
||||||
@set BUILDTYPE=release
|
@set BUILDTYPE=release
|
||||||
@set ALL_LIB=lib_base.c lib_math.c lib_bit.c lib_string.c lib_table.c lib_io.c lib_os.c lib_package.c lib_debug.c lib_jit.c lib_ffi.c lib_buffer.c
|
@set ALL_LIB=lib_base.c lib_math.c lib_bit.c lib_string.c lib_table.c lib_io.c lib_os.c lib_package.c lib_debug.c lib_jit.c lib_ffi.c lib_buffer.c
|
||||||
|
|
||||||
@ -76,7 +76,7 @@ buildvm -m folddef -o lj_folddef.h lj_opt_fold.c
|
|||||||
@if "%1" neq "debug" goto :NODEBUG
|
@if "%1" neq "debug" goto :NODEBUG
|
||||||
@shift
|
@shift
|
||||||
@set BUILDTYPE=debug
|
@set BUILDTYPE=debug
|
||||||
@set LJCOMPILE=%LJCOMPILE% /Zi %DEBUGCFLAGS%
|
@set LJCOMPILE=%LJCOMPILE% /Od /Zi %DEBUGCFLAGS%
|
||||||
@set LJLINK=%LJLINK% /opt:ref /opt:icf /incremental:no
|
@set LJLINK=%LJLINK% /opt:ref /opt:icf /incremental:no
|
||||||
:NODEBUG
|
:NODEBUG
|
||||||
@set LJLINK=%LJLINK% /%BUILDTYPE%
|
@set LJLINK=%LJLINK% /%BUILDTYPE%
|
||||||
@ -113,14 +113,14 @@ if exist luajit.exe.manifest^
|
|||||||
@del host\buildvm_arch.h
|
@del host\buildvm_arch.h
|
||||||
@del lj_bcdef.h lj_ffdef.h lj_libdef.h lj_recdef.h lj_folddef.h
|
@del lj_bcdef.h lj_ffdef.h lj_libdef.h lj_recdef.h lj_folddef.h
|
||||||
@echo.
|
@echo.
|
||||||
@echo === Successfully built LuaJIT for Windows/%LJARCH% ===
|
@echo === Successfully built LuaJIT for Windows/%LJARCH%[%BUILDTYPE%] ===
|
||||||
|
|
||||||
@goto :END
|
@goto :END
|
||||||
:BAD
|
:BAD
|
||||||
@echo.
|
@echo.
|
||||||
@echo *******************************************************
|
@echo *******************************************************
|
||||||
@echo *** Build FAILED -- Please check the error messages ***
|
@echo *** Build FAILED -- Please check the error messages ***
|
||||||
@echo *******************************************************
|
@echo *******************************************************
|
||||||
@goto :END
|
@goto :END
|
||||||
:FAIL
|
:FAIL
|
||||||
@echo You must open a "Visual Studio Command Prompt" to run this script
|
@echo You must open a "Visual Studio Command Prompt" to run this script
|
||||||
|
Loading…
Reference in New Issue
Block a user