|
@@ -147,6 +147,14 @@ POP_PUSH(bool, Bool)
|
|
|
} \
|
|
|
}
|
|
|
|
|
|
+#define INVERT_SIGN(type, Type) \
|
|
|
+ { \
|
|
|
+ type value = 0; \
|
|
|
+ if(sPop##Type(sc, &value)) { \
|
|
|
+ sPush##Type(sc, -value); \
|
|
|
+ } \
|
|
|
+ }
|
|
|
+
|
|
|
static void sReserveBytes(Script* sc) {
|
|
|
int bytes = 0;
|
|
|
int offset = 0;
|
|
@@ -186,55 +194,6 @@ static void sStore(Script* sc, int length) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-/*static void sAllocateArray(Script* sc) {
|
|
|
- Object length;
|
|
|
- if(!sPop(sc, &length) && sCheckType(sc, &length, OT_INT)) {
|
|
|
- if(length.as.intValue < 0) {
|
|
|
- sError(sc, "negative array length");
|
|
|
- return;
|
|
|
- }
|
|
|
- Object o = {.type = OT_ARRAY,
|
|
|
- .as.intValue =
|
|
|
- aAllocate(&sc->allocator, length.as.intValue)};
|
|
|
- sPush(sc, &o);
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-static void sArrayLength(Script* sc) {
|
|
|
- Object* o = sPopAndDereference(sc);
|
|
|
- if(o != NULL && sCheckType(sc, o, OT_ARRAY)) {
|
|
|
- int arrayPointer = o->as.intValue;
|
|
|
- if(arrayPointer < 0 || arrayPointer >= sc->allocator.capacity) {
|
|
|
- sError(sc, "array pointer is out of range");
|
|
|
- return;
|
|
|
- }
|
|
|
- sPushInt(sc, sc->allocator.data[arrayPointer].length);
|
|
|
- }
|
|
|
-}*/
|
|
|
-
|
|
|
-static void sPushCodeString(Script* sc) {
|
|
|
- int value = 0;
|
|
|
- if(sReadInt(sc, &value)) {
|
|
|
- char* s = (char*)(sc->code->code + sc->readIndex);
|
|
|
- sc->readIndex += value;
|
|
|
- sPush(sc, s, sizeof(char*));
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-static void sInvertSignInt(Script* sc) {
|
|
|
- int i = 0;
|
|
|
- if(sPopInt(sc, &i)) {
|
|
|
- sPushInt(sc, -i);
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-static void sInvertSignFloat(Script* sc) {
|
|
|
- float f = 0;
|
|
|
- if(sPopFloat(sc, &f)) {
|
|
|
- sPushFloat(sc, -f);
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
static void sNot(Script* sc) {
|
|
|
bool value = false;
|
|
|
if(sPopBool(sc, &value)) {
|
|
@@ -278,7 +237,6 @@ static void sReturn(Script* sc) {
|
|
|
if(sReadInt(sc, &bytes) && sPopInt(sc, &varIndex)) {
|
|
|
sc->stackVarIndex = varIndex;
|
|
|
sFree(sc, bytes);
|
|
|
-
|
|
|
int returnIndex;
|
|
|
if(sPopInt(sc, &returnIndex)) {
|
|
|
sc->readIndex = returnIndex;
|
|
@@ -286,21 +244,14 @@ static void sReturn(Script* sc) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-static void sReturnInt(Script* sc) {
|
|
|
- int value = 0;
|
|
|
- if(sPopInt(sc, &value)) {
|
|
|
- sReturn(sc);
|
|
|
- sPushInt(sc, value);
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-static void sReturnBool(Script* sc) {
|
|
|
- bool value = 0;
|
|
|
- if(sPopBool(sc, &value)) {
|
|
|
- sReturn(sc);
|
|
|
- sPushBool(sc, value);
|
|
|
+#define RETURN(type, Type) \
|
|
|
+ { \
|
|
|
+ type value; \
|
|
|
+ if(sPop##Type(sc, &value)) { \
|
|
|
+ sReturn(sc); \
|
|
|
+ sPush##Type(sc, value); \
|
|
|
+ } \
|
|
|
}
|
|
|
-}
|
|
|
|
|
|
static void sIfGoTo(Script* sc) {
|
|
|
int gotoIndex = 0;
|
|
@@ -331,7 +282,6 @@ static void sConsumeInstruction(Script* sc) {
|
|
|
case OP_NOTHING: break;
|
|
|
case OP_PUSH_INT: PUSH_CONSTANT(int, Int, 0); break;
|
|
|
case OP_PUSH_FLOAT: PUSH_CONSTANT(float, Float, 0.0f); break;
|
|
|
- case OP_PUSH_CONST_STRING: sPushCodeString(sc); break;
|
|
|
case OP_PUSH_TRUE: sPushBool(sc, true); break;
|
|
|
case OP_PUSH_FALSE: sPushBool(sc, false); break;
|
|
|
case OP_ADD_INT: NUMBER_OP(int, Int, +); break;
|
|
@@ -349,8 +299,8 @@ static void sConsumeInstruction(Script* sc) {
|
|
|
case OP_MOD_INT:
|
|
|
CHECKED_NUMBER_OP(int, Int, %, ZERO_CHECK("module"));
|
|
|
break;
|
|
|
- case OP_INVERT_SIGN_INT: sInvertSignInt(sc); break;
|
|
|
- case OP_INVERT_SIGN_FLOAT: sInvertSignFloat(sc); break;
|
|
|
+ case OP_INVERT_SIGN_INT: INVERT_SIGN(int, Int); break;
|
|
|
+ case OP_INVERT_SIGN_FLOAT: INVERT_SIGN(float, Float); break;
|
|
|
case OP_LESS_INT: BOOL_OP(int, Int, <); break;
|
|
|
case OP_LESS_FLOAT: BOOL_OP(float, Float, <); break;
|
|
|
case OP_GREATER_INT: BOOL_OP(int, Int, >); break;
|
|
@@ -377,14 +327,8 @@ static void sConsumeInstruction(Script* sc) {
|
|
|
case OP_PEEK_TRUE_GOTO: sPeekTrueGoTo(sc); break;
|
|
|
case OP_GOSUB: sGoSub(sc); break;
|
|
|
case OP_RETURN: sReturn(sc); break;
|
|
|
- case OP_RETURN_INT: sReturnInt(sc); break;
|
|
|
- case OP_RETURN_BOOL:
|
|
|
- sReturnBool(sc);
|
|
|
- break;
|
|
|
- // case OP_SET_RETURN: sSetReturn(sc); break;
|
|
|
- // case OP_DUPLICATE: sDuplicate(sc); break;
|
|
|
- // case OP_ALLOCATE_ARRAY: sAllocateArray(sc); break;
|
|
|
- // case OP_ARRAY_LENGTH: sArrayLength(sc); break;
|
|
|
+ case OP_RETURN_INT: RETURN(int, Int); break;
|
|
|
+ case OP_RETURN_BOOL: RETURN(bool, Bool); break;
|
|
|
case OP_RESERVE: sReserveBytes(sc); break;
|
|
|
case OP_LOAD_INT: sLoad(sc, sizeof(int)); break;
|
|
|
case OP_STORE_INT: sStore(sc, sizeof(int)); break;
|