Skip to content

Commit 8e93872

Browse files
committed
Clean up for one.c compilation.
1 parent 0edd102 commit 8e93872

File tree

4 files changed

+53
-63
lines changed

4 files changed

+53
-63
lines changed

jsbuiltin.c

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "jsi.h"
2+
#include "jslex.h"
23
#include "jscompile.h"
34
#include "jsvalue.h"
45
#include "jsbuiltin.h"
@@ -96,19 +97,6 @@ static int Encode(js_State *J, const char *str, const char *unescaped)
9697
return 1;
9798
}
9899

99-
static inline int ishex(int c)
100-
{
101-
return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F');
102-
}
103-
104-
static inline int tohex(int c)
105-
{
106-
if (c >= '0' && c <= '9') return c - '0';
107-
if (c >= 'a' && c <= 'f') return c - 'a' + 0xA;
108-
if (c >= 'A' && c <= 'F') return c - 'A' + 0xA;
109-
return 0;
110-
}
111-
112100
static int Decode(js_State *J, const char *str, const char *reserved)
113101
{
114102
js_Buffer *sb = NULL;
@@ -123,9 +111,9 @@ static int Decode(js_State *J, const char *str, const char *reserved)
123111
js_urierror(J, "truncated escape sequence");
124112
a = *str++;
125113
b = *str++;
126-
if (!ishex(a) || !ishex(b))
114+
if (!jsY_ishex(a) || !jsY_ishex(b))
127115
js_urierror(J, "invalid escape sequence");
128-
c = tohex(a) << 4 | tohex(b);
116+
c = jsY_tohex(a) << 4 | jsY_tohex(b);
129117
if (!strchr(reserved, c))
130118
sb_putc(&sb, c);
131119
else {

jslex.c

Lines changed: 42 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ int jsY_findword(const char *s, const char **list, int num)
9898
return -1;
9999
}
100100

101-
static inline int findkeyword(js_State *J, const char *s)
101+
static inline int jsY_findkeyword(js_State *J, const char *s)
102102
{
103103
int i = jsY_findword(s, keywords, nelem(keywords));
104104
if (i >= 0) {
@@ -109,44 +109,41 @@ static inline int findkeyword(js_State *J, const char *s)
109109
return TK_IDENTIFIER;
110110
}
111111

112-
static inline int iswhite(int c)
112+
int jsY_iswhite(int c)
113113
{
114114
return c == 0x9 || c == 0xB || c == 0xC || c == 0x20 || c == 0xA0 || c == 0xFEFF;
115115
}
116116

117-
static inline int isnewline(c)
117+
int jsY_isnewline(int c)
118118
{
119119
return c == 0xA || c == 0xD || c == 0x2028 || c == 0x2029;
120120
}
121121

122-
static inline int isidentifierstart(int c)
122+
static inline int jsY_isidentifierstart(int c)
123123
{
124124
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '$' || c == '_' || isalpharune(c);
125125
}
126126

127-
static inline int isidentifierpart(int c)
127+
static inline int jsY_isidentifierpart(int c)
128128
{
129-
return (c >= '0' && c <= '9') || isidentifierstart(c);
129+
return (c >= '0' && c <= '9') || jsY_isidentifierstart(c);
130130
}
131131

132-
static inline int isdec(int c)
132+
static inline int jsY_isdec(int c)
133133
{
134134
return (c >= '0' && c <= '9');
135135
}
136136

137-
static inline int ishex(int c)
137+
int jsY_ishex(int c)
138138
{
139139
return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F');
140140
}
141141

142-
static inline int tohex(int c)
142+
int jsY_tohex(int c)
143143
{
144-
if (c >= '0' && c <= '9')
145-
return c - '0';
146-
if (c >= 'a' && c <= 'f')
147-
return c - 'a' + 0xA;
148-
if (c >= 'A' && c <= 'F')
149-
return c - 'A' + 0xA;
144+
if (c >= '0' && c <= '9') return c - '0';
145+
if (c >= 'a' && c <= 'f') return c - 'a' + 0xA;
146+
if (c >= 'A' && c <= 'F') return c - 'A' + 0xA;
150147
return 0;
151148
}
152149

@@ -162,22 +159,22 @@ static void jsY_next(js_State *J)
162159
/* consume CR LF as one unit */
163160
if (c == '\r' && *J->source == '\n')
164161
++J->source;
165-
if (isnewline(c)) {
162+
if (jsY_isnewline(c)) {
166163
J->line++;
167164
c = '\n';
168165
}
169166
J->lexchar = c;
170167
}
171168

172-
static void unescape(js_State *J)
169+
static void jsY_unescape(js_State *J)
173170
{
174171
if (ACCEPT('\\')) {
175172
if (ACCEPT('u')) {
176173
int x = 0;
177-
if (!ishex(PEEK)) goto error; x |= tohex(PEEK) << 12; NEXT();
178-
if (!ishex(PEEK)) goto error; x |= tohex(PEEK) << 8; NEXT();
179-
if (!ishex(PEEK)) goto error; x |= tohex(PEEK) << 4; NEXT();
180-
if (!ishex(PEEK)) goto error; x |= tohex(PEEK);
174+
if (!jsY_ishex(PEEK)) goto error; x |= jsY_tohex(PEEK) << 12; NEXT();
175+
if (!jsY_ishex(PEEK)) goto error; x |= jsY_tohex(PEEK) << 8; NEXT();
176+
if (!jsY_ishex(PEEK)) goto error; x |= jsY_tohex(PEEK) << 4; NEXT();
177+
if (!jsY_ishex(PEEK)) goto error; x |= jsY_tohex(PEEK);
181178
J->lexchar = x;
182179
return;
183180
}
@@ -235,10 +232,10 @@ static inline int lexcomment(js_State *J)
235232
static inline double lexhex(js_State *J)
236233
{
237234
double n = 0;
238-
if (!ishex(PEEK))
235+
if (!jsY_ishex(PEEK))
239236
jsY_error(J, "malformed hexadecimal number");
240-
while (ishex(PEEK)) {
241-
n = n * 16 + tohex(PEEK);
237+
while (jsY_ishex(PEEK)) {
238+
n = n * 16 + jsY_tohex(PEEK);
242239
NEXT();
243240
}
244241
return n;
@@ -247,9 +244,9 @@ static inline double lexhex(js_State *J)
247244
static inline double lexinteger(js_State *J)
248245
{
249246
double n = 0;
250-
if (!isdec(PEEK))
247+
if (!jsY_isdec(PEEK))
251248
jsY_error(J, "malformed number");
252-
while (isdec(PEEK)) {
249+
while (jsY_isdec(PEEK)) {
253250
n = n * 10 + (PEEK - '0');
254251
NEXT();
255252
}
@@ -260,7 +257,7 @@ static inline double lexfraction(js_State *J)
260257
{
261258
double n = 0;
262259
double d = 1;
263-
while (isdec(PEEK)) {
260+
while (jsY_isdec(PEEK)) {
264261
n = n * 10 + (PEEK - '0');
265262
d = d * 10;
266263
NEXT();
@@ -290,13 +287,13 @@ static inline int lexnumber(js_State *J)
290287
J->number = lexhex(J);
291288
return TK_NUMBER;
292289
}
293-
if (isdec(PEEK))
290+
if (jsY_isdec(PEEK))
294291
jsY_error(J, "number with leading zero");
295292
n = 0;
296293
if (ACCEPT('.'))
297294
n += lexfraction(J);
298295
} else if (ACCEPT('.')) {
299-
if (!isdec(PEEK))
296+
if (!jsY_isdec(PEEK))
300297
return '.';
301298
n = lexfraction(J);
302299
} else {
@@ -311,7 +308,7 @@ static inline int lexnumber(js_State *J)
311308
else if (e > 0)
312309
n *= pow(10, e);
313310

314-
if (isidentifierstart(PEEK))
311+
if (jsY_isidentifierstart(PEEK))
315312
jsY_error(J, "number with letter suffix");
316313

317314
J->number = n;
@@ -330,16 +327,16 @@ static inline int lexescape(js_State *J)
330327
switch (PEEK) {
331328
case 'u':
332329
NEXT();
333-
if (!ishex(PEEK)) return 1; else { x |= tohex(PEEK) << 12; NEXT(); }
334-
if (!ishex(PEEK)) return 1; else { x |= tohex(PEEK) << 8; NEXT(); }
335-
if (!ishex(PEEK)) return 1; else { x |= tohex(PEEK) << 4; NEXT(); }
336-
if (!ishex(PEEK)) return 1; else { x |= tohex(PEEK); NEXT(); }
330+
if (!jsY_ishex(PEEK)) return 1; else { x |= jsY_tohex(PEEK) << 12; NEXT(); }
331+
if (!jsY_ishex(PEEK)) return 1; else { x |= jsY_tohex(PEEK) << 8; NEXT(); }
332+
if (!jsY_ishex(PEEK)) return 1; else { x |= jsY_tohex(PEEK) << 4; NEXT(); }
333+
if (!jsY_ishex(PEEK)) return 1; else { x |= jsY_tohex(PEEK); NEXT(); }
337334
textpush(J, x);
338335
break;
339336
case 'x':
340337
NEXT();
341-
if (!ishex(PEEK)) return 1; else { x |= tohex(PEEK) << 4; NEXT(); }
342-
if (!ishex(PEEK)) return 1; else { x |= tohex(PEEK); NEXT(); }
338+
if (!jsY_ishex(PEEK)) return 1; else { x |= jsY_tohex(PEEK) << 4; NEXT(); }
339+
if (!jsY_ishex(PEEK)) return 1; else { x |= jsY_tohex(PEEK); NEXT(); }
343340
textpush(J, x);
344341
break;
345342
case '0': textpush(J, 0); NEXT(); break;
@@ -436,7 +433,7 @@ static int lexregexp(js_State *J)
436433
/* regexp flags */
437434
g = i = m = 0;
438435

439-
while (isidentifierpart(PEEK)) {
436+
while (jsY_isidentifierpart(PEEK)) {
440437
if (ACCEPT('g')) ++g;
441438
else if (ACCEPT('i')) ++i;
442439
else if (ACCEPT('m')) ++m;
@@ -475,7 +472,7 @@ static int jsY_lexx(js_State *J)
475472
while (1) {
476473
J->lexline = J->line; /* save location of beginning of token */
477474

478-
while (iswhite(PEEK))
475+
while (jsY_iswhite(PEEK))
479476
NEXT();
480477

481478
if (ACCEPT('\n')) {
@@ -626,22 +623,22 @@ static int jsY_lexx(js_State *J)
626623
}
627624

628625
/* Handle \uXXXX escapes in identifiers */
629-
unescape(J);
630-
if (isidentifierstart(PEEK)) {
626+
jsY_unescape(J);
627+
if (jsY_isidentifierstart(PEEK)) {
631628
textinit(J);
632629
textpush(J, PEEK);
633630

634631
NEXT();
635-
unescape(J);
636-
while (isidentifierpart(PEEK)) {
632+
jsY_unescape(J);
633+
while (jsY_isidentifierpart(PEEK)) {
637634
textpush(J, PEEK);
638635
NEXT();
639-
unescape(J);
636+
jsY_unescape(J);
640637
}
641638

642639
textend(J);
643640

644-
return findkeyword(J, J->lexbuf.text);
641+
return jsY_findkeyword(J, J->lexbuf.text);
645642
}
646643

647644
if (PEEK >= 0x20 && PEEK <= 0x7E)
@@ -669,7 +666,7 @@ int jsY_lexjson(js_State *J)
669666
while (1) {
670667
J->lexline = J->line; /* save location of beginning of token */
671668

672-
while (iswhite(PEEK) || PEEK == '\n')
669+
while (jsY_iswhite(PEEK) || PEEK == '\n')
673670
NEXT();
674671

675672
if (PEEK >= '0' && PEEK <= '9') {

jslex.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ enum
6666
TK_WITH,
6767
};
6868

69+
int jsY_iswhite(int c);
70+
int jsY_isnewline(int c);
71+
int jsY_ishex(int c);
72+
int jsY_tohex(int c);
73+
6974
const char *jsY_tokenstring(int token);
7075
int jsY_findword(const char *s, const char **list, int num);
7176

jsstring.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ static int Sp_toUpperCase(js_State *J, int argc)
276276
return 1;
277277
}
278278

279-
static int iswhite(int c)
279+
static int istrim(int c)
280280
{
281281
return c == 0x9 || c == 0xB || c == 0xC || c == 0x20 || c == 0xA0 || c == 0xFEFF ||
282282
c == 0xA || c == 0xD || c == 0x2028 || c == 0x2029;
@@ -286,10 +286,10 @@ static int Sp_trim(js_State *J, int argc)
286286
{
287287
const char *s, *e;
288288
s = js_tostring(J, 0);
289-
while (iswhite(*s))
289+
while (istrim(*s))
290290
++s;
291291
e = s + strlen(s);
292-
while (e > s && iswhite(e[-1]))
292+
while (e > s && istrim(e[-1]))
293293
--e;
294294
js_pushlstring(J, s, e - s);
295295
return 1;

0 commit comments

Comments
 (0)