diff --git a/Makefile b/Makefile index 656a0c7..7168f16 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ HDRS := $(wildcard js*.h utf.h regex.h) OBJS := $(SRCS:%.c=build/%.o) CC := clang -CFLAGS := -Wall -Wextra -Wunreachable-code -Wno-unused-parameter -Werror -g +CFLAGS := -std=c99 -pedantic -Wall -Wextra -Wunreachable-code -Wno-unused-parameter -Werror -g default: build js re diff --git a/jsarray.c b/jsarray.c index efd42bc..db4917e 100644 --- a/jsarray.c +++ b/jsarray.c @@ -400,7 +400,7 @@ static void Ap_unshift(js_State *J, unsigned int argc) static void Ap_toString(js_State *J, unsigned int argc) { js_pop(J, argc); - return Ap_join(J, 0); + Ap_join(J, 0); } static void Ap_indexOf(js_State *J, unsigned int argc) diff --git a/jsdump.c b/jsdump.c index 43e8e12..9e0c9ae 100644 --- a/jsdump.c +++ b/jsdump.c @@ -130,23 +130,23 @@ static int prec(enum js_AstType type) } } -static inline void pc(int c) +static void pc(int c) { putchar(c); } -static inline void ps(const char *s) +static void ps(const char *s) { fputs(s, stdout); } -static inline void in(int d) +static void in(int d) { while (d-- > 0) putchar('\t'); } -static inline void nl(void) +static void nl(void) { putchar('\n'); } diff --git a/jslex.c b/jslex.c index 286f85e..0e2d875 100644 --- a/jslex.c +++ b/jslex.c @@ -98,7 +98,7 @@ int jsY_findword(const char *s, const char **list, int num) return -1; } -static inline int jsY_findkeyword(js_State *J, const char *s) +static int jsY_findkeyword(js_State *J, const char *s) { int i = jsY_findword(s, keywords, nelem(keywords)); if (i >= 0) { @@ -119,17 +119,17 @@ int jsY_isnewline(int c) return c == 0xA || c == 0xD || c == 0x2028 || c == 0x2029; } -static inline int jsY_isidentifierstart(int c) +static int jsY_isidentifierstart(int c) { return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '$' || c == '_' || isalpharune(c); } -static inline int jsY_isidentifierpart(int c) +static int jsY_isidentifierpart(int c) { return (c >= '0' && c <= '9') || jsY_isidentifierstart(c); } -static inline int jsY_isdec(int c) +static int jsY_isdec(int c) { return (c >= '0' && c <= '9'); } @@ -192,7 +192,7 @@ static void textinit(js_State *J) J->lexbuf.len = 0; } -static inline void textpush(js_State *J, Rune c) +static void textpush(js_State *J, Rune c) { int n = runelen(c); if (J->lexbuf.len + n > J->lexbuf.cap) { @@ -202,19 +202,19 @@ static inline void textpush(js_State *J, Rune c) J->lexbuf.len += runetochar(J->lexbuf.text + J->lexbuf.len, &c); } -static inline char *textend(js_State *J) +static char *textend(js_State *J) { textpush(J, 0); return J->lexbuf.text; } -static inline void lexlinecomment(js_State *J) +static void lexlinecomment(js_State *J) { while (PEEK && PEEK != '\n') NEXT(); } -static inline int lexcomment(js_State *J) +static int lexcomment(js_State *J) { /* already consumed initial '/' '*' sequence */ while (PEEK != 0) { @@ -229,7 +229,7 @@ static inline int lexcomment(js_State *J) return -1; } -static inline double lexhex(js_State *J) +static double lexhex(js_State *J) { double n = 0; if (!jsY_ishex(PEEK)) @@ -241,7 +241,7 @@ static inline double lexhex(js_State *J) return n; } -static inline double lexinteger(js_State *J) +static double lexinteger(js_State *J) { double n = 0; if (!jsY_isdec(PEEK)) @@ -253,7 +253,7 @@ static inline double lexinteger(js_State *J) return n; } -static inline double lexfraction(js_State *J) +static double lexfraction(js_State *J) { double n = 0; double d = 1; @@ -265,7 +265,7 @@ static inline double lexfraction(js_State *J) return n / d; } -static inline double lexexponent(js_State *J) +static double lexexponent(js_State *J) { double sign; if (ACCEPT('e') || ACCEPT('E')) { @@ -277,7 +277,7 @@ static inline double lexexponent(js_State *J) return 0; } -static inline int lexnumber(js_State *J) +static int lexnumber(js_State *J) { double n; double e; @@ -315,7 +315,7 @@ static inline int lexnumber(js_State *J) return TK_NUMBER; } -static inline int lexescape(js_State *J) +static int lexescape(js_State *J) { int x = 0; @@ -354,7 +354,7 @@ static inline int lexescape(js_State *J) return 0; } -static inline int lexstring(js_State *J) +static int lexstring(js_State *J) { const char *s; @@ -452,7 +452,7 @@ static int lexregexp(js_State *J) } /* simple "return [no Line Terminator here] ..." contexts */ -static inline int isnlthcontext(int last) +static int isnlthcontext(int last) { switch (last) { case TK_BREAK: diff --git a/json.c b/json.c index e2a070a..ef565d3 100644 --- a/json.c +++ b/json.c @@ -5,12 +5,12 @@ #include "utf.h" -static inline void jsonnext(js_State *J) +static void jsonnext(js_State *J) { J->lookahead = jsY_lexjson(J); } -static inline int jsonaccept(js_State *J, int t) +static int jsonaccept(js_State *J, int t) { if (J->lookahead == t) { jsonnext(J); @@ -19,7 +19,7 @@ static inline int jsonaccept(js_State *J, int t) return 0; } -static inline void jsonexpect(js_State *J, int t) +static void jsonexpect(js_State *J, int t) { if (!jsonaccept(J, t)) js_syntaxerror(J, "JSON: unexpected token: %s (expected %s)", diff --git a/jsparse.c b/jsparse.c index 47d8bbf..2147543 100644 --- a/jsparse.c +++ b/jsparse.c @@ -130,12 +130,12 @@ void jsP_freeparse(js_State *J) /* Lookahead */ -static inline void next(js_State *J) +static void next(js_State *J) { J->lookahead = jsY_lex(J); } -static inline int accept(js_State *J, int t) +static int accept(js_State *J, int t) { if (J->lookahead == t) { next(J); @@ -144,7 +144,7 @@ static inline int accept(js_State *J, int t) return 0; } -static inline void expect(js_State *J, int t) +static void expect(js_State *J, int t) { if (accept(J, t)) return; @@ -883,7 +883,7 @@ static js_Ast *funbody(js_State *J) /* Constant folding */ -static inline int toint32(double d) +static int toint32(double d) { double two32 = 4294967296.0; double two31 = 2147483648.0; @@ -899,7 +899,7 @@ static inline int toint32(double d) return d; } -static inline unsigned int touint32(double d) +static unsigned int touint32(double d) { return toint32(d); } diff --git a/jsproperty.c b/jsproperty.c index ed3c6d7..26b2cac 100644 --- a/jsproperty.c +++ b/jsproperty.c @@ -57,7 +57,7 @@ static js_Property *lookup(js_Property *node, const char *name) return NULL; } -static inline js_Property *skew(js_Property *node) +static js_Property *skew(js_Property *node) { if (node->left->level == node->level) { js_Property *temp = node; @@ -68,7 +68,7 @@ static inline js_Property *skew(js_Property *node) return node; } -static inline js_Property *split(js_Property *node) +static js_Property *split(js_Property *node) { if (node->right->right->level == node->level) { js_Property *temp = node; diff --git a/jsregexp.c b/jsregexp.c index 3f4579a..e49159b 100644 --- a/jsregexp.c +++ b/jsregexp.c @@ -146,7 +146,7 @@ static void jsB_RegExp(js_State *J, unsigned int argc) { if (js_isregexp(J, 1) && argc == 1) return; - return jsB_new_RegExp(J, argc); + jsB_new_RegExp(J, argc); } static void Rp_toString(js_State *J, unsigned int argc) @@ -176,7 +176,7 @@ static void Rp_toString(js_State *J, unsigned int argc) static void Rp_exec(js_State *J, unsigned int argc) { - return js_RegExp_prototype_exec(J, js_toregexp(J, 0), js_tostring(J, 1)); + js_RegExp_prototype_exec(J, js_toregexp(J, 0), js_tostring(J, 1)); } void jsB_initregexp(js_State *J) diff --git a/jsstring.c b/jsstring.c index 115689d..531e141 100644 --- a/jsstring.c +++ b/jsstring.c @@ -322,8 +322,10 @@ static void Sp_match(js_State *J, unsigned int argc) js_newregexp(J, js_tostring(J, 1), 0); re = js_toregexp(J, -1); - if (!(re->flags & JS_REGEXP_G)) - return js_RegExp_prototype_exec(J, re, text); + if (!(re->flags & JS_REGEXP_G)) { + js_RegExp_prototype_exec(J, re, text); + return; + } re->last = 0; @@ -526,8 +528,9 @@ static void Sp_replace_string(js_State *J, unsigned int argc) static void Sp_replace(js_State *J, unsigned int argc) { if (js_isregexp(J, 1)) - return Sp_replace_regexp(J, argc); - return Sp_replace_string(J, argc); + Sp_replace_regexp(J, argc); + else + Sp_replace_string(J, argc); } static void Sp_split_regexp(js_State *J, unsigned int argc) diff --git a/regex.c b/regex.c index 58e6a28..e8a2bf2 100644 --- a/regex.c +++ b/regex.c @@ -54,7 +54,7 @@ static void die(struct cstate *g, const char *message) longjmp(g->kaboom, 1); } -static inline int canon(Rune c) +static int canon(Rune c) { Rune u = toupperrune(c); if (c >= 128 && u < 128) @@ -398,12 +398,12 @@ static Renode *newrep(struct cstate *g, Renode *atom, int ng, int min, int max) return rep; } -static inline void next(struct cstate *g) +static void next(struct cstate *g) { g->lookahead = lex(g); } -static inline int accept(struct cstate *g, int t) +static int accept(struct cstate *g, int t) { if (g->lookahead == t) { next(g); @@ -832,12 +832,12 @@ struct estate { Resub *m; }; -static inline int isnewline(int c) +static int isnewline(int c) { return c == 0xA || c == 0xD || c == 0x2028 || c == 0x2029; } -static inline int iswordchar(int c) +static int iswordchar(int c) { return c == '_' || (c >= 'a' && c <= 'z') || @@ -845,7 +845,7 @@ static inline int iswordchar(int c) (c >= '0' && c <= '9'); } -static inline int incclass(Reclass *cc, Rune c) +static int incclass(Reclass *cc, Rune c) { Rune *p; for (p = cc->spans; p < cc->end; p += 2) @@ -854,7 +854,7 @@ static inline int incclass(Reclass *cc, Rune c) return 0; } -static inline int incclasscanon(Reclass *cc, Rune c) +static int incclasscanon(Reclass *cc, Rune c) { Rune *p, r; for (p = cc->spans; p < cc->end; p += 2) @@ -895,8 +895,8 @@ static int match(struct estate *g, Reinst *pc, const char *s) pc = pc->x; continue; case I_SPLIT: - // TODO: use I_PROGRESS instead? #if 0 + // TODO: use I_PROGRESS instead? if (match(g, pc->x, s)) return 1; pc = pc->y;