RPA Toolkit
Fixed RJS string comparison
authorMartin Stoilov <martin@rpasearch.com>
Wed, 3 Aug 2011 05:02:56 +0000 (22:02 -0700)
committerMartin Stoilov <martin@rpasearch.com>
Wed, 3 Aug 2011 05:02:56 +0000 (22:02 -0700)
rjs/rjsexec.c
rvm/rvmoperatorbin.c
rvm/rvmoperatoreq.c
rvm/rvmoperatoreq.h
rvm/rvmoperatornoteq.c
rvm/rvmoperatornoteq.h

index 2908593..1aecd9a 100644 (file)
@@ -309,7 +309,6 @@ int main(int argc, char *argv[])
                if (r_strcmp(argv[i], "-f") == 0) {
                        if (++i < argc) {
                                script = rjs_file_map(argv[i]);
-                               r_printf("%s\n", script->str);
                                if (script) {
                                        unmapscript = script;
                                }
index e9e22d8..091a998 100644 (file)
@@ -225,20 +225,6 @@ void rvm_op_binary_init(rvm_opmap_t *opmap)
                binary_operations[i].double_binop_fun = rvm_op_abort_double;
        }
 
-       rvm_op_binary_insert(opmap, RVM_OPID_ADD, rvm_op_add_unsigned, rvm_op_add_signed, rvm_op_add_double);
-       /*
-        * Overwrite RVM_OPID_ADD for string concatenation
-        */
-
-       rvm_opmap_set_binary_handler(opmap, RVM_OPID_ADD, rvm_op_concat_string_string, RVM_DTYPE_STRING, RVM_DTYPE_STRING);
-       rvm_opmap_set_binary_handler(opmap, RVM_OPID_ADD, rvm_op_concat_string_signed, RVM_DTYPE_STRING, RVM_DTYPE_SINGED);
-       rvm_opmap_set_binary_handler(opmap, RVM_OPID_ADD, rvm_op_concat_string_signed, RVM_DTYPE_STRING, RVM_DTYPE_UNSIGNED);
-       rvm_opmap_set_binary_handler(opmap, RVM_OPID_ADD, rvm_op_concat_signed_string, RVM_DTYPE_SINGED, RVM_DTYPE_STRING);
-       rvm_opmap_set_binary_handler(opmap, RVM_OPID_ADD, rvm_op_concat_signed_string, RVM_DTYPE_UNSIGNED, RVM_DTYPE_STRING);
-       rvm_opmap_set_binary_handler(opmap, RVM_OPID_ADD, rvm_op_concat_string_double, RVM_DTYPE_STRING, RVM_DTYPE_DOUBLE);
-       rvm_opmap_set_binary_handler(opmap, RVM_OPID_ADD, rvm_op_concat_double_string, RVM_DTYPE_DOUBLE, RVM_DTYPE_STRING);
-
-
        rvm_op_binary_insert(opmap, RVM_OPID_SUB, rvm_op_sub_unsigned, rvm_op_sub_signed, rvm_op_sub_double);
        rvm_op_binary_insert(opmap, RVM_OPID_MUL, rvm_op_mul_unsigned, rvm_op_mul_signed, rvm_op_mul_double);
        rvm_op_binary_insert(opmap, RVM_OPID_DIV, rvm_op_div_unsigned, rvm_op_div_signed, rvm_op_div_double);
@@ -253,10 +239,28 @@ void rvm_op_binary_init(rvm_opmap_t *opmap)
        rvm_op_binary_insert(opmap, RVM_OPID_MOD, rvm_op_mod_unsigned, rvm_op_mod_signed, rvm_op_mod_double);
        rvm_op_binary_insert(opmap, RVM_OPID_LOGICOR, rvm_op_logicor_unsigned, rvm_op_logicor_signed, rvm_op_logicor_double);
        rvm_op_binary_insert(opmap, RVM_OPID_LOGICAND, rvm_op_logicand_unsigned, rvm_op_logicand_signed, rvm_op_logicand_double);
-       rvm_op_binary_insert(opmap, RVM_OPID_EQ, rvm_op_eq_unsigned, rvm_op_eq_signed, rvm_op_eq_double);
        rvm_op_binary_insert(opmap, RVM_OPID_NOTEQ, rvm_op_noteq_unsigned, rvm_op_noteq_signed, rvm_op_noteq_double);
        rvm_op_binary_insert(opmap, RVM_OPID_LESS, rvm_op_less_unsigned, rvm_op_less_signed, rvm_op_less_double);
        rvm_op_binary_insert(opmap, RVM_OPID_LESSEQ, rvm_op_lesseq_unsigned, rvm_op_lesseq_signed, rvm_op_lesseq_double);
        rvm_op_binary_insert(opmap, RVM_OPID_GREATER, rvm_op_greater_unsigned, rvm_op_greater_signed, rvm_op_greater_double);
        rvm_op_binary_insert(opmap, RVM_OPID_GREATEREQ, rvm_op_greatereq_unsigned, rvm_op_greatereq_signed, rvm_op_greatereq_double);
+
+       rvm_op_binary_insert(opmap, RVM_OPID_ADD, rvm_op_add_unsigned, rvm_op_add_signed, rvm_op_add_double);
+       /*
+        * Overwrite RVM_OPID_ADD for string concatenation
+        */
+       rvm_opmap_set_binary_handler(opmap, RVM_OPID_ADD, rvm_op_concat_string_string, RVM_DTYPE_STRING, RVM_DTYPE_STRING);
+       rvm_opmap_set_binary_handler(opmap, RVM_OPID_ADD, rvm_op_concat_string_signed, RVM_DTYPE_STRING, RVM_DTYPE_SINGED);
+       rvm_opmap_set_binary_handler(opmap, RVM_OPID_ADD, rvm_op_concat_string_signed, RVM_DTYPE_STRING, RVM_DTYPE_UNSIGNED);
+       rvm_opmap_set_binary_handler(opmap, RVM_OPID_ADD, rvm_op_concat_signed_string, RVM_DTYPE_SINGED, RVM_DTYPE_STRING);
+       rvm_opmap_set_binary_handler(opmap, RVM_OPID_ADD, rvm_op_concat_signed_string, RVM_DTYPE_UNSIGNED, RVM_DTYPE_STRING);
+       rvm_opmap_set_binary_handler(opmap, RVM_OPID_ADD, rvm_op_concat_string_double, RVM_DTYPE_STRING, RVM_DTYPE_DOUBLE);
+       rvm_opmap_set_binary_handler(opmap, RVM_OPID_ADD, rvm_op_concat_double_string, RVM_DTYPE_DOUBLE, RVM_DTYPE_STRING);
+
+       rvm_op_binary_insert(opmap, RVM_OPID_EQ, rvm_op_eq_unsigned, rvm_op_eq_signed, rvm_op_eq_double);
+       rvm_opmap_set_binary_handler(opmap, RVM_OPID_EQ, rvm_op_eq_string_string, RVM_DTYPE_STRING, RVM_DTYPE_STRING);
+
+       rvm_op_binary_insert(opmap, RVM_OPID_NOTEQ, rvm_op_noteq_unsigned, rvm_op_noteq_signed, rvm_op_noteq_double);
+       rvm_opmap_set_binary_handler(opmap, RVM_OPID_NOTEQ, rvm_op_noteq_string_string, RVM_DTYPE_STRING, RVM_DTYPE_STRING);
+
 }
