shithub: libmujs

Download patch

ref: 588fdd18d6cdab241ee4af92cd854ff20fffb691
parent: 5f3ea4132d2a7b34c3a14b196f2444f375d1f93b
author: Tor Andersson <[email protected]>
date: Tue Feb 18 08:39:49 EST 2014

Small cleanups.

--- a/jscompile.c
+++ b/jscompile.c
@@ -295,7 +295,6 @@
 		break;
 	default:
 		jsC_error(J, lhs, "invalid l-value in assignment");
-		break;
 	}
 }
 
@@ -331,7 +330,6 @@
 		break;
 	default:
 		jsC_error(J, lhs, "invalid l-value in for-in loop assignment");
-		break;
 	}
 }
 
@@ -357,7 +355,6 @@
 		break;
 	default:
 		jsC_error(J, lhs, "invalid l-value in assignment");
-		break;
 	}
 }
 
@@ -374,7 +371,6 @@
 		break;
 	default:
 		jsC_error(J, lhs, "invalid l-value in assignment");
-		break;
 	}
 }
 
@@ -403,7 +399,6 @@
 		break;
 	default:
 		jsC_error(J, exp, "invalid l-value in delete expression");
-		break;
 	}
 }
 
@@ -612,7 +607,7 @@
 
 /* Patch break and continue statements */
 
-static void addjump(JF, js_AstType type, js_Ast *target, int inst)
+static void addjump(JF, enum js_AstType type, js_Ast *target, int inst)
 {
 	js_JumpList *jump = malloc(sizeof *jump);
 	jump->type = type;
@@ -632,7 +627,7 @@
 	}
 }
 
-static int isloop(js_AstType T)
+static int isloop(enum js_AstType T)
 {
 	return T == STM_DO || T == STM_WHILE ||
 		T == STM_FOR || T == STM_FOR_VAR ||
@@ -639,7 +634,7 @@
 		T == STM_FOR_IN || T == STM_FOR_IN_VAR;
 }
 
-static int isfun(js_AstType T)
+static int isfun(enum js_AstType T)
 {
 	return T == AST_FUNDEC || T == EXP_FUN || T == EXP_PROP_GET || T == EXP_PROP_SET;
 }
@@ -699,7 +694,7 @@
 
 /* Emit code to rebalance stack and scopes during an abrupt exit */
 
