RPA Toolkit
Work on the RJS compiler
authorMartin Stoilov <martin@rpasearch.com>
Wed, 4 May 2011 04:33:11 +0000 (21:33 -0700)
committerMartin Stoilov <martin@rpasearch.com>
Wed, 4 May 2011 04:33:11 +0000 (21:33 -0700)
rjs/rjscompiler.c
rpa2/rparecord.c
rpa2/rparecord.h
rvm/rvmcpu.c

index 0e42aea..8a8cf0c 100644 (file)
@@ -338,9 +338,9 @@ rint rjs_compiler_rh_identifier(rjs_compiler_t *co, rarray_t *records, rlong rec
                 * If this is the last child of UID_LEFTHANDSIDEEXPRESSIONADDR
                 */
                if (v->datatype == VARMAP_DATATYPE_OFFSET) {
                 * If this is the last child of UID_LEFTHANDSIDEEXPRESSIONADDR
                 */
                if (v->datatype == VARMAP_DATATYPE_OFFSET) {
-                       rvm_codegen_addins(co->cg, rvm_asm(RVM_ADDRS, R1, FP, DA, v->data.offset));
+                       rvm_codegen_addins(co->cg, rvm_asm(RVM_ADDRS, R0, FP, DA, v->data.offset));
                } else {
                } else {
-                       rvm_codegen_addins(co->cg, rvm_asmp(RVM_MOV, R1, DA, XX, v->data.ptr));
+                       rvm_codegen_addins(co->cg, rvm_asmp(RVM_MOV, R0, DA, XX, v->data.ptr));
                }
        } else {
                if (v->datatype == VARMAP_DATATYPE_OFFSET) {
                }
        } else {
                if (v->datatype == VARMAP_DATATYPE_OFFSET) {
@@ -404,7 +404,7 @@ rint rjs_compiler_rh_lefthandsideexpressionaddr(rjs_compiler_t *co, rarray_t *re
        rec = rpa_recordtree_get(records, rec, RPA_RECORD_END);
        prec = (rparecord_t *)r_array_slot(records, rec);
        rjs_compiler_debughead(co, records, rec);
        rec = rpa_recordtree_get(records, rec, RPA_RECORD_END);
        prec = (rparecord_t *)r_array_slot(records, rec);
        rjs_compiler_debughead(co, records, rec);
-       rvm_codegen_addins(co->cg, rvm_asmp(RVM_PUSH, R1, XX, XX, 0));
+       rvm_codegen_addins(co->cg, rvm_asmp(RVM_PUSH, R0, XX, XX, 0));
        rjs_compiler_debugtail(co, records, rec);
        return 0;
 }
        rjs_compiler_debugtail(co, records, rec);
        return 0;
 }
@@ -527,6 +527,36 @@ rint rjs_compiler_rh_newarrayexpression(rjs_compiler_t *co, rarray_t *records, r
 }
 
 
 }
 
 
+rint rjs_compiler_rh_memberexpressiondotop(rjs_compiler_t *co, rarray_t *records, rlong rec)
+{
+       rparecord_t *prec;
+       prec = (rparecord_t *)r_array_slot(records, rec);
+       rjs_compiler_debughead(co, records, rec);
+       rjs_compiler_debugtail(co, records, rec);
+
+       if (rjs_compiler_playchildrecords(co, records, rec) < 0)
+               return -1;
+
+       rec = rpa_recordtree_get(records, rec, RPA_RECORD_END);
+       prec = (rparecord_t *)r_array_slot(records, rec);
+       rjs_compiler_debughead(co, records, rec);
+       if (rpa_record_getruleuid(records, rpa_recordtree_parent(records, rec, RPA_RECORD_START)) == UID_LEFTHANDSIDEEXPRESSIONADDR &&
+               rpa_recordtree_next(records, rec, RPA_RECORD_START) == -1) {
+               rvm_codegen_addins(co->cg, rvm_asm(RVM_POP, R1, XX, XX, 0));    // Supposedly Array Address
+               rvm_codegen_addins(co->cg, rvm_asm(RVM_MOV, R0, DA, XX, prec->inputsiz));
+               rvm_codegen_addins(co->cg, rvm_asmp(RVM_MOV, R2, DA, XX, (void*)prec->input));
+               rvm_codegen_addins(co->cg, rvm_asm(RVM_OBJLKUPADD, R0, R1, R2, 0));     // Get the address of the element at offset R0
+       } else {
+               rvm_codegen_addins(co->cg, rvm_asm(RVM_POP, R1, XX, XX, 0));    // Supposedly Array Address
+               rvm_codegen_addins(co->cg, rvm_asm(RVM_MOV, R0, DA, XX, prec->inputsiz));
+               rvm_codegen_addins(co->cg, rvm_asmp(RVM_MOV, R2, DA, XX, (void*)prec->input));
+               rvm_codegen_addins(co->cg, rvm_asm(RVM_OBJLKUP, R0, R1, R2, 0));        // Get the address of the element at offset R0
+       }
+       rjs_compiler_debugtail(co, records, rec);
+       return 0;
+}
+
+
 rint rjs_compiler_rh_(rjs_compiler_t *co, rarray_t *records, rlong rec)
 {
        rparecord_t *prec;
 rint rjs_compiler_rh_(rjs_compiler_t *co, rarray_t *records, rlong rec)
 {
        rparecord_t *prec;
@@ -577,6 +607,7 @@ rjs_compiler_t *rjs_compiler_create(rvmcpu_t *cpu)
        co->handlers[UID_INITIALISER] = rjs_compiler_rh_initializer;
        co->handlers[UID_ASSIGNMENTEXPRESSIONOP] = rjs_compiler_rh_assignmentexpressionop;
        co->handlers[UID_NEWARRAYEXPRESSION] = rjs_compiler_rh_newarrayexpression;
        co->handlers[UID_INITIALISER] = rjs_compiler_rh_initializer;
        co->handlers[UID_ASSIGNMENTEXPRESSIONOP] = rjs_compiler_rh_assignmentexpressionop;
        co->handlers[UID_NEWARRAYEXPRESSION] = rjs_compiler_rh_newarrayexpression;
+       co->handlers[UID_MEMBEREXPRESSIONDOTOP] = rjs_compiler_rh_memberexpressiondotop;
 
        return co;
 }
 
        return co;
 }
index d4c7263..8bcffcc 100644 (file)
@@ -262,10 +262,26 @@ static void rpa_recordptr_setusertype(rparecord_t *prec, ruint32 usertype, rvals
 }
 
 
 }
 
 
