ref: 8e938724ff805a6bfe4a8dcc01a6b1c175a6438c
parent: 0edd10268310a9bfbd6bd0791a4558a17cc338e1
author: Tor Andersson <[email protected]>
date: Tue Feb 11 08:42:25 EST 2014
Clean up for one.c compilation.
--- a/jsbuiltin.c
+++ b/jsbuiltin.c
@@ -1,4 +1,5 @@
#include "jsi.h"
+#include "jslex.h"
#include "jscompile.h"
#include "jsvalue.h"
#include "jsbuiltin.h"
@@ -96,19 +97,6 @@
return 1;
}
-static inline int ishex(int c)
-{
- return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F');
-}
-
-static inline int tohex(int c)
-{
- if (c >= '0' && c <= '9') return c - '0';
- if (c >= 'a' && c <= 'f') return c - 'a' + 0xA;
- if (c >= 'A' && c <= 'F') return c - 'A' + 0xA;
- return 0;
-}
-
static int Decode(js_State *J, const char *str, const char *reserved)
{
js_Buffer *sb = NULL;
@@ -123,9 +111,9 @@
js_urierror(J, "truncated escape sequence");
a = *str++;
b = *str++;
- if (!ishex(a) || !ishex(b))
+ if (!jsY_ishex(a) || !jsY_ishex(b))
js_urierror(J, "invalid escape sequence");
- c = tohex(a) << 4 | tohex(b);
+ c = jsY_tohex(a) << 4 | jsY_tohex(b);
if (!strchr(reserved, c))
sb_putc(&sb, c);
else {
--- a/jslex.c
+++ b/jslex.c
@@ -98,7 +98,7 @@
return -1;
}
-static inline int findkeyword(js_State *J, const char *s)
+static inline int jsY_findkeyword(js_State *J, const char *s)
{
int i = jsY_findword(s, keywords, nelem(keywords));
if (i >= 0) {
@@ -109,44 +109,41 @@
return TK_IDENTIFIER;
}
-static inline int iswhite(int c)
+int jsY_iswhite(int c)
{
return c == 0x9 || c == 0xB || c == 0xC || c == 0x20 || c == 0xA0 || c == 0xFEFF;
}
-static inline int isnewline(c)
+int jsY_isnewline(int c)
{
return c == 0xA || c == 0xD || c == 0x2028 || c == 0x2029;
}
-static inline int isidentifierstart(int c)
+static inline int jsY_isidentifierstart(int c)
{
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '$' || c == '_' || isalpharune(c);
}
-static inline int isidentifierpart(int c)
+static inline int jsY_isidentifierpart(int c)
{
- return (c >= '0' && c <= '9') || isidentifierstart(c);
+ return (c >= '0' && c <= '9') || jsY_isidentifierstart(c);
}
-static inline int isdec(int c)
+static inline int jsY_isdec(int c)
{
return (c >= '0' && c <= '9');
}
-static inline int ishex(int c)
+int jsY_ishex(int c)
{
return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F');
}
-static inline int tohex(int c)
+int jsY_tohex(int c)
{
- if (c >= '0' && c <= '9')
- return c - '0';
- if (c >= 'a' && c <= 'f')
- return c - 'a' + 0xA;
- if (c >= 'A' && c <= 'F')
- return c - 'A' + 0xA;
+ if (c >= '0' && c <= '9') return c - '0';
+ if (c >= 'a' && c <= 'f') return c - 'a' + 0xA;
+ if (c >= 'A' && c <= 'F') return c - 'A' + 0xA;
return 0;
}
@@ -162,7 +159,7 @@
/* consume CR LF as one unit */
if (c == '\r' && *J->source == '\n')
++J->source;
- if (isnewline(c)) {
+ if (jsY_isnewline(c)) {
J->line++;
c = '\n';
}
@@ -169,15 +166,15 @@
J->lexchar = c;
}
-static void unescape(js_State *J)
+static void jsY_unescape(js_State *J)
{
if (ACCEPT('\\')) {
if (ACCEPT('u')) {
int x = 0;
- if (!ishex(PEEK)) goto error; x |= tohex(PEEK) << 12; NEXT();
- if (!ishex(PEEK)) goto error; x |= tohex(PEEK) << 8; NEXT();
- if (!ishex(PEEK)) goto error; x |= tohex(PEEK) << 4; NEXT();
- if (!ishex(PEEK)) goto error; x |= tohex(PEEK);
+ if (!jsY_ishex(PEEK)) goto error; x |= jsY_tohex(PEEK) << 12; NEXT();
+ if (!jsY_ishex(PEEK)) goto error; x |= jsY_tohex(PEEK) << 8; NEXT();
+ if (!jsY_ishex(PEEK)) goto error; x |= jsY_tohex(PEEK) << 4; NEXT();
+ if (!jsY_ishex(PEEK)) goto error; x |= jsY_tohex(PEEK);
J->lexchar = x;
return;
}
@@ -235,10 +232,10 @@
static inline double lexhex(js_State *J)
{
double n = 0;
- if (!ishex(PEEK))
+ if (!jsY_ishex(PEEK))
jsY_error(J, "malformed hexadecimal number");
- while (ishex(PEEK)) {
- n = n * 16 + tohex(PEEK);
+ while (jsY_ishex(PEEK)) {
+ n = n * 16 + jsY_tohex(PEEK);
NEXT();
}
return n;
@@ -247,9 +244,9 @@
static inline double lexinteger(js_State *J)
{
double n = 0;
- if (!isdec(PEEK))
+ if (!jsY_isdec(PEEK))
jsY_error(J, "malformed number");
- while (isdec(PEEK)) {
+ while (jsY_isdec(PEEK)) {
n = n * 10 + (PEEK - '0');
NEXT();
}
@@ -260,7 +257,7 @@
{
double n = 0;
double d = 1;
- while (isdec(PEEK)) {
+ while (jsY_isdec(PEEK)) {
n = n * 10 + (PEEK - '0');
d = d * 10;
NEXT();
@@ -290,13 +287,13 @@
J->number = lexhex(J);
return TK_NUMBER;
}
- if (isdec(PEEK))
+ if (jsY_isdec(PEEK))
jsY_error(J, "number with leading zero");
n = 0;
if (ACCEPT('.'))
n += lexfraction(J);
} else if (ACCEPT('.')) {
- if (!isdec(PEEK))
+ if (!jsY_isdec(PEEK))
return '.';
n = lexfraction(J);
} else {
@@ -311,7 +308,7 @@
else if (e > 0)
n *= pow(10, e);
- if (isidentifierstart(PEEK))
+ if (jsY_isidentifierstart(PEEK))
jsY_error(J, "number with letter suffix");
J->number = n;
@@ -330,16 +327,16 @@
switch (PEEK) {
case 'u':
NEXT();
- if (!ishex(PEEK)) return 1; else { x |= tohex(PEEK) << 12; NEXT(); }
- if (!ishex(PEEK)) return 1; else { x |= tohex(PEEK) << 8; NEXT(); }
- if (!ishex(PEEK)) return 1; else { x |= tohex(PEEK) << 4; NEXT(); }
- if (!ishex(PEEK)) return 1; else { x |= tohex(PEEK); NEXT(); }
+ if (!jsY_ishex(PEEK)) return 1; else { x |= jsY_tohex(PEEK) << 12; NEXT(); }
+ if (!jsY_ishex(PEEK)) return 1; else { x |= jsY_tohex(PEEK) << 8; NEXT(); }
+ if (!jsY_ishex(PEEK)) return 1; else { x |= jsY_tohex(PEEK) << 4; NEXT(); }
+ if (!jsY_ishex(PEEK)) return 1; else { x |= jsY_tohex(PEEK); NEXT(); }
textpush(J, x);
break;
case 'x':
NEXT();
- if (!ishex(PEEK)) return 1; else { x |= tohex(PEEK) << 4; NEXT(); }
- if (!ishex(PEEK)) return 1; else { x |= tohex(PEEK); NEXT(); }
+ if (!jsY_ishex(PEEK)) return 1; else { x |= jsY_tohex(PEEK) << 4; NEXT(); }
+ if (!jsY_ishex(PEEK)) return 1; else { x |= jsY_tohex(PEEK); NEXT(); }
textpush(J, x);
break;
case '0': textpush(J, 0); NEXT(); break;
@@ -436,7 +433,7 @@
/* regexp flags */
g = i = m = 0;
- while (isidentifierpart(PEEK)) {
+ while (jsY_isidentifierpart(PEEK)) {
if (ACCEPT('g')) ++g;
else if (ACCEPT('i')) ++i;
else if (ACCEPT('m')) ++m;
@@ -475,7 +472,7 @@
while (1) {
J->lexline = J->line; /* save location of beginning of token */
- while (iswhite(PEEK))
+ while (jsY_iswhite(PEEK))
NEXT();
if (ACCEPT('\n')) {
@@ -626,22 +623,22 @@
}
/* Handle \uXXXX escapes in identifiers */
- unescape(J);
- if (isidentifierstart(PEEK)) {
+ jsY_unescape(J);
+ if (jsY_isidentifierstart(PEEK)) {
textinit(J);
textpush(J, PEEK);
NEXT();
- unescape(J);
- while (isidentifierpart(PEEK)) {
+ jsY_unescape(J);
+ while (jsY_isidentifierpart(PEEK)) {
textpush(J, PEEK);
NEXT();
- unescape(J);
+ jsY_unescape(J);
}
textend(J);
- return findkeyword(J, J->lexbuf.text);
+ return jsY_findkeyword(J, J->lexbuf.text);
}
if (PEEK >= 0x20 && PEEK <= 0x7E)
@@ -669,7 +666,7 @@
while (1) {
J->lexline = J->line; /* save location of beginning of token */
- while (iswhite(PEEK) || PEEK == '\n')
+ while (jsY_iswhite(PEEK) || PEEK == '\n')
NEXT();
if (PEEK >= '0' && PEEK <= '9') {
--- a/jslex.h
+++ b/jslex.h
@@ -66,6 +66,11 @@
TK_WITH,
};
+int jsY_iswhite(int c);
+int jsY_isnewline(int c);
+int jsY_ishex(int c);
+int jsY_tohex(int c);
+
const char *jsY_tokenstring(int token);
int jsY_findword(const char *s, const char **list, int num);
--- a/jsstring.c
+++ b/jsstring.c
@@ -276,7 +276,7 @@
return 1;
}
-static int iswhite(int c)
+static int istrim(int c)
{
return c == 0x9 || c == 0xB || c == 0xC || c == 0x20 || c == 0xA0 || c == 0xFEFF ||
c == 0xA || c == 0xD || c == 0x2028 || c == 0x2029;
@@ -286,10 +286,10 @@
{
const char *s, *e;
s = js_tostring(J, 0);
- while (iswhite(*s))
+ while (istrim(*s))
++s;
e = s + strlen(s);
- while (e > s && iswhite(e[-1]))
+ while (e > s && istrim(e[-1]))
--e;
js_pushlstring(J, s, e - s);
return 1;