index 5de3b27..4d12741 100644 (file)
@@ -53,3 +53,27 @@ void rvm_op_eq_double(rvmcpu_t *cpu, ruint16 opid, rvmreg_t *res, double op1, do
        RVM_REG_SETTYPE(res, RVM_DTYPE_BOOLEAN);
        RVM_STATUS_UPDATE(cpu, RVM_STATUS_Z, !r);
 }
+
+
+void rvm_op_eq_string(rvmcpu_t *cpu, ruint16 opid, rvmreg_t *res, double op1, double op2)
+{
+       ruword r;
+
+       r = (op1 == op2) ? 1 : 0;
+       RVM_REG_SETU(res, r);
+       RVM_REG_SETTYPE(res, RVM_DTYPE_BOOLEAN);
+       RVM_STATUS_UPDATE(cpu, RVM_STATUS_Z, !r);
+}
+
+
+void rvm_op_eq_string_string(rvmcpu_t *cpu, ruint16 opid, rvmreg_t *res, const rvmreg_t *arg1, const rvmreg_t *arg2)
+{
+       ruword r;
+       rstring_t *s1 = (rstring_t *)RVM_REG_GETP(arg1);
+       rstring_t *s2 = (rstring_t *)RVM_REG_GETP(arg2);
+
+       r = (s1->s.size ==  s2->s.size && r_strncmp(s1->s.str, s2->s.str, s1->s.size) == 0) ? 1 : 0;
+       rvm_reg_setboolean(res, r);
+       RVM_STATUS_UPDATE(cpu, RVM_STATUS_Z, !r);
+}
+
index 89f613a..45f6c96 100644 (file)
@@ -31,6 +31,7 @@ extern "C" {
 void rvm_op_eq_unsigned(rvmcpu_t *cpu, ruint16 opid, rvmreg_t *res, ruword op1, ruword op2);
 void rvm_op_eq_signed(rvmcpu_t *cpu, ruint16 opid, rvmreg_t *res, rword op1, rword op2);
 void rvm_op_eq_double(rvmcpu_t *cpu, ruint16 opid, rvmreg_t *res, double op1, double op2);
+void rvm_op_eq_string_string(rvmcpu_t *cpu, ruint16 opid, rvmreg_t *res, const rvmreg_t *arg1, const rvmreg_t *arg2);
 
 #ifdef __cplusplus
 }
