From 460a35cbcb33fbc56f5a658b96a793b9bb8963e9 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Fri, 28 Apr 2023 10:33:53 -0300 Subject: New type name 'uint' (unsigned int) --- lpcode.c | 2 +- lptree.c | 2 +- lptypes.h | 10 ++++++---- lpvm.c | 20 ++++++++++---------- lpvm.h | 2 +- 5 files changed, 19 insertions(+), 17 deletions(-) diff --git a/lpcode.c b/lpcode.c index b68f32d..9d7d0eb 100644 --- a/lpcode.c +++ b/lpcode.c @@ -412,7 +412,7 @@ static int nextinstruction (CompileState *compst, int n) { int size = compst->p->codesize; int ncode = compst->ncode; if (ncode >= size - n) { - unsigned int nsize = size + (size >> 1) + n; + uint nsize = size + (size >> 1) + n; if (nsize > INT_MAX) luaL_error(compst->L, "code too large"); realloccode(compst->L, compst->p, nsize); diff --git a/lptree.c b/lptree.c index ff5cb9d..dcee27e 100644 --- a/lptree.c +++ b/lptree.c @@ -736,7 +736,7 @@ static int lp_utfr (lua_State *L) { lua_Unsigned to = (lua_Unsigned)luaL_checkinteger(L, 2); luaL_argcheck(L, from <= to, 2, "empty range"); if (to <= 0x7f) { /* ascii range? */ - unsigned int f; + uint f; byte buff[CHARSETSIZE]; /* code it as a regular charset */ clearset(buff); for (f = (int)from; f <= to; f++) diff --git a/lptypes.h b/lptypes.h index e10d88b..3f860b9 100644 --- a/lptypes.h +++ b/lptypes.h @@ -83,6 +83,8 @@ typedef size_t lua_Unsigned; typedef unsigned char byte; +typedef unsigned int uint; + #define BITSPERCHAR 8 @@ -102,7 +104,7 @@ typedef struct Charset { #define clearset(s) fillset(s,0) /* number of slots needed for 'n' bytes */ -#define bytes2slots(n) (((n) - 1u) / (unsigned int)sizeof(TTree) + 1u) +#define bytes2slots(n) (((n) - 1u) / (uint)sizeof(TTree) + 1u) /* set 'b' bit in charset 'cs' */ #define setchar(cs,b) ((cs)[(b) >> 3] |= (1 << ((b) & 7))) @@ -129,8 +131,8 @@ typedef struct Charset { /* size (in instructions) for l bytes (l > 0) */ -#define instsize(l) ((int)(((l) + (unsigned int)sizeof(Instruction) - 1u) \ - / (unsigned int)sizeof(Instruction))) +#define instsize(l) ((int)(((l) + (uint)sizeof(Instruction) - 1u) \ + / (uint)sizeof(Instruction))) /* size (in elements) for a ISet instruction */ @@ -141,7 +143,7 @@ typedef struct Charset { -#define testchar(st,c) ((((unsigned int)(st)[((c) >> 3)]) >> ((c) & 7)) & 1) +#define testchar(st,c) ((((uint)(st)[((c) >> 3)]) >> ((c) & 7)) & 1) #endif diff --git a/lpvm.c b/lpvm.c index 14e7270..e6f7dac 100644 --- a/lpvm.c +++ b/lpvm.c @@ -23,10 +23,10 @@ static const Instruction giveup = {{IGiveup, 0, {0}}}; -int charinset (const Instruction *i, const byte *buff, unsigned int c) { +int charinset (const Instruction *i, const byte *buff, uint c) { c -= i->i.aux2.set.offset; - if (c >= ((unsigned int)i->i.aux2.set.size /* size in instructions... */ - * (unsigned int)sizeof(Instruction) /* in bytes... */ + if (c >= ((uint)i->i.aux2.set.size /* size in instructions... */ + * (uint)sizeof(Instruction) /* in bytes... */ * 8u)) /* in bits */ return i->i.aux1; /* out of range; return default value */ return testchar(buff, c); @@ -37,10 +37,10 @@ int charinset (const Instruction *i, const byte *buff, unsigned int c) { ** Decode one UTF-8 sequence, returning NULL if byte sequence is invalid. */ static const char *utf8_decode (const char *o, int *val) { - static const unsigned int limits[] = {0xFF, 0x7F, 0x7FF, 0xFFFFu}; + static const uint limits[] = {0xFF, 0x7F, 0x7FF, 0xFFFFu}; const unsigned char *s = (const unsigned char *)o; - unsigned int c = s[0]; /* first byte */ - unsigned int res = 0; /* final result */ + uint c = s[0]; /* first byte */ + uint res = 0; /* final result */ if (c < 0x80) /* ascii? */ res = c; else { @@ -99,7 +99,7 @@ static Capture *growcap (lua_State *L, Capture *capture, int *capsize, return capture; /* no need to grow array */ else { /* must grow */ Capture *newc; - unsigned int newsize = captop + n + 1; /* minimum size needed */ + uint newsize = captop + n + 1; /* minimum size needed */ if (newsize < (MAXNEWSIZE / 3) * 2) newsize += newsize / 2; /* 1.5 that size, if not too big */ else if (newsize < (MAXNEWSIZE / 9) * 8) @@ -269,14 +269,14 @@ const char *match (lua_State *L, const char *o, const char *s, const char *e, continue; } case ISet: { - unsigned int c = (byte)*s; + uint c = (byte)*s; if (charinset(p, (p+1)->buff, c) && s < e) { p += 1 + p->i.aux2.set.size; s++; } else goto fail; continue; } case ITestSet: { - unsigned int c = (byte)*s; + uint c = (byte)*s; if (charinset(p, (p + 2)->buff, c) && s < e) p += 2 + p->i.aux2.set.size; else p += getoffset(p); @@ -290,7 +290,7 @@ const char *match (lua_State *L, const char *o, const char *s, const char *e, } case ISpan: { for (; s < e; s++) { - unsigned int c = (byte)*s; + uint c = (byte)*s; if (!charinset(p, (p+1)->buff, c)) break; } p += 1 + p->i.aux2.set.size; diff --git a/lpvm.h b/lpvm.h index 86114e0..a64d577 100644 --- a/lpvm.h +++ b/lpvm.h @@ -65,7 +65,7 @@ typedef union Instruction { #define utf_to(inst) (((inst)->i.aux2.key << 8) | (inst)->i.aux1) -int charinset (const Instruction *i, const byte *buff, unsigned int c); +int charinset (const Instruction *i, const byte *buff, uint c); void printpatt (Instruction *p, int n); const char *match (lua_State *L, const char *o, const char *s, const char *e, Instruction *op, Capture *capture, int ptop); -- cgit v1.2.3-55-g6feb