|
@@ -164,7 +164,7 @@ static void sPushCodeFloat(Script* sc) {
|
|
sPushFloat(sc, value);
|
|
sPushFloat(sc, value);
|
|
}
|
|
}
|
|
|
|
|
|
-static void sIntBinary(Script* sc, int (*fInt)(int, int), float (*fFloat)(float, float)) {
|
|
|
|
|
|
+static void sNumberBinary(Script* sc, int (*fInt)(int, int), float (*fFloat)(float, float)) {
|
|
Object o[2];
|
|
Object o[2];
|
|
if(sPop(sc, o) || sPop(sc, o + 1)) {
|
|
if(sPop(sc, o) || sPop(sc, o + 1)) {
|
|
return;
|
|
return;
|
|
@@ -181,6 +181,13 @@ static void sIntBinary(Script* sc, int (*fInt)(int, int), float (*fFloat)(float,
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+static void sIntBinary(Script* sc, int (*f)(int, int)) {
|
|
|
|
+ Object o[2];
|
|
|
|
+ if(!sPop(sc, o) && !sPop(sc, o + 1) && sCheckType(sc, o, OT_INT) && sCheckType(sc, o + 1, OT_INT)) {
|
|
|
|
+ sPushInt(sc, f(o[0].data.intValue, o[1].data.intValue));
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
static int sIntAdd(int a, int b) {
|
|
static int sIntAdd(int a, int b) {
|
|
return a + b;
|
|
return a + b;
|
|
}
|
|
}
|
|
@@ -197,6 +204,10 @@ static int sIntDiv(int a, int b) {
|
|
return b / a;
|
|
return b / a;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+static int sMod(int a, int b) {
|
|
|
|
+ return b % a;
|
|
|
|
+}
|
|
|
|
+
|
|
static float sFloatAdd(float a, float b) {
|
|
static float sFloatAdd(float a, float b) {
|
|
return a + b;
|
|
return a + b;
|
|
}
|
|
}
|
|
@@ -344,10 +355,11 @@ static void sConsumeInstruction(Script* sc) {
|
|
case OP_POP: sPopEmpty(sc); break;
|
|
case OP_POP: sPopEmpty(sc); break;
|
|
case OP_SET: sSet(sc); break;
|
|
case OP_SET: sSet(sc); break;
|
|
case OP_GET: sGet(sc); break;
|
|
case OP_GET: sGet(sc); break;
|
|
- case OP_ADD: sIntBinary(sc, sIntAdd, sFloatAdd); break;
|
|
|
|
- case OP_SUB: sIntBinary(sc, sIntSub, sFloatSub); break;
|
|
|
|
- case OP_MUL: sIntBinary(sc, sIntMul, sFloatMul); break;
|
|
|
|
- case OP_DIV: sIntBinary(sc, sIntDiv, sFloatDiv); break;
|
|
|
|
|
|
+ case OP_ADD: sNumberBinary(sc, sIntAdd, sFloatAdd); break;
|
|
|
|
+ case OP_SUB: sNumberBinary(sc, sIntSub, sFloatSub); break;
|
|
|
|
+ case OP_MUL: sNumberBinary(sc, sIntMul, sFloatMul); break;
|
|
|
|
+ case OP_DIV: sNumberBinary(sc, sIntDiv, sFloatDiv); break;
|
|
|
|
+ case OP_MOD: sIntBinary(sc, sMod); break;
|
|
case OP_LESS: sBoolBinary(sc, sIntLess, sFloatLess); break;
|
|
case OP_LESS: sBoolBinary(sc, sIntLess, sFloatLess); break;
|
|
case OP_GREATER: sBoolBinary(sc, sIntGreater, sFloatGreater); break;
|
|
case OP_GREATER: sBoolBinary(sc, sIntGreater, sFloatGreater); break;
|
|
case OP_EQUAL: sEqual(sc); break;
|
|
case OP_EQUAL: sEqual(sc); break;
|
|
@@ -444,6 +456,7 @@ void sPrintCode(Script* sc) {
|
|
case OP_SUB: puts("Sub"); break;
|
|
case OP_SUB: puts("Sub"); break;
|
|
case OP_MUL: puts("Mul"); break;
|
|
case OP_MUL: puts("Mul"); break;
|
|
case OP_DIV: puts("Div"); break;
|
|
case OP_DIV: puts("Div"); break;
|
|
|
|
+ case OP_MOD: puts("Mod"); break;
|
|
case OP_LESS: puts("Less"); break;
|
|
case OP_LESS: puts("Less"); break;
|
|
case OP_GREATER: puts("Greater"); break;
|
|
case OP_GREATER: puts("Greater"); break;
|
|
case OP_EQUAL: puts("Equal"); break;
|
|
case OP_EQUAL: puts("Equal"); break;
|