index 30854c8..a9ffc2a 100644 (file)
@@ -53,3 +53,15 @@ void rvm_op_noteq_double(rvmcpu_t *cpu, ruint16 opid, rvmreg_t *res, double op1,
        RVM_REG_SETTYPE(res, RVM_DTYPE_BOOLEAN);
        RVM_STATUS_UPDATE(cpu, RVM_STATUS_Z, !r);
 }
+
+
+void rvm_op_noteq_string_string(rvmcpu_t *cpu, ruint16 opid, rvmreg_t *res, const rvmreg_t *arg1, const rvmreg_t *arg2)
+{
+       ruword r;
+       rstring_t *s1 = (rstring_t *)RVM_REG_GETP(arg1);
+       rstring_t *s2 = (rstring_t *)RVM_REG_GETP(arg2);
+
+       r = (s1->s.size ==  s2->s.size && r_strncmp(s1->s.str, s2->s.str, s1->s.size) == 0) ? 0 : 1;
+       rvm_reg_setboolean(res, r);
+       RVM_STATUS_UPDATE(cpu, RVM_STATUS_Z, !r);
+}
index d75dfb6..90c73ad 100644 (file)
@@ -31,6 +31,7 @@ extern "C" {
 void rvm_op_noteq_unsigned(rvmcpu_t *cpu, ruint16 opid, rvmreg_t *res, ruword op1, ruword op2);
 void rvm_op_noteq_signed(rvmcpu_t *cpu, ruint16 opid, rvmreg_t *res, rword op1, rword op2);
 void rvm_op_noteq_double(rvmcpu_t *cpu, ruint16 opid, rvmreg_t *res, double op1, double op2);
+void rvm_op_noteq_string_string(rvmcpu_t *cpu, ruint16 opid, rvmreg_t *res, const rvmreg_t *arg1, const rvmreg_t *arg2);
 
 #ifdef __cplusplus
 }