SpiderScript - Speedup fixes to bytecode
authorJohn Hodge <[email protected]>
Wed, 21 Sep 2011 08:37:51 +0000 (16:37 +0800)
committerJohn Hodge <[email protected]>
Wed, 21 Sep 2011 08:37:51 +0000 (16:37 +0800)
Usermode/Libraries/libspiderscript.so_src/exec_bytecode.c
Usermode/Libraries/libspiderscript.so_src/main.c

index 9dabeff..780bee5 100644 (file)
@@ -612,6 +612,32 @@ int Bytecode_int_ExecuteFunction(tSpiderScript *Script, tScript_Function *Fcn, t
 
                        GET_STACKVAL(val2);     // Right
                        GET_STACKVAL(val1);     // Left
+
+                       #define PERFORM_NUM_OP(_type, _field) if(val1.Type == _type && val1.Type == val2.Type) { \
+                               switch(op->Operation) { \
+                               case BC_OP_ADD: val1._field = val1._field + val2._field;        break; \
+                               case BC_OP_SUBTRACT:    val1._field = val1._field - val2._field;        break; \
+                               case BC_OP_MULTIPLY:    val1._field = val1._field * val2._field;        break; \
+                               case BC_OP_DIVIDE:      val1._field = val1._field / val2._field;        break; \
+                               case BC_OP_EQUALS:      val1._field = val1._field == val2._field;       break; \
+                               case BC_OP_LESSTHAN:    val1._field = val1._field < val2._field;        break; \
+                               case BC_OP_LESSTHANOREQUAL:     val1._field = val1._field <= val2._field;       break; \
+                               case BC_OP_GREATERTHAN: val1._field = val1._field > val2._field;        break; \
+                               case BC_OP_GREATERTHANOREQUAL:  val1._field = val1._field >= val2._field;       break; \
+                               \
+                               case BC_OP_BITAND:      val1._field = (int64_t)val1._field & (int64_t)val2._field;      break; \
+                               case BC_OP_BITOR:       val1._field = (int64_t)val1._field | (int64_t)val2._field;      break; \
+                               case BC_OP_BITXOR:      val1._field = (int64_t)val1._field ^ (int64_t)val2._field;      break; \
+                               case BC_OP_MODULO:      val1._field = (int64_t)val1._field % (int64_t)val2._field;      break; \
+                               default:        AST_RuntimeError(NULL, "Invalid operation on datatype %i", _type); nextop = NULL; break;\
+                               }\
+                               PUT_STACKVAL(val1);\
+                               break;\
+                       }
+
+                       PERFORM_NUM_OP(SS_DATATYPE_INTEGER, Integer);
+                       PERFORM_NUM_OP(SS_DATATYPE_REAL, Real);
+               
                        pval1 = Bytecode_int_GetSpiderValue(&val1, &tmpVal1);
                        pval2 = Bytecode_int_GetSpiderValue(&val2, &tmpVal2);
                        Bytecode_int_DerefStackValue(&val1);
index e2f846a..bd29280 100644 (file)
@@ -73,6 +73,7 @@ tSpiderScript *SpiderScript_ParseFile(tSpiderVariant *Variant, const char *Filen
        
        
        // HACK!!
+       #if 1
        // - Save AST to a file
        {
                char    cacheFilename[strlen(Filename)+6+1];
@@ -81,6 +82,7 @@ tSpiderScript *SpiderScript_ParseFile(tSpiderVariant *Variant, const char *Filen
        
                SpiderScript_SaveAST(ret, cacheFilename);       
        }
+       #endif
        // - Save Bytecode too
        {
                char    cacheFilename[strlen(Filename)+6+1];

UCC git Repository :: git.ucc.asn.au