shithub: libmujs

Download patch

ref: 6a592abfc410b3ba1c7c8a18ec88d327e60d3c3e
parent: cd97fb4b5cff1d1b9f2cf77b4ab0d2e726451b8e
author: Tor Andersson <[email protected]>
date: Thu Mar 7 09:27:07 EST 2019

Use emitarg instead of emitraw to emit opcode arguments.

--- a/jscompile.c
+++ b/jscompile.c
@@ -89,6 +89,11 @@
 	emitraw(J, F, value);
 }
 
+static void emitarg(JF, int value)
+{
+	emitraw(J, F, value);
+}
+
 static void emitline(JF, js_Ast *node)
 {
 	if (F->lastline != node->line) {
@@ -175,7 +180,7 @@
 static void emitfunction(JF, js_Function *fun)
 {
 	emit(J, F, OP_CLOSURE);
-	emitraw(J, F, addfunction(J, F, fun));
+	emitarg(J, F, addfunction(J, F, fun));
 }
 
 static void emitnumber(JF, double num)
@@ -188,13 +193,13 @@
 		emit(J, F, OP_NUMBER_1);
 	} else if (num == (js_Instruction)num) {
 		emit(J, F, OP_NUMBER_POS);
-		emitraw(J, F, (js_Instruction)num);
+		emitarg(J, F, (js_Instruction)num);
 	} else if (num < 0 && -num == (js_Instruction)(-num)) {
 		emit(J, F, OP_NUMBER_NEG);
-		emitraw(J, F, (js_Instruction)(-num));
+		emitarg(J, F, (js_Instruction)(-num));
 	} else {
 		emit(J, F, OP_NUMBER);
-		emitraw(J, F, addnumber(J, F, num));
+		emitarg(J, F, addnumber(J, F, num));
 	}
 }
 
@@ -201,7 +206,7 @@
 static void emitstring(JF, int opcode, const char *str)
 {
 	emit(J, F, opcode);
-	emitraw(J, F, addstring(J, F, str));
+	emitarg(J, F, addstring(J, F, str));
 }
 
 static void emitlocal(JF, int oploc, int opvar, js_Ast *ident)
@@ -218,7 +223,7 @@
 		i = findlocal(J, F, ident->string);
 		if (i >= 0) {
 			emit(J, F, oploc);
-			emitraw(J, F, i);
+			emitarg(J, F, i);
 			return;
 		}
 	}
@@ -232,9 +237,10 @@
 
 static int emitjump(JF, int opcode)
 {
-	int inst = F->codelen + 1;
+	int inst;
 	emit(J, F, opcode);
-	emitraw(J, F, 0);
+	inst = F->codelen;
+	emitarg(J, F, 0);
 	return inst;
 }
 
@@ -243,7 +249,7 @@
 	emit(J, F, opcode);
 	if (dest != (js_Instruction)dest)
 		js_syntaxerror(J, "jump address integer overflow");
-	emitraw(J, F, dest);
+	emitarg(J, F, dest);
 }
 
 static void labelto(JF, int inst, int addr)
@@ -546,7 +552,7 @@
 	}
 	n = cargs(J, F, args);
 	emit(J, F, OP_CALL);
-	emitraw(J, F, n);
+	emitarg(J, F, n);
 }
 
 static void cexp(JF, js_Ast *exp)
@@ -565,8 +571,8 @@
 
 	case EXP_REGEXP:
 		emit(J, F, OP_NEWREGEXP);
-		emitraw(J, F, addstring(J, F, exp->string));
-		emitraw(J, F, exp->number);
+		emitarg(J, F, addstring(J, F, exp->string));
+		emitarg(J, F, exp->number);
 		break;
 
 	case EXP_OBJECT:
@@ -606,7 +612,7 @@
 		cexp(J, F, exp->a);
 		n = cargs(J, F, exp->b);
 		emit(J, F, OP_NEW);
-		emitraw(J, F, n);
+		emitarg(J, F, n);
 		break;
 
 	case EXP_DELETE:
@@ -1348,7 +1354,7 @@
 		if (F->lightweight) {
 			addlocal(J, F, name, 0);
 			emit(J, F, OP_INITLOCAL);
-			emitraw(J, F, findlocal(J, F, name->string));
+			emitarg(J, F, findlocal(J, F, name->string));
 		} else {
 			emitstring(J, F, OP_INITVAR, name->string);
 		}
--- a/jsrun.c
+++ b/jsrun.c
@@ -1236,7 +1236,7 @@
 	printf("stack {\n");
 	for (i = 0; i < TOP; ++i) {
 		putchar(i == BOT ? '>' : ' ');
-		printf("% 4d: ", i);
+		printf("%4d: ", i);
 		js_dumpvalue(J, STACK[i]);
 		putchar('\n');
 	}