+rlong rpa_record_getruleuid(rarray_t *records, rlong rec)
+{
+       rparecord_t *prec;
+
+       if (rec < 0)
+               return -1;
+       rec = rpa_recordtree_get(records, rec, RPA_RECORD_START);
+       if (rec >= r_array_length(records))
+               return -1;
+       prec = (rparecord_t *)r_array_slot(records, rec);
+       return prec->ruleuid;
+}
+
+
 void rpa_record_setusertype(rarray_t *records, rlong rec, ruint32 usertype, rvalset_t op)
 {
        rparecord_t *prec;
 
 void rpa_record_setusertype(rarray_t *records, rlong rec, ruint32 usertype, rvalset_t op)
 {
        rparecord_t *prec;
 
+       if (rec < 0)
+               return;
        rec = rpa_recordtree_get(records, rec, RPA_RECORD_START);
        if (rec >= r_array_length(records))
                return;
        rec = rpa_recordtree_get(records, rec, RPA_RECORD_START);
        if (rec >= r_array_length(records))
                return;
@@ -283,6 +299,8 @@ rlong rpa_record_getusertype(rarray_t *records, rlong rec)
 {
        rparecord_t *prec;
 
 {
        rparecord_t *prec;
 
+       if (rec < 0)
+               return -1;
        rec = rpa_recordtree_get(records, rec, RPA_RECORD_START);
        if (rec >= r_array_length(records))
                return -1;
        rec = rpa_recordtree_get(records, rec, RPA_RECORD_START);
        if (rec >= r_array_length(records))
                return -1;
index dd1ff55..b7c22bb 100644 (file)
@@ -50,6 +50,7 @@ rparecord_t *rpa_record_get(rarray_t *records, rlong rec);
 
 void rpa_record_dumpindented(rarray_t *records, rlong rec, rint level);
 void rpa_record_dump(rarray_t *records, rlong rec);
 
 void rpa_record_dumpindented(rarray_t *records, rlong rec, rint level);
 void rpa_record_dump(rarray_t *records, rlong rec);
+rlong rpa_record_getruleuid(rarray_t *records, rlong rec);
 void rpa_record_setusertype(rarray_t *records, rlong rec, ruint32 usertype, rvalset_t op);
 rlong rpa_record_getusertype(rarray_t *records, rlong rec);
 rint rpa_record_optchar(rparecord_t *prec, rint defc);
 void rpa_record_setusertype(rarray_t *records, rlong rec, ruint32 usertype, rvalset_t op);
 rlong rpa_record_getusertype(rarray_t *records, rlong rec);
 rint rpa_record_optchar(rparecord_t *prec, rint defc);
index 7dcf7bd..6bbfaba 100644 (file)
@@ -1126,6 +1126,8 @@ static void rvm_op_prn(rvmcpu_t *cpu, rvm_asmins_t *ins)
                rvm_printf("(STRING) R%d = %s\n", ins->op1, ((rstring_t*) RVM_REG_GETP(r))->s.str);
        else if (rvm_reg_gettype(r) == RVM_DTYPE_ARRAY)
                rvm_printf("(ARRAY) R%d = %p\n", ins->op1, RVM_REG_GETP(r));
                rvm_printf("(STRING) R%d = %s\n", ins->op1, ((rstring_t*) RVM_REG_GETP(r))->s.str);
        else if (rvm_reg_gettype(r) == RVM_DTYPE_ARRAY)
                rvm_printf("(ARRAY) R%d = %p\n", ins->op1, RVM_REG_GETP(r));
+       else if (rvm_reg_gettype(r) == RVM_DTYPE_JSOBJECT)
+               rvm_printf("(Object) R%d = %p\n", ins->op1, RVM_REG_GETP(r));
        else if (rvm_reg_gettype(r) == RVM_DTYPE_SWIID)
                rvm_printf("(SWI) R%d = %p\n", ins->op1, RVM_REG_GETP(r));
        else
        else if (rvm_reg_gettype(r) == RVM_DTYPE_SWIID)
                rvm_printf("(SWI) R%d = %p\n", ins->op1, RVM_REG_GETP(r));
        else