diff --git a/js.h b/js.h index d4cd6ab..aa6e20f 100644 --- a/js.h +++ b/js.h @@ -11,15 +11,6 @@ typedef struct js_State js_State; -typedef struct js_StringNode js_StringNode; -typedef struct js_Ast js_Ast; -typedef struct js_Function js_Function; -typedef struct js_Environment js_Environment; - -typedef struct js_Value js_Value; -typedef struct js_Object js_Object; -typedef struct js_Property js_Property; - typedef int (*js_CFunction)(js_State *J, int argc); #define JS_REGEXP_G 1 @@ -34,8 +25,15 @@ int js_error(js_State *J, const char *fmt, ...); int js_loadstring(js_State *J, const char *s); int js_loadfile(js_State *J, const char *filename); -const char *js_intern(js_State *J, const char *s); +/* private */ +typedef struct js_Ast js_Ast; +typedef struct js_Environment js_Environment; +typedef struct js_Function js_Function; +typedef struct js_Object js_Object; +typedef struct js_StringNode js_StringNode; + +const char *js_intern(js_State *J, const char *s); void js_printstringtree(js_State *J); #endif diff --git a/jscompile.c b/jscompile.c index d1eca43..fbefdcf 100644 --- a/jscompile.c +++ b/jscompile.c @@ -15,8 +15,8 @@ static int paramlen(js_Ast *list) { int n = 0; while (list) { - n++; list = list->b; + ++n; } return n; } @@ -54,7 +54,7 @@ static js_Function *newfun(js_State *J, js_Ast *name, js_Ast *params, js_Ast *bo static void freefun(js_State *J, js_Function *F) { // int i; -// for (i = 0; i < F->funlen; i++) +// for (i = 0; i < F->funlen; ++i) // freefun(J, F->funtab[i]); free(F->funtab); free(F->numtab); @@ -87,7 +87,7 @@ static int addfunction(JF, js_Function *value) static int addnumber(JF, double value) { int i; - for (i = 0; i < F->numlen; i++) + for (i = 0; i < F->numlen; ++i) if (F->numtab[i] == value) return i; if (F->numlen >= F->numcap) { @@ -101,7 +101,7 @@ static int addnumber(JF, double value) static int addstring(JF, const char *value) { int i; - for (i = 0; i < F->strlen; i++) + for (i = 0; i < F->strlen; ++i) if (!strcmp(F->strtab[i], value)) return i; if (F->strlen >= F->strcap) { @@ -224,7 +224,7 @@ static int cargs(JF, js_Ast *list) while (list) { cexp(J, F, list->a); list = list->b; - n++; + ++n; } return n; } diff --git a/jscompile.h b/jscompile.h index a0ef95c..f094b14 100644 --- a/jscompile.h +++ b/jscompile.h @@ -111,7 +111,6 @@ js_Function *jsC_compile(js_State *J, js_Ast *prog); void jsC_freecompile(js_State *J); int jsC_error(js_State *J, js_Ast *node, const char *fmt, ...); -void jsC_dumpvalue(js_State *J, js_Value v); void jsC_dumpfunction(js_State *J, js_Function *fun); #endif diff --git a/jsdump.c b/jsdump.c index 4e20d3c..1ab4934 100644 --- a/jsdump.c +++ b/jsdump.c @@ -596,16 +596,16 @@ void jsC_dumpfunction(js_State *J, js_Function *F) int i; printf("function %p %s(", F, F->name); - for (i = 0; i < F->numparams; i++) + for (i = 0; i < F->numparams; ++i) printf("%s%s", i > 0 ? ", " : "", F->params[i]); printf(")\n"); - for (i = 0; i < F->funlen; i++) + for (i = 0; i < F->funlen; ++i) printf("\tfunction %p %s\n", F->funtab[i], F->funtab[i]->name); - for (i = 0; i < F->strlen; i++) { + for (i = 0; i < F->strlen; ++i) { ps("\tstring "); pstr(F->strtab[i]); ps("\n"); } // TODO: regexp - for (i = 0; i < F->numlen; i++) + for (i = 0; i < F->numlen; ++i) printf("\tnumber %.9g\n", F->numtab[i]); while (p < end) { @@ -648,7 +648,7 @@ void jsC_dumpfunction(js_State *J, js_Function *F) nl(); } - for (i = 0; i < F->funlen; i++) { + for (i = 0; i < F->funlen; ++i) { if (F->funtab[i] != F) { nl(); jsC_dumpfunction(J, F->funtab[i]); diff --git a/jsintern.c b/jsintern.c index 49273f0..baf2076 100644 --- a/jsintern.c +++ b/jsintern.c @@ -71,7 +71,7 @@ static void printstringnode(js_StringNode *node, int level) if (node->left != &sentinel) printstringnode(node->left, level + 1); printf("%d: ", node->level); - for (i = 0; i < level; i++) + for (i = 0; i < level; ++i) putchar('\t'); printf("'%s'\n", node->string); if (node->right != &sentinel) diff --git a/jsobject.h b/jsobject.h index 000a93b..ef4de0b 100644 --- a/jsobject.h +++ b/jsobject.h @@ -1,8 +1,11 @@ #ifndef js_object_h #define js_object_h -typedef enum js_Class js_Class; typedef enum js_Type js_Type; +typedef struct js_Value js_Value; + +typedef enum js_Class js_Class; +typedef struct js_Property js_Property; struct js_Environment { diff --git a/jsrun.c b/jsrun.c index 03be42a..8d39ece 100644 --- a/jsrun.c +++ b/jsrun.c @@ -13,7 +13,7 @@ static void js_call(js_State *J, int argc); static void js_dumpstack(js_State *J) { int i; - for (i = 0; i < top; i++) { + for (i = 0; i < top; ++i) { printf("stack %d: ", i); js_dumpvalue(J, stack[i]); putchar('\n'); @@ -502,15 +502,20 @@ static void runfun(js_State *J, js_Function *F, js_Environment *E) js_pushboolean(J, x >= y); break; - // case OP_EQ: - // case OP_NE: + case OP_EQ: case OP_STRICTEQ: x = js_tonumber(J, -2); y = js_tonumber(J, -1); js_pop(J, 2); js_pushboolean(J, x == y); break; - // case OP_STRICTNE: + case OP_NE: + case OP_STRICTNE: + x = js_tonumber(J, -2); + y = js_tonumber(J, -1); + js_pop(J, 2); + js_pushboolean(J, x != y); + break; /* Branching */ @@ -564,7 +569,7 @@ static void js_call(js_State *J, int argc) F = obj->function; E = js_newenvironment(J, obj->scope, js_newobject(J, JS_COBJECT)); - for (i = 0; i < F->numparams; i++) { + for (i = 0; i < F->numparams; ++i) { ref = js_decvar(J, E, F->params[i]); if (i + 1 < argc) ref->value = js_tovalue(J, i + 1); diff --git a/jsstate.c b/jsstate.c index e5a0494..ff33073 100644 --- a/jsstate.c +++ b/jsstate.c @@ -1,6 +1,6 @@ #include "js.h" -#include "jsstate.h" #include "jsobject.h" +#include "jsstate.h" js_State *js_newstate(void) { diff --git a/main.c b/main.c index ab18c23..140dda3 100644 --- a/main.c +++ b/main.c @@ -8,7 +8,7 @@ main(int argc, char **argv) J = js_newstate(); - for (i = 1; i < argc; i++) { + for (i = 1; i < argc; ++i) { js_loadfile(J, argv[i]); // js_run(J); }