diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2023-04-28 10:33:53 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2023-04-28 10:33:53 -0300 |
commit | 460a35cbcb33fbc56f5a658b96a793b9bb8963e9 (patch) | |
tree | 138df91e9dec0544b64bad3334d01ca38d2b7408 | |
parent | 503126fec29117e31d633b81203f887b99040c4a (diff) | |
download | lpeg-460a35cbcb33fbc56f5a658b96a793b9bb8963e9.tar.gz lpeg-460a35cbcb33fbc56f5a658b96a793b9bb8963e9.tar.bz2 lpeg-460a35cbcb33fbc56f5a658b96a793b9bb8963e9.zip |
New type name 'uint' (unsigned int)
-rw-r--r-- | lpcode.c | 2 | ||||
-rw-r--r-- | lptree.c | 2 | ||||
-rw-r--r-- | lptypes.h | 10 | ||||
-rw-r--r-- | lpvm.c | 20 | ||||
-rw-r--r-- | lpvm.h | 2 |
5 files changed, 19 insertions, 17 deletions
@@ -412,7 +412,7 @@ static int nextinstruction (CompileState *compst, int n) { | |||
412 | int size = compst->p->codesize; | 412 | int size = compst->p->codesize; |
413 | int ncode = compst->ncode; | 413 | int ncode = compst->ncode; |
414 | if (ncode >= size - n) { | 414 | if (ncode >= size - n) { |
415 | unsigned int nsize = size + (size >> 1) + n; | 415 | uint nsize = size + (size >> 1) + n; |
416 | if (nsize > INT_MAX) | 416 | if (nsize > INT_MAX) |
417 | luaL_error(compst->L, "code too large"); | 417 | luaL_error(compst->L, "code too large"); |
418 | realloccode(compst->L, compst->p, nsize); | 418 | realloccode(compst->L, compst->p, nsize); |
@@ -736,7 +736,7 @@ static int lp_utfr (lua_State *L) { | |||
736 | lua_Unsigned to = (lua_Unsigned)luaL_checkinteger(L, 2); | 736 | lua_Unsigned to = (lua_Unsigned)luaL_checkinteger(L, 2); |
737 | luaL_argcheck(L, from <= to, 2, "empty range"); | 737 | luaL_argcheck(L, from <= to, 2, "empty range"); |
738 | if (to <= 0x7f) { /* ascii range? */ | 738 | if (to <= 0x7f) { /* ascii range? */ |
739 | unsigned int f; | 739 | uint f; |
740 | byte buff[CHARSETSIZE]; /* code it as a regular charset */ | 740 | byte buff[CHARSETSIZE]; /* code it as a regular charset */ |
741 | clearset(buff); | 741 | clearset(buff); |
742 | for (f = (int)from; f <= to; f++) | 742 | for (f = (int)from; f <= to; f++) |
@@ -83,6 +83,8 @@ typedef size_t lua_Unsigned; | |||
83 | 83 | ||
84 | typedef unsigned char byte; | 84 | typedef unsigned char byte; |
85 | 85 | ||
86 | typedef unsigned int uint; | ||
87 | |||
86 | 88 | ||
87 | #define BITSPERCHAR 8 | 89 | #define BITSPERCHAR 8 |
88 | 90 | ||
@@ -102,7 +104,7 @@ typedef struct Charset { | |||
102 | #define clearset(s) fillset(s,0) | 104 | #define clearset(s) fillset(s,0) |
103 | 105 | ||
104 | /* number of slots needed for 'n' bytes */ | 106 | /* number of slots needed for 'n' bytes */ |
105 | #define bytes2slots(n) (((n) - 1u) / (unsigned int)sizeof(TTree) + 1u) | 107 | #define bytes2slots(n) (((n) - 1u) / (uint)sizeof(TTree) + 1u) |
106 | 108 | ||
107 | /* set 'b' bit in charset 'cs' */ | 109 | /* set 'b' bit in charset 'cs' */ |
108 | #define setchar(cs,b) ((cs)[(b) >> 3] |= (1 << ((b) & 7))) | 110 | #define setchar(cs,b) ((cs)[(b) >> 3] |= (1 << ((b) & 7))) |
@@ -129,8 +131,8 @@ typedef struct Charset { | |||
129 | 131 | ||
130 | 132 | ||
131 | /* size (in instructions) for l bytes (l > 0) */ | 133 | /* size (in instructions) for l bytes (l > 0) */ |
132 | #define instsize(l) ((int)(((l) + (unsigned int)sizeof(Instruction) - 1u) \ | 134 | #define instsize(l) ((int)(((l) + (uint)sizeof(Instruction) - 1u) \ |
133 | / (unsigned int)sizeof(Instruction))) | 135 | / (uint)sizeof(Instruction))) |
134 | 136 | ||
135 | 137 | ||
136 | /* size (in elements) for a ISet instruction */ | 138 | /* size (in elements) for a ISet instruction */ |
@@ -141,7 +143,7 @@ typedef struct Charset { | |||
141 | 143 | ||
142 | 144 | ||
143 | 145 | ||
144 | #define testchar(st,c) ((((unsigned int)(st)[((c) >> 3)]) >> ((c) & 7)) & 1) | 146 | #define testchar(st,c) ((((uint)(st)[((c) >> 3)]) >> ((c) & 7)) & 1) |
145 | 147 | ||
146 | 148 | ||
147 | #endif | 149 | #endif |
@@ -23,10 +23,10 @@ | |||
23 | static const Instruction giveup = {{IGiveup, 0, {0}}}; | 23 | static const Instruction giveup = {{IGiveup, 0, {0}}}; |
24 | 24 | ||
25 | 25 | ||
26 | int charinset (const Instruction *i, const byte *buff, unsigned int c) { | 26 | int charinset (const Instruction *i, const byte *buff, uint c) { |
27 | c -= i->i.aux2.set.offset; | 27 | c -= i->i.aux2.set.offset; |
28 | if (c >= ((unsigned int)i->i.aux2.set.size /* size in instructions... */ | 28 | if (c >= ((uint)i->i.aux2.set.size /* size in instructions... */ |
29 | * (unsigned int)sizeof(Instruction) /* in bytes... */ | 29 | * (uint)sizeof(Instruction) /* in bytes... */ |
30 | * 8u)) /* in bits */ | 30 | * 8u)) /* in bits */ |
31 | return i->i.aux1; /* out of range; return default value */ | 31 | return i->i.aux1; /* out of range; return default value */ |
32 | return testchar(buff, c); | 32 | return testchar(buff, c); |
@@ -37,10 +37,10 @@ int charinset (const Instruction *i, const byte *buff, unsigned int c) { | |||
37 | ** Decode one UTF-8 sequence, returning NULL if byte sequence is invalid. | 37 | ** Decode one UTF-8 sequence, returning NULL if byte sequence is invalid. |
38 | */ | 38 | */ |
39 | static const char *utf8_decode (const char *o, int *val) { | 39 | static const char *utf8_decode (const char *o, int *val) { |
40 | static const unsigned int limits[] = {0xFF, 0x7F, 0x7FF, 0xFFFFu}; | 40 | static const uint limits[] = {0xFF, 0x7F, 0x7FF, 0xFFFFu}; |
41 | const unsigned char *s = (const unsigned char *)o; | 41 | const unsigned char *s = (const unsigned char *)o; |
42 | unsigned int c = s[0]; /* first byte */ | 42 | uint c = s[0]; /* first byte */ |
43 | unsigned int res = 0; /* final result */ | 43 | uint res = 0; /* final result */ |
44 | if (c < 0x80) /* ascii? */ | 44 | if (c < 0x80) /* ascii? */ |
45 | res = c; | 45 | res = c; |
46 | else { | 46 | else { |
@@ -99,7 +99,7 @@ static Capture *growcap (lua_State *L, Capture *capture, int *capsize, | |||
99 | return capture; /* no need to grow array */ | 99 | return capture; /* no need to grow array */ |
100 | else { /* must grow */ | 100 | else { /* must grow */ |
101 | Capture *newc; | 101 | Capture *newc; |
102 | unsigned int newsize = captop + n + 1; /* minimum size needed */ | 102 | uint newsize = captop + n + 1; /* minimum size needed */ |
103 | if (newsize < (MAXNEWSIZE / 3) * 2) | 103 | if (newsize < (MAXNEWSIZE / 3) * 2) |
104 | newsize += newsize / 2; /* 1.5 that size, if not too big */ | 104 | newsize += newsize / 2; /* 1.5 that size, if not too big */ |
105 | else if (newsize < (MAXNEWSIZE / 9) * 8) | 105 | 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, | |||
269 | continue; | 269 | continue; |
270 | } | 270 | } |
271 | case ISet: { | 271 | case ISet: { |
272 | unsigned int c = (byte)*s; | 272 | uint c = (byte)*s; |
273 | if (charinset(p, (p+1)->buff, c) && s < e) | 273 | if (charinset(p, (p+1)->buff, c) && s < e) |
274 | { p += 1 + p->i.aux2.set.size; s++; } | 274 | { p += 1 + p->i.aux2.set.size; s++; } |
275 | else goto fail; | 275 | else goto fail; |
276 | continue; | 276 | continue; |
277 | } | 277 | } |
278 | case ITestSet: { | 278 | case ITestSet: { |
279 | unsigned int c = (byte)*s; | 279 | uint c = (byte)*s; |
280 | if (charinset(p, (p + 2)->buff, c) && s < e) | 280 | if (charinset(p, (p + 2)->buff, c) && s < e) |
281 | p += 2 + p->i.aux2.set.size; | 281 | p += 2 + p->i.aux2.set.size; |
282 | else p += getoffset(p); | 282 | else p += getoffset(p); |
@@ -290,7 +290,7 @@ const char *match (lua_State *L, const char *o, const char *s, const char *e, | |||
290 | } | 290 | } |
291 | case ISpan: { | 291 | case ISpan: { |
292 | for (; s < e; s++) { | 292 | for (; s < e; s++) { |
293 | unsigned int c = (byte)*s; | 293 | uint c = (byte)*s; |
294 | if (!charinset(p, (p+1)->buff, c)) break; | 294 | if (!charinset(p, (p+1)->buff, c)) break; |
295 | } | 295 | } |
296 | p += 1 + p->i.aux2.set.size; | 296 | p += 1 + p->i.aux2.set.size; |
@@ -65,7 +65,7 @@ typedef union Instruction { | |||
65 | #define utf_to(inst) (((inst)->i.aux2.key << 8) | (inst)->i.aux1) | 65 | #define utf_to(inst) (((inst)->i.aux2.key << 8) | (inst)->i.aux1) |
66 | 66 | ||
67 | 67 | ||
68 | int charinset (const Instruction *i, const byte *buff, unsigned int c); | 68 | int charinset (const Instruction *i, const byte *buff, uint c); |
69 | void printpatt (Instruction *p, int n); | 69 | void printpatt (Instruction *p, int n); |
70 | const char *match (lua_State *L, const char *o, const char *s, const char *e, | 70 | const char *match (lua_State *L, const char *o, const char *s, const char *e, |
71 | Instruction *op, Capture *capture, int ptop); | 71 | Instruction *op, Capture *capture, int ptop); |