Small cleanups.

This commit is contained in:
Tor Andersson
2014-02-18 14:38:50 +01:00
parent 5f3ea4132d
commit 588fdd18d6
10 changed files with 29 additions and 40 deletions
+4 -9
View File
@@ -295,7 +295,6 @@ static void cassign(JF, js_Ast *lhs, js_Ast *rhs)
break;
default:
jsC_error(J, lhs, "invalid l-value in assignment");
break;
}
}
@@ -331,7 +330,6 @@ static void cassignforin(JF, js_Ast *stm)
break;
default:
jsC_error(J, lhs, "invalid l-value in for-in loop assignment");
break;
}
}
@@ -357,7 +355,6 @@ static void cassignop1(JF, js_Ast *lhs, int dup)
break;
default:
jsC_error(J, lhs, "invalid l-value in assignment");
break;
}
}
@@ -374,7 +371,6 @@ static void cassignop2(JF, js_Ast *lhs)
break;
default:
jsC_error(J, lhs, "invalid l-value in assignment");
break;
}
}
@@ -403,7 +399,6 @@ static void cdelete(JF, js_Ast *exp)
break;
default:
jsC_error(J, exp, "invalid l-value in delete expression");
break;
}
}
@@ -612,7 +607,7 @@ static void cexp(JF, js_Ast *exp)
/* 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,14 +627,14 @@ static void labeljumps(JF, js_JumpList *jump, int baddr, int caddr)
}
}
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 ||
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 @@ static js_Ast *returntarget(JF, js_Ast *node)
/* 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 {
+1 -3
View File
@@ -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 @@ struct js_Function
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
+4 -4
View File
@@ -17,21 +17,21 @@ static const char *opname[] = {
#include "opnames.h"
};
const char *jsP_aststring(js_AstType type)
const char *jsP_aststring(enum js_AstType type)
{
if (type > nelem(astname))
return "<unknown>";
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:
+1
View File
@@ -45,6 +45,7 @@ int js_utfptrtoidx(const char *s, const char *p);
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);
+8 -8
View File
@@ -126,14 +126,14 @@ void jsB_initmath(js_State *J)
{
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);
+2 -4
View File
@@ -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 @@ typedef struct js_JumpList js_JumpList;
struct js_JumpList
{
js_AstType type;
enum js_AstType type;
int inst;
js_JumpList *next;
};
@@ -141,7 +139,7 @@ js_Ast *jsP_parsefunction(js_State *J, const char *filename, const char *params,
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);
+1 -1
View File
@@ -144,7 +144,7 @@ static js_Property *delete(js_State *J, js_Property *node, const char *name)
}
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;
+1 -1
View File
@@ -42,7 +42,7 @@ int js_RegExp_prototype_exec(js_State *J, js_Regexp *re, const char *text)
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;
+4 -4
View File
@@ -594,7 +594,7 @@ const char *js_ref(js_State *J)
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 @@ static void jsR_run(js_State *J, js_Function *F)
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,14 +1301,14 @@ static void jsR_run(js_State *J, js_Function *F)
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:
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 */
+3 -6
View File
@@ -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 @@ enum js_Class {
struct js_Value
{
js_Type type;
enum js_Type type;
union {
int boolean;
double number;
@@ -55,7 +52,7 @@ struct js_Regexp
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 @@ const char *jsV_numbertostring(js_State *J, double number);
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);