ref: 20d0fa04df4d750f52ac6a41b50ebd96a1d005f0
parent: 603977ae5bad97d544725cd6c36f9af30e6aef4e
author: Tor Andersson <tor.andersson@artifex.com>
date: Fri Mar 8 05:57:13 EST 2019
Simplify opcodes: numbers and integer constants.
--- a/jscompile.c
+++ b/jscompile.c
@@ -186,20 +186,20 @@
static void emitnumber(JF, double num)
{
if (num == 0) {
- emit(J, F, OP_NUMBER_0);
+ emit(J, F, OP_INTEGER);
+ emitarg(J, F, 32768);
if (signbit(num))
emit(J, F, OP_NEG);
- } else if (num == 1) {
- emit(J, F, OP_NUMBER_1);
- } else if (num == (js_Instruction)num) {
- emit(J, F, OP_NUMBER_POS);
- emitarg(J, F, (js_Instruction)num);
- } else if (num < 0 && -num == (js_Instruction)(-num)) {
- emit(J, F, OP_NUMBER_NEG);
- emitarg(J, F, (js_Instruction)(-num));
} else {
- emit(J, F, OP_NUMBER);
- emitarg(J, F, addnumber(J, F, num));
+ double nv = num + 32768;
+ js_Instruction iv = nv;
+ if (nv == iv) {
+ emit(J, F, OP_INTEGER);
+ emitarg(J, F, iv);
+ } else {
+ emit(J, F, OP_NUMBER);
+ emitarg(J, F, addnumber(J, F, num));
+ }
}
}
--- a/jscompile.h
+++ b/jscompile.h
@@ -10,11 +10,7 @@
OP_ROT3, /* A B C -- C A B */
OP_ROT4, /* A B C D -- D A B C */
- OP_NUMBER_0, /* -- 0 */
- OP_NUMBER_1, /* -- 1 */
- OP_NUMBER_POS, /* -K- K */
- OP_NUMBER_NEG, /* -K- -K */
-
+ OP_INTEGER, /* -K- (number-32768) */
OP_NUMBER, /* -N- <number> */
OP_STRING, /* -S- <string> */
OP_CLOSURE, /* -F- <closure> */
--- a/jsdump.c
+++ b/jsdump.c
@@ -797,6 +797,9 @@
ps(opname[c]);
switch (c) {
+ case OP_INTEGER:
+ printf(" %d", (*p++) - 32768);
+ break;
case OP_NUMBER:
printf(" %.9g", F->numtab[*p++]);
break;
@@ -830,8 +833,6 @@
case OP_GETLOCAL:
case OP_SETLOCAL:
case OP_DELLOCAL:
- case OP_NUMBER_POS:
- case OP_NUMBER_NEG:
case OP_CALL:
case OP_NEW:
case OP_JUMP:
--- a/jsrun.c
+++ b/jsrun.c
@@ -1315,10 +1315,7 @@
case OP_ROT3: js_rot3(J); break;
case OP_ROT4: js_rot4(J); break;
- case OP_NUMBER_0: js_pushnumber(J, 0); break;
- case OP_NUMBER_1: js_pushnumber(J, 1); break;
- case OP_NUMBER_POS: js_pushnumber(J, *pc++); break;
- case OP_NUMBER_NEG: js_pushnumber(J, -(*pc++)); break;
+ case OP_INTEGER: js_pushnumber(J, *pc++ - 32768); break;
case OP_NUMBER: js_pushnumber(J, NT[*pc++]); break;
case OP_STRING: js_pushliteral(J, ST[*pc++]); break;
--- a/opnames.h
+++ b/opnames.h
@@ -4,10 +4,7 @@
"rot2",
"rot3",
"rot4",
-"number_0",
-"number_1",
-"number_pos",
-"number_neg",
+"integer",
"number",
"string",
"closure",