-static void cexit(JF, js_AstType T, js_Ast *node, js_Ast *target)
+static void cexit(JF, enum js_AstType T, js_Ast *node, js_Ast *target)
 {
 	js_Ast *prev;
 	do {
--- a/jscompile.h
+++ b/jscompile.h
@@ -1,8 +1,6 @@
 #ifndef js_compile_h
 #define js_compile_h
 
-typedef enum js_OpCode js_OpCode;
-
 enum js_OpCode
 {
 	OP_POP,		/* A -- */
@@ -151,7 +149,7 @@
 
 js_Function *jsC_compilefunction(js_State *J, js_Ast *prog);
 js_Function *jsC_compile(js_State *J, js_Ast *prog);
-const char *jsC_opcodestring(int opcode);
+const char *jsC_opcodestring(enum js_OpCode opcode);
 void jsC_dumpfunction(js_State *J, js_Function *fun);
 
 #endif
--- a/jsdump.c
+++ b/jsdump.c
@@ -17,7 +17,7 @@
 #include "opnames.h"
 };
 
-const char *jsP_aststring(js_AstType type)
+const char *jsP_aststring(enum js_AstType type)
 {
 	if (type > nelem(astname))
 		return "<unknown>";
@@ -24,14 +24,14 @@
 	return astname[type];
 }
 
-const char *jsC_opcodestring(int opcode)
+const char *jsC_opcodestring(enum js_OpCode opcode)
 {
-	if (opcode < 0 || opcode > nelem(opname))
+	if (opcode > nelem(opname))
 		return "<unknown>";
 	return opname[opcode];
 }
 
-static int prec(js_AstType type)
+static int prec(enum js_AstType type)
 {
 	switch (type) {
 	case EXP_IDENTIFIER:
--- a/jsi.h
+++ b/jsi.h
@@ -45,6 +45,7 @@
 const char *js_utfidxtoptr(const char *s, int i);
 
 void js_dup(js_State *J);
+void js_dup2(js_State *J);
 void js_rot2(js_State *J);
 void js_rot3(js_State *J);
 void js_rot2pop1(js_State *J);
--- a/jsmath.c
+++ b/jsmath.c
@@ -126,14 +126,14 @@
 {
 	js_pushobject(J, jsV_newobject(J, JS_CMATH, J->Object_prototype));
 	{
-		jsB_propn(J, "E", M_E);
-		jsB_propn(J, "LN10", M_LN10);
-		jsB_propn(J, "LN2", M_LN2);
-		jsB_propn(J, "LOG2E", M_LOG2E);
-		jsB_propn(J, "LOG10E", M_LOG10E);
-		jsB_propn(J, "PI", M_PI);
-		jsB_propn(J, "SQRT1_2", M_SQRT1_2);
-		jsB_propn(J, "SQRT2", M_SQRT2);
+		jsB_propn(J, "E", 2.7182818284590452354);
+		jsB_propn(J, "LN10", 2.302585092994046);
+		jsB_propn(J, "LN2", 0.6931471805599453);
+		jsB_propn(J, "LOG2E", 1.4426950408889634);
+		jsB_propn(J, "LOG10E", 0.4342944819032518);
+		jsB_propn(J, "PI", 3.1415926535897932);
+		jsB_propn(J, "SQRT1_2", 0.7071067811865476);
+		jsB_propn(J, "SQRT2", 1.4142135623730951);
 
 		jsB_propf(J, "abs", Math_abs, 1);
 		jsB_propf(J, "acos", Math_acos, 1);
--- a/jsparse.h
+++ b/jsparse.h
@@ -1,8 +1,6 @@
 #ifndef js_parse_h
 #define js_parse_h
 
-typedef enum js_AstType js_AstType;
-
 enum js_AstType
 {
 	AST_LIST,
@@ -120,7 +118,7 @@
 
 struct js_JumpList
 {
-	js_AstType type;
+	enum js_AstType type;
 	int inst;
 	js_JumpList *next;
 };
@@ -141,7 +139,7 @@
 js_Ast *jsP_parse(js_State *J, const char *filename, const char *source);
 void jsP_freeparse(js_State *J);
 
-const char *jsP_aststring(js_AstType type);
+const char *jsP_aststring(enum js_AstType type);
 void jsP_dumpsyntax(js_State *J, js_Ast *prog);
 void jsP_dumplist(js_State *J, js_Ast *prog);
 
--- a/jsproperty.c
+++ b/jsproperty.c
@@ -144,7 +144,7 @@
 }
 
 
-js_Object *jsV_newobject(js_State *J, js_Class type, js_Object *prototype)
+js_Object *jsV_newobject(js_State *J, enum js_Class type, js_Object *prototype)
 {
 	js_Object *obj = calloc(sizeof(js_Object), 1);
 	obj->gcmark = 0;
--- a/jsregexp.c
+++ b/jsregexp.c
@@ -42,7 +42,7 @@
 
 	opts = 0;
 	if (re->flags & JS_REGEXP_G) {
-		if (re->last < 0 || re->last > strlen(text)) {
+		if (re->last > strlen(text)) {
 			re->last = 0;
 			js_pushnull(J);
 			return 1;
--- a/jsrun.c
+++ b/jsrun.c
@@ -594,7 +594,7 @@
 		s = v->u.boolean ? "_True" : "_False";
 		break;
 	case JS_TOBJECT:
-		sprintf(buf, "%p", v->u.object);
+		sprintf(buf, "%p", (void*)v->u.object);
 		s = js_intern(J, buf);
 		break;
 	default:
@@ -998,7 +998,7 @@
 	const char **ST = F->strtab;
 	short *pcstart = F->code;
 	short *pc = F->code;
-	js_OpCode opcode;
+	enum js_OpCode opcode;
 	int offset;
 
 	const char *str;
@@ -1301,7 +1301,7 @@
 			ix = js_toint32(J, -2);
 			uy = js_touint32(J, -1);
 			js_pop(J, 2);
-			js_pushnumber(J, ix >> (uy & 0x1F)); break;
+			js_pushnumber(J, ix >> (uy & 0x1F));
 			break;
 
 		case OP_USHR:
@@ -1308,7 +1308,7 @@
 			ux = js_touint32(J, -2);
 			uy = js_touint32(J, -1);
 			js_pop(J, 2);
-			js_pushnumber(J, ux >> (uy & 0x1F)); break;
+			js_pushnumber(J, ux >> (uy & 0x1F));
 			break;
 
 		/* Relational operators */
--- a/jsvalue.h
+++ b/jsvalue.h
@@ -1,9 +1,6 @@
 #ifndef js_object_h
 #define js_object_h
 
-typedef enum js_Type js_Type;
-typedef enum js_Class js_Class;
-
 typedef struct js_Property js_Property;
 typedef struct js_Iterator js_Iterator;
 
@@ -36,7 +33,7 @@
 
 struct js_Value
 {
-	js_Type type;
+	enum js_Type type;
 	union {
 		int boolean;
 		double number;
@@ -55,7 +52,7 @@
 
 struct js_Object
 {
-	js_Class type;
+	enum js_Class type;
 	int extensible;
 	js_Property *properties;
 	js_Property *head, *tail; /* for enumeration */
@@ -133,7 +130,7 @@
 double jsV_stringtonumber(js_State *J, const char *string);
 
 /* jsproperty.c */
-js_Object *jsV_newobject(js_State *J, js_Class type, js_Object *prototype);
+js_Object *jsV_newobject(js_State *J, enum js_Class type, js_Object *prototype);
 js_Property *jsV_getownproperty(js_State *J, js_Object *obj, const char *name);
 js_Property *jsV_getpropertyx(js_State *J, js_Object *obj, const char *name, int *own);
 js_Property *jsV_getproperty(js_State *J, js_Object *obj, const char *name);