shithub: libmujs

Download patch

ref: 6f4c2143e56d833f9a7705f34d97c48a80a65178
parent: 0fd3f364ec2556f16c26498cc9575ee9807f463b
author: Tor Andersson <tor@ccxvii.net>
date: Wed Jan 22 20:35:44 EST 2014

Use 'emitraw' function to emit operands in preparation for eventual peephole optimisations.

--- a/jscompile.c
+++ b/jscompile.c
@@ -49,7 +49,7 @@
 
 /* Emit opcodes, constants and jumps */
 
-static void emit(JF, int value)
+static void emitraw(JF, int value)
 {
 	if (F->codelen >= F->codecap) {
 		F->codecap = F->codecap ? F->codecap * 2 : 64;
@@ -58,6 +58,11 @@
 	F->code[F->codelen++] = value;
 }
 
+static void emit(JF, int value)
+{
+	emitraw(J, F, value);
+}
+
 static int addfunction(JF, js_Function *value)
 {
 	if (F->funlen >= F->funcap) {
@@ -99,7 +104,7 @@
 static void emitfunction(JF, js_Function *fun)
 {
 	emit(J, F, OP_CLOSURE);
-	emit(J, F, addfunction(J, F, fun));
+	emitraw(J, F, addfunction(J, F, fun));
 }
 
 static void emitnumber(JF, double num)
@@ -110,10 +115,10 @@
 		emit(J, F, OP_NUMBER_1);
 	else if (num == (short)num) {
 		emit(J, F, OP_NUMBER_X);
-		emit(J, F, (short)num);
+		emitraw(J, F, (short)num);
 	} else {
 		emit(J, F, OP_NUMBER);
-		emit(J, F, addnumber(J, F, num));
+		emitraw(J, F, addnumber(J, F, num));
 	}
 }
 
@@ -120,7 +125,7 @@
 static void emitstring(JF, int opcode, const char *str)
 {
 	emit(J, F, opcode);
-	emit(J, F, addstring(J, F, str));
+	emitraw(J, F, addstring(J, F, str));
 }
 
 static int here(JF)
@@ -132,7 +137,7 @@
 {
 	int inst = F->codelen + 1;
 	emit(J, F, opcode);
-	emit(J, F, 0);
+	emitraw(J, F, 0);
 	return inst;
 }
 
@@ -139,7 +144,7 @@
 static void jumpto(JF, int opcode, int dest)
 {
 	emit(J, F, opcode);
-	emit(J, F, dest);
+	emitraw(J, F, dest);
 }
 
 static void label(JF, int inst)
@@ -174,7 +179,7 @@
 		if (list->a->type != EXP_UNDEF) {
 			emit(J, F, OP_DUP);
 			emit(J, F, OP_NUMBER_X);
-			emit(J, F, i++);
+			emitraw(J, F, i++);
 			cexp(J, F, list->a);
 			emit(J, F, OP_SETPROP);
 			emit(J, F, OP_POP);
@@ -381,7 +386,7 @@
 	}
 	n = cargs(J, F, args);
 	emit(J, F, OP_CALL);
-	emit(J, F, n);
+	emitraw(J, F, n);
 }
 
 static void cexp(JF, js_Ast *exp)
@@ -436,7 +441,7 @@
 		cexp(J, F, exp->a);
 		n = cargs(J, F, exp->b);
 		emit(J, F, OP_NEW);
-		emit(J, F, n);
+		emitraw(J, F, n);
 		break;
 
 	case EXP_DELETE:
@@ -696,7 +701,7 @@
 	{
 		/* if we get here, we have caught an exception in the try block */
 		L2 = jump(J, F, OP_CATCH);
-		emit(J, F, addstring(J, F, catchvar->string));
+		emitraw(J, F, addstring(J, F, catchvar->string));
 		{
 			/* if we get here, we have caught an exception in the catch block */
 			emit(J, F, OP_THROW); /* rethrow exception */
@@ -719,7 +724,7 @@
 	{
 		/* if we get here, we have caught an exception in the try block */
 		L2 = jump(J, F, OP_CATCH);
-		emit(J, F, addstring(J, F, catchvar->string));
+		emitraw(J, F, addstring(J, F, catchvar->string));
 		{
 			/* if we get here, we have caught an exception in the catch block */
 			cstm(J, F, finallystm); /* inline finally block */