Skip to content

Commit

Permalink
update Lua.
Browse files Browse the repository at this point in the history
  • Loading branch information
pigpigyyy committed Apr 4, 2024
1 parent e140fc0 commit 6f527fd
Show file tree
Hide file tree
Showing 21 changed files with 227 additions and 207 deletions.
60 changes: 30 additions & 30 deletions Source/3rdParty/Lua/lapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ LUA_API void lua_arith (lua_State *L, int op) {
}
/* first operand at top - 2, second at top - 1; result go to top - 2 */
luaO_arith(L, op, s2v(L->top.p - 2), s2v(L->top.p - 1), L->top.p - 2);
L->top.p--; /* remove second operand */
L->top.p--; /* pop second operand */
lua_unlock(L);
}

Expand Down Expand Up @@ -683,27 +683,27 @@ LUA_API int lua_pushthread (lua_State *L) {


static int auxgetstr (lua_State *L, const TValue *t, const char *k) {
int hres;
int tag;
TString *str = luaS_new(L, k);
luaV_fastget(t, str, s2v(L->top.p), luaH_getstr, hres);
if (hres == HOK) {
luaV_fastget(t, str, s2v(L->top.p), luaH_getstr, tag);
if (!tagisempty(tag)) {
api_incr_top(L);
}
else {
setsvalue2s(L, L->top.p, str);
api_incr_top(L);
luaV_finishget(L, t, s2v(L->top.p - 1), L->top.p - 1, hres);
tag = luaV_finishget(L, t, s2v(L->top.p - 1), L->top.p - 1, tag);
}
lua_unlock(L);
return ttype(s2v(L->top.p - 1));
return novariant(tag);
}


static void getGlobalTable (lua_State *L, TValue *gt) {
Table *registry = hvalue(&G(L)->l_registry);
int hres = luaH_getint(registry, LUA_RIDX_GLOBALS, gt);
(void)hres; /* avoid warnings (not used) when checks are off */
api_check(L, hres == HOK, "global table must exist");
int tag = luaH_getint(registry, LUA_RIDX_GLOBALS, gt);
(void)tag; /* avoid not-used warnings when checks are off */
api_check(L, novariant(tag) == LUA_TTABLE, "global table must exist");
}


Expand All @@ -716,16 +716,16 @@ LUA_API int lua_getglobal (lua_State *L, const char *name) {


LUA_API int lua_gettable (lua_State *L, int idx) {
int hres;
int tag;
TValue *t;
lua_lock(L);
api_checkpop(L, 1);
t = index2value(L, idx);
luaV_fastget(t, s2v(L->top.p - 1), s2v(L->top.p - 1), luaH_get, hres);
if (hres != HOK)
luaV_finishget(L, t, s2v(L->top.p - 1), L->top.p - 1, hres);
luaV_fastget(t, s2v(L->top.p - 1), s2v(L->top.p - 1), luaH_get, tag);
if (tagisempty(tag))
tag = luaV_finishget(L, t, s2v(L->top.p - 1), L->top.p - 1, tag);
lua_unlock(L);
return ttype(s2v(L->top.p - 1));
return novariant(tag);
}


Expand All @@ -737,27 +737,27 @@ LUA_API int lua_getfield (lua_State *L, int idx, const char *k) {

LUA_API int lua_geti (lua_State *L, int idx, lua_Integer n) {
TValue *t;
int hres;
int tag;
lua_lock(L);
t = index2value(L, idx);
luaV_fastgeti(t, n, s2v(L->top.p), hres);
if (hres != HOK) {
luaV_fastgeti(t, n, s2v(L->top.p), tag);
if (tagisempty(tag)) {
TValue key;
setivalue(&key, n);
luaV_finishget(L, t, &key, L->top.p, hres);
tag = luaV_finishget(L, t, &key, L->top.p, tag);
}
api_incr_top(L);
lua_unlock(L);
return ttype(s2v(L->top.p - 1));
return novariant(tag);
}


l_sinline int finishrawget (lua_State *L, int hres) {
if (hres != HOK) /* avoid copying empty items to the stack */
static int finishrawget (lua_State *L, int tag) {
if (tagisempty(tag)) /* avoid copying empty items to the stack */
setnilvalue(s2v(L->top.p));
api_incr_top(L);
lua_unlock(L);
return ttype(s2v(L->top.p - 1));
return novariant(tag);
}


Expand All @@ -770,23 +770,23 @@ l_sinline Table *gettable (lua_State *L, int idx) {

LUA_API int lua_rawget (lua_State *L, int idx) {
Table *t;
int tag;
lua_lock(L);
api_checkpop(L, 1);
t = gettable(L, idx);
if (luaH_get(t, s2v(L->top.p - 1), s2v(L->top.p - 1)) != HOK)
setnilvalue(s2v(L->top.p - 1));
lua_unlock(L);
return ttype(s2v(L->top.p - 1));
tag = luaH_get(t, s2v(L->top.p - 1), s2v(L->top.p - 1));
L->top.p--; /* pop key */
return finishrawget(L, tag);
}


LUA_API int lua_rawgeti (lua_State *L, int idx, lua_Integer n) {
Table *t;
int hres;
int tag;
lua_lock(L);
t = gettable(L, idx);
luaH_fastgeti(t, n, s2v(L->top.p), hres);
return finishrawget(L, hres);
luaH_fastgeti(t, n, s2v(L->top.p), tag);
return finishrawget(L, tag);
}


Expand Down Expand Up @@ -1301,7 +1301,7 @@ LUA_API int lua_next (lua_State *L, int idx) {
if (more)
api_incr_top(L);
else /* no more elements */
L->top.p -= 1; /* remove key */
L->top.p--; /* pop key */
lua_unlock(L);
return more;
}
Expand Down
2 changes: 1 addition & 1 deletion Source/3rdParty/Lua/lauxlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ LUALIB_API int (luaL_loadstring) (lua_State *L, const char *s);

LUALIB_API lua_State *(luaL_newstate) (void);

LUALIB_API unsigned int luaL_makeseed (lua_State *L);
LUALIB_API unsigned luaL_makeseed (lua_State *L);

LUALIB_API lua_Integer (luaL_len) (lua_State *L, int idx);

Expand Down
4 changes: 2 additions & 2 deletions Source/3rdParty/Lua/lcode.c
Original file line number Diff line number Diff line change
Expand Up @@ -544,9 +544,9 @@ static int addk (FuncState *fs, TValue *key, TValue *v) {
TValue val;
lua_State *L = fs->ls->L;
Proto *f = fs->f;
int aux = luaH_get(fs->ls->h, key, &val); /* query scanner table */
int tag = luaH_get(fs->ls->h, key, &val); /* query scanner table */
int k, oldsize;
if (aux == HOK && ttisinteger(&val)) { /* is there an index there? */
if (tag == LUA_VNUMINT) { /* is there an index there? */
k = cast_int(ivalue(&val));
/* correct value? (warning: must distinguish floats from integers!) */
if (k < fs->nk && ttypetag(&f->k[k]) == ttypetag(v) &&
Expand Down
2 changes: 1 addition & 1 deletion Source/3rdParty/Lua/lcode.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ typedef enum UnOpr { OPR_MINUS, OPR_BNOT, OPR_NOT, OPR_LEN, OPR_NOUNOPR } UnOpr;
#define luaK_jumpto(fs,t) luaK_patchlist(fs, luaK_jump(fs), t)

LUAI_FUNC int luaK_code (FuncState *fs, Instruction i);
LUAI_FUNC int luaK_codeABx (FuncState *fs, OpCode o, int A, unsigned int Bx);
LUAI_FUNC int luaK_codeABx (FuncState *fs, OpCode o, int A, unsigned Bx);
LUAI_FUNC int luaK_codeABCk (FuncState *fs, OpCode o, int A,
int B, int C, int k);
LUAI_FUNC int luaK_exp2const (FuncState *fs, const expdesc *e, TValue *v);
Expand Down
25 changes: 15 additions & 10 deletions Source/3rdParty/Lua/ldump.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ typedef struct {
int strip;
int status;
Table *h; /* table to track saved strings */
lua_Unsigned nstr; /* counter to number saved strings */
lua_Integer nstr; /* counter for counting saved strings */
} DumpState;


Expand Down Expand Up @@ -86,12 +86,12 @@ static void dumpByte (DumpState *D, int y) {
** size for 'dumpVarint' buffer: each byte can store up to 7 bits.
** (The "+6" rounds up the division.)
*/
#define DIBS ((sizeof(varint_t) * CHAR_BIT + 6) / 7)
#define DIBS ((sizeof(size_t) * CHAR_BIT + 6) / 7)

/*
** Dumps an unsigned integer using the MSB Varint encoding
*/
static void dumpVarint (DumpState *D, varint_t x) {
static void dumpVarint (DumpState *D, size_t x) {
lu_byte buff[DIBS];
int n = 1;
buff[DIBS - 1] = x & 0x7f; /* fill least-significant byte */
Expand All @@ -101,9 +101,13 @@ static void dumpVarint (DumpState *D, varint_t x) {
}


static void dumpSize (DumpState *D, size_t sz) {
dumpVarint(D, sz);
}

static void dumpInt (DumpState *D, int x) {
lua_assert(x >= 0);
dumpVarint(D, x);
dumpVarint(D, cast(size_t, x));
}


Expand All @@ -126,22 +130,23 @@ static void dumpInteger (DumpState *D, lua_Integer x) {
*/
static void dumpString (DumpState *D, TString *ts) {
if (ts == NULL)
dumpVarint(D, 0);
dumpSize(D, 0);
else {
TValue idx;
if (luaH_getstr(D->h, ts, &idx) == HOK) { /* string already saved? */
dumpVarint(D, 1); /* reuse a saved string */
dumpVarint(D, l_castS2U(ivalue(&idx))); /* index of saved string */
int tag = luaH_getstr(D->h, ts, &idx);
if (!tagisempty(tag)) { /* string already saved? */
dumpSize(D, 1); /* reuse a saved string */
dumpSize(D, cast_sizet(ivalue(&idx))); /* index of saved string */
}
else { /* must write and save the string */
TValue key, value; /* to save the string in the hash */
size_t size;
const char *s = getlstr(ts, size);
dumpVarint(D, size + 2);
dumpSize(D, size + 2);
dumpVector(D, s, size + 1); /* include ending '\0' */
D->nstr++; /* one more saved string */
setsvalue(D->L, &key, ts); /* the string is the key */
setivalue(&value, l_castU2S(D->nstr)); /* its index is the value */
setivalue(&value, D->nstr); /* its index is the value */
luaH_set(D->L, D->h, &key, &value); /* h[ts] = nstr */
/* integer value does not need barrier */
}
Expand Down
40 changes: 20 additions & 20 deletions Source/3rdParty/Lua/lgc.c
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,24 @@ static void traverseweakvalue (global_State *g, Table *h) {
}


/*
** Traverse the array part of a table.
*/
static int traversearray (global_State *g, Table *h) {
unsigned asize = luaH_realasize(h);
int marked = 0; /* true if some object is marked in this traversal */
unsigned i;
for (i = 0; i < asize; i++) {
GCObject *o = gcvalarr(h, i);
if (o != NULL && iswhite(o)) {
marked = 1;
reallymarkobject(g, o);
}
}
return marked;
}


/*
** Traverse an ephemeron table and link it to proper list. Returns true
** iff any object was marked during this traversal (which implies that
Expand All @@ -478,20 +496,11 @@ static void traverseweakvalue (global_State *g, Table *h) {
** by 'genlink'.
*/
static int traverseephemeron (global_State *g, Table *h, int inv) {
int marked = 0; /* true if an object is marked in this traversal */
int hasclears = 0; /* true if table has white keys */
int hasww = 0; /* true if table has entry "white-key -> white-value" */
unsigned int i;
unsigned int asize = luaH_realasize(h);
unsigned int nsize = sizenode(h);
/* traverse array part */
for (i = 0; i < asize; i++) {
GCObject *o = gcvalarr(h, i);
if (o != NULL && iswhite(o)) {
marked = 1;
reallymarkobject(g, o);
}
}
int marked = traversearray(g, h); /* traverse array part */
/* traverse hash part; if 'inv', traverse descending
(see 'convergeephemerons') */
for (i = 0; i < nsize; i++) {
Expand Down Expand Up @@ -523,13 +532,7 @@ static int traverseephemeron (global_State *g, Table *h, int inv) {

static void traversestrongtable (global_State *g, Table *h) {
Node *n, *limit = gnodelast(h);
unsigned int i;
unsigned int asize = luaH_realasize(h);
for (i = 0; i < asize; i++) { /* traverse array part */
GCObject *o = gcvalarr(h, i);
if (o != NULL && iswhite(o))
reallymarkobject(g, o);
}
traversearray(g, h);
for (n = gnode(h, 0); n < limit; n++) { /* traverse hash part */
if (isempty(gval(n))) /* entry is empty? */
clearkey(n); /* clear its key */
Expand Down Expand Up @@ -1052,7 +1055,6 @@ static void setpause (global_State *g) {
l_obj threshold = applygcparam(g, PAUSE, g->marked);
l_obj debt = threshold - gettotalobjs(g);
if (debt < 0) debt = 0;
//printf("pause: %ld %ld\n", debt, g->marked);
luaE_setdebt(g, debt);
}

Expand Down Expand Up @@ -1258,7 +1260,6 @@ static void minor2inc (lua_State *L, global_State *g, int kind) {
static int checkminormajor (global_State *g, l_obj addedold1) {
l_obj step = applygcparam(g, MINORMUL, g->GCmajorminor);
l_obj limit = applygcparam(g, MINORMAJOR, g->GCmajorminor);
//printf("-> (%ld) major? marked: %ld limit: %ld step: %ld addedold1: %ld)\n", gettotalobjs(g), g->marked, limit, step, addedold1);
return (addedold1 >= (step >> 1) || g->marked >= limit);
}

Expand Down Expand Up @@ -1407,7 +1408,6 @@ static int checkmajorminor (lua_State *L, global_State *g) {
l_obj addedobjs = numobjs - g->GCmajorminor;
l_obj limit = applygcparam(g, MAJORMINOR, addedobjs);
l_obj tobecollected = numobjs - g->marked;
//printf("(%ld) -> minor? tobecollected: %ld limit: %ld\n", numobjs, tobecollected, limit);
if (tobecollected > limit) {
atomic2gen(L, g); /* return to generational mode */
setminordebt(g);
Expand Down
2 changes: 1 addition & 1 deletion Source/3rdParty/Lua/llimits.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ typedef signed char ls_byte;
#define L_P2I size_t
#endif

#define point2uint(p) ((unsigned int)((L_P2I)(p) & UINT_MAX))
#define point2uint(p) cast_uint((L_P2I)(p) & UINT_MAX)



Expand Down
11 changes: 11 additions & 0 deletions Source/3rdParty/Lua/lobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,19 @@ typedef union {
/* Value returned for a key not found in a table (absent key) */
#define LUA_VABSTKEY makevariant(LUA_TNIL, 2)

/* Special variant to signal that a fast get is accessing a non-table */
#define LUA_VNOTABLE makevariant(LUA_TNIL, 3)


/* macro to test for (any kind of) nil */
#define ttisnil(v) checktype((v), LUA_TNIL)

/*
** Macro to test the result of a table access. Formally, it should
** distinguish between LUA_VEMPTY/LUA_VABSTKEY/LUA_VNOTABLE and
** other tags. As currently nil is equivalent to LUA_VEMPTY, it is
** simpler to just test whether the value is nil.
*/
#define tagisempty(tag) (novariant(tag) == LUA_TNIL)


Expand Down Expand Up @@ -247,6 +256,8 @@ typedef union {


#define l_isfalse(o) (ttisfalse(o) || ttisnil(o))
#define tagisfalse(t) ((t) == LUA_VFALSE || novariant(t) == LUA_TNIL)



#define setbfvalue(obj) settt_(obj, LUA_VFALSE)
Expand Down
2 changes: 1 addition & 1 deletion Source/3rdParty/Lua/lstate.c
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ LUA_API int lua_closethread (lua_State *L, lua_State *from) {
}


LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud, unsigned int seed) {
LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud, unsigned seed) {
int i;
lua_State *L;
global_State *g;
Expand Down
Loading

0 comments on commit 6f527fd

Please sign in to comment.