Skip to content

Commit d5a0d23

Browse files
feat: update from origin to latest 5.5.0 changes
1 parent 10d42c6 commit d5a0d23

44 files changed

Lines changed: 942 additions & 601 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

include/lauxlib.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ LUALIB_API int (luaL_checkoption) (lua_State *L, int arg, const char *def,
8181
LUALIB_API int (luaL_fileresult) (lua_State *L, int stat, const char *fname);
8282
LUALIB_API int (luaL_execresult) (lua_State *L, int stat);
8383

84+
LUALIB_API void *luaL_alloc (void *ud, void *ptr, size_t osize,
85+
size_t nsize);
86+
8487

8588
/* predefined references */
8689
#define LUA_NOREF (-2)

include/lcode.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,12 @@ LUAI_FUNC int luaK_codevABCk (FuncState *fs, OpCode o, int A, int B, int C,
6868
LUAI_FUNC int luaK_exp2const (FuncState *fs, const expdesc *e, TValue *v);
6969
LUAI_FUNC void luaK_fixline (FuncState *fs, int line);
7070
LUAI_FUNC void luaK_nil (FuncState *fs, int from, int n);
71+
LUAI_FUNC void luaK_codecheckglobal (FuncState *fs, expdesc *var, int k,
72+
int line);
7173
LUAI_FUNC void luaK_reserveregs (FuncState *fs, int n);
7274
LUAI_FUNC void luaK_checkstack (FuncState *fs, int n);
7375
LUAI_FUNC void luaK_int (FuncState *fs, int reg, lua_Integer n);
76+
LUAI_FUNC void luaK_vapar2local (FuncState *fs, expdesc *var);
7477
LUAI_FUNC void luaK_dischargevars (FuncState *fs, expdesc *e);
7578
LUAI_FUNC int luaK_exp2anyreg (FuncState *fs, expdesc *e);
7679
LUAI_FUNC void luaK_exp2anyregup (FuncState *fs, expdesc *e);
@@ -79,7 +82,6 @@ LUAI_FUNC void luaK_exp2val (FuncState *fs, expdesc *e);
7982
LUAI_FUNC void luaK_self (FuncState *fs, expdesc *e, expdesc *key);
8083
LUAI_FUNC void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k);
8184
LUAI_FUNC void luaK_goiftrue (FuncState *fs, expdesc *e);
82-
LUAI_FUNC void luaK_goiffalse (FuncState *fs, expdesc *e);
8385
LUAI_FUNC void luaK_storevar (FuncState *fs, expdesc *var, expdesc *e);
8486
LUAI_FUNC void luaK_setreturns (FuncState *fs, expdesc *e, int nresults);
8587
LUAI_FUNC void luaK_setoneret (FuncState *fs, expdesc *e);

include/ldebug.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ LUAI_FUNC l_noret luaG_tointerror (lua_State *L, const TValue *p1,
5353
const TValue *p2);
5454
LUAI_FUNC l_noret luaG_ordererror (lua_State *L, const TValue *p1,
5555
const TValue *p2);
56+
LUAI_FUNC l_noret luaG_errnnil (lua_State *L, LClosure *cl, int k);
5657
LUAI_FUNC l_noret luaG_runerror (lua_State *L, const char *fmt, ...);
5758
LUAI_FUNC const char *luaG_addinfo (lua_State *L, const char *msg,
5859
TString *src, int line);

include/ljumptab.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ static const void *const disptab[NUM_OPCODES] = {
2121
#if 0
2222
** you can update the following list with this command:
2323
**
24-
** sed -n '/^OP_/\!d; s/OP_/\&\&L_OP_/ ; s/,.*/,/ ; s/\/.*// ; p' lopcodes.h
24+
** sed -n '/^OP_/!d; s/OP_/\&\&L_OP_/ ; s/,.*/,/ ; s/\/.*// ; p' lopcodes.h
2525
**
2626
#endif
2727

@@ -57,8 +57,8 @@ static const void *const disptab[NUM_OPCODES] = {
5757
&&L_OP_BANDK,
5858
&&L_OP_BORK,
5959
&&L_OP_BXORK,
60-
&&L_OP_SHRI,
6160
&&L_OP_SHLI,
61+
&&L_OP_SHRI,
6262
&&L_OP_ADD,
6363
&&L_OP_SUB,
6464
&&L_OP_MUL,
@@ -106,6 +106,8 @@ static const void *const disptab[NUM_OPCODES] = {
106106
&&L_OP_SETLIST,
107107
&&L_OP_CLOSURE,
108108
&&L_OP_VARARG,
109+
&&L_OP_GETVARG,
110+
&&L_OP_ERRNNIL,
109111
&&L_OP_VARARGPREP,
110112
&&L_OP_EXTRAARG
111113

include/llimits.h

Lines changed: 51 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
/*
2121
** 'l_mem' is a signed integer big enough to count the total memory
2222
** used by Lua. (It is signed due to the use of debt in several
23-
** computations.) Usually, 'ptrdiff_t' should work, but we use 'long'
24-
** for 16-bit machines.
23+
** computations.) 'lu_mem' is a corresponding unsigned type. Usually,
24+
** 'ptrdiff_t' should work, but we use 'long' for 16-bit machines.
2525
*/
2626
#if defined(LUAI_MEM) /* { external definitions? */
2727
typedef LUAI_MEM l_mem;
@@ -59,13 +59,6 @@ typedef lu_byte TStatus;
5959
#define MAX_SIZE (sizeof(size_t) < sizeof(lua_Integer) ? MAX_SIZET \
6060
: cast_sizet(LUA_MAXINTEGER))
6161

62-
/*
63-
** floor of the log2 of the maximum signed value for integral type 't'.
64-
** (That is, maximum 'n' such that '2^n' fits in the given signed type.)
65-
*/
66-
#define log2maxs(t) (l_numbits(t) - 2)
67-
68-
6962
/*
7063
** test whether an unsigned value is a power of 2 (or zero)
7164
*/
@@ -287,6 +280,55 @@ typedef unsigned long l_uint32;
287280
#endif
288281

289282

283+
284+
/*
285+
** lua_numbertointeger converts a float number with an integral value
286+
** to an integer, or returns 0 if the float is not within the range of
287+
** a lua_Integer. (The range comparisons are tricky because of
288+
** rounding. The tests here assume a two-complement representation,
289+
** where MININTEGER always has an exact representation as a float;
290+
** MAXINTEGER may not have one, and therefore its conversion to float
291+
** may have an ill-defined value.)
292+
*/
293+
#define lua_numbertointeger(n,p) \
294+
((n) >= (LUA_NUMBER)(LUA_MININTEGER) && \
295+
(n) < -(LUA_NUMBER)(LUA_MININTEGER) && \
296+
(*(p) = (LUA_INTEGER)(n), 1))
297+
298+
299+
300+
/*
301+
** LUAI_FUNC is a mark for all extern functions that are not to be
302+
** exported to outside modules.
303+
** LUAI_DDEF and LUAI_DDEC are marks for all extern (const) variables,
304+
** none of which to be exported to outside modules (LUAI_DDEF for
305+
** definitions and LUAI_DDEC for declarations).
306+
** Elf and MACH/gcc (versions 3.2 and later) mark them as "hidden" to
307+
** optimize access when Lua is compiled as a shared library. Not all elf
308+
** targets support this attribute. Unfortunately, gcc does not offer
309+
** a way to check whether the target offers that support, and those
310+
** without support give a warning about it. To avoid these warnings,
311+
** change to the default definition.
312+
*/
313+
#if !defined(LUAI_FUNC)
314+
315+
#if defined(__GNUC__) && ((__GNUC__*100 + __GNUC_MINOR__) >= 302) && \
316+
(defined(__ELF__) || defined(__MACH__))
317+
#define LUAI_FUNC __attribute__((visibility("internal"))) extern
318+
#else
319+
#define LUAI_FUNC extern
320+
#endif
321+
322+
#define LUAI_DDEC(dec) LUAI_FUNC dec
323+
#define LUAI_DDEF /* empty */
324+
325+
#endif
326+
327+
328+
/* Give these macros simpler names for internal use */
329+
#define l_likely(x) luai_likely(x)
330+
#define l_unlikely(x) luai_unlikely(x)
331+
290332
/*
291333
** {==================================================================
292334
** "Abstraction Layer" for basic report of messages and errors

include/lobject.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,7 @@ typedef struct TString {
418418

419419

420420
#define strisshr(ts) ((ts)->shrlen >= 0)
421+
#define isextstr(ts) (ttislngstring(ts) && tsvalue(ts)->shrlen != LSTRREG)
421422

422423

423424
/*
@@ -582,8 +583,10 @@ typedef struct AbsLineInfo {
582583
/*
583584
** Flags in Prototypes
584585
*/
585-
#define PF_ISVARARG 1
586-
#define PF_FIXED 2 /* prototype has parts in fixed memory */
586+
#define PF_ISVARARG 1 /* function is vararg */
587+
#define PF_VAVAR 2 /* function has vararg parameter */
588+
#define PF_VATAB 4 /* function has vararg table */
589+
#define PF_FIXED 8 /* prototype has parts in fixed memory */
587590

588591

589592
/*

include/lopcodes.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,8 @@ OP_BANDK,/* A B C R[A] := R[B] & K[C]:integer */
272272
OP_BORK,/* A B C R[A] := R[B] | K[C]:integer */
273273
OP_BXORK,/* A B C R[A] := R[B] ~ K[C]:integer */
274274

275-
OP_SHRI,/* A B sC R[A] := R[B] >> sC */
276275
OP_SHLI,/* A B sC R[A] := sC << R[B] */
276+
OP_SHRI,/* A B sC R[A] := R[B] >> sC */
277277

278278
OP_ADD,/* A B C R[A] := R[B] + R[C] */
279279
OP_SUB,/* A B C R[A] := R[B] - R[C] */
@@ -338,7 +338,11 @@ OP_CLOSURE,/* A Bx R[A] := closure(KPROTO[Bx]) */
338338

339339
OP_VARARG,/* A C R[A], R[A+1], ..., R[A+C-2] = vararg */
340340

341-
OP_VARARGPREP,/*A (adjust vararg parameters) */
341+
OP_GETVARG, /* A B C R[A] := R[B][R[C]], R[B] is vararg parameter */
342+
343+
OP_ERRNNIL,/* A Bx raise error if R[A] ~= nil (K[Bx] is global name)*/
344+
345+
OP_VARARGPREP,/* (adjust vararg parameters) */
342346

343347
OP_EXTRAARG/* Ax extra (larger) argument for previous opcode */
344348
} OpCode;

include/lopnames.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ static const char *const opnames[] = {
4545
"BANDK",
4646
"BORK",
4747
"BXORK",
48-
"SHRI",
4948
"SHLI",
49+
"SHRI",
5050
"ADD",
5151
"SUB",
5252
"MUL",
@@ -94,6 +94,8 @@ static const char *const opnames[] = {
9494
"SETLIST",
9595
"CLOSURE",
9696
"VARARG",
97+
"GETVARG",
98+
"ERRNNIL",
9799
"VARARGPREP",
98100
"EXTRAARG",
99101
NULL

include/lparser.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ typedef enum {
3737
info = result register */
3838
VLOCAL, /* local variable; var.ridx = register index;
3939
var.vidx = relative index in 'actvar.arr' */
40+
VVARGVAR, /* vararg parameter; var.ridx = register index;
41+
var.vidx = relative index in 'actvar.arr' */
4042
VGLOBAL, /* global variable;
4143
info = relative index in 'actvar.arr' (or -1 for
4244
implicit declaration) */
@@ -49,6 +51,8 @@ typedef enum {
4951
ind.ro = true if it represents a read-only global;
5052
ind.keystr = if key is a string, index in 'k' of that string;
5153
-1 if key is not a string */
54+
VVARGIND, /* indexed vararg parameter;
55+
ind.* as in VINDEXED */
5256
VINDEXUP, /* indexed upvalue;
5357
ind.idx = key's K index;
5458
ind.* as in VINDEXED */
@@ -97,10 +101,11 @@ typedef struct expdesc {
97101
/* kinds of variables */
98102
#define VDKREG 0 /* regular local */
99103
#define RDKCONST 1 /* local constant */
100-
#define RDKTOCLOSE 2 /* to-be-closed */
101-
#define RDKCTC 3 /* local compile-time constant */
102-
#define GDKREG 4 /* regular global */
103-
#define GDKCONST 5 /* global constant */
104+
#define RDKVAVAR 2 /* vararg parameter */
105+
#define RDKTOCLOSE 3 /* to-be-closed */
106+
#define RDKCTC 4 /* local compile-time constant */
107+
#define GDKREG 5 /* regular global */
108+
#define GDKCONST 6 /* global constant */
104109

105110
/* variables that live in registers */
106111
#define varinreg(v) ((v)->vd.kind <= RDKTOCLOSE)

include/lstate.h

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ typedef struct CallInfo CallInfo;
8585
** they must be visited again at the end of the cycle), but they are
8686
** marked black because assignments to them must activate barriers (to
8787
** move them back to TOUCHED1).
88-
** - Open upvales are kept gray to avoid barriers, but they stay out
88+
** - Open upvalues are kept gray to avoid barriers, but they stay out
8989
** of gray lists. (They don't even have a 'gclist' field.)
9090
*/
9191

@@ -232,7 +232,7 @@ struct CallInfo {
232232
/* call is running a C function (still in first 16 bits) */
233233
#define CIST_C (1u << (CIST_RECST + 3))
234234
/* call is on a fresh "luaV_execute" frame */
235-
#define CIST_FRESH cast(l_uint32, CIST_C << 1)
235+
#define CIST_FRESH (cast(l_uint32, CIST_C) << 1)
236236
/* function is closing tbc variables */
237237
#define CIST_CLSRET (CIST_FRESH << 1)
238238
/* function has tbc variables to close */
@@ -249,10 +249,6 @@ struct CallInfo {
249249
#define CIST_HOOKYIELD (CIST_TAIL << 1)
250250
/* function "called" a finalizer */
251251
#define CIST_FIN (CIST_HOOKYIELD << 1)
252-
#if defined(LUA_COMPAT_LT_LE)
253-
/* using __lt for __le */
254-
#define CIST_LEQ (CIST_FIN << 1)
255-
#endif
256252

257253

258254
#define get_nresults(cs) (cast_int((cs) & CIST_NRESULTS) - 1)
@@ -430,9 +426,9 @@ union GCUnion {
430426

431427
/*
432428
** macro to convert a Lua object into a GCObject
433-
** (The access to 'tt' tries to ensure that 'v' is actually a Lua object.)
434429
*/
435-
#define obj2gco(v) check_exp((v)->tt >= LUA_TSTRING, &(cast_u(v)->gc))
430+
#define obj2gco(v) \
431+
check_exp(novariant((v)->tt) >= LUA_TSTRING, &(cast_u(v)->gc))
436432

437433

438434
/* actual number of total memory allocated */

0 commit comments

Comments
 (0)