shithub: libmujs

Download patch

ref: 18b192b8aa8dd3779d33ead2b5d8531a43389cd4
parent: f7cdddbbe911ffc6fa36ce0f9c3448e9bccc2452
author: Tor Andersson <tor@ccxvii.net>
date: Wed Jan 15 20:59:17 EST 2014

Minor cleanups.

--- 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_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
--- a/jscompile.c
+++ b/jscompile.c
@@ -15,8 +15,8 @@
 {
 	int n = 0;
 	while (list) {
-		n++;
 		list = list->b;
+		++n;
 	}
 	return n;
 }
@@ -54,7 +54,7 @@
 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 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 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 @@
 	while (list) {
 		cexp(J, F, list->a);
 		list = list->b;
-		n++;
+		++n;
 	}
 	return n;
 }
--- a/jscompile.h
+++ b/jscompile.h
@@ -111,7 +111,6 @@
 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
--- a/jsdump.c
+++ b/jsdump.c
@@ -596,16 +596,16 @@
 	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 @@
 		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]);
--- a/jsintern.c
+++ b/jsintern.c
@@ -71,7 +71,7 @@
 	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)
--- 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
 {
--- a/jsrun.c
+++ b/jsrun.c
@@ -13,7 +13,7 @@
 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,8 +502,7 @@
 			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);
@@ -510,7 +509,13 @@
 			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 @@
 	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);
--- 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)
 {
--- a/main.c
+++ b/main.c
@@ -8,7 +8,7 @@
 
 	J = js_newstate();
 
-	for (i = 1; i < argc; i++) {
+	for (i = 1; i < argc; ++i) {
 		js_loadfile(J, argv[i]);
 		// js_run(J);
 	}