RPA Toolkit
work on js object implementation
authorMartin Stoilov <martin@rpasearch.com>
Mon, 24 Jan 2011 06:07:40 +0000 (22:07 -0800)
committerMartin Stoilov <martin@rpasearch.com>
Mon, 24 Jan 2011 06:07:40 +0000 (22:07 -0800)
rvm/rvmcpu.c
tests/ecma262.rpa
tests/rpagen-test.c

index 0cc5d49..18af6ae 100644 (file)
@@ -1445,7 +1445,7 @@ static void rvm_op_ldobjn(rvmcpu_t *cpu, rvm_asmins_t *ins)
        rvmreg_t *arg2 = RVM_CPUREG_PTR(cpu, ins->op2);
        rvmreg_t tmp = rvm_reg_create_long(0);
        rjs_object_t *a = NULL;
-       ruint index;
+       rlong index;
 
        rvm_opmap_invoke_binary_handler(cpu->opmap, RVM_OPID_CAST, cpu, &tmp, RVM_CPUREG_PTR(cpu, ins->op3), &tmp);
        index = RVM_REG_GETL(&tmp);
@@ -1462,7 +1462,7 @@ static void rvm_op_stobjn(rvmcpu_t *cpu, rvm_asmins_t *ins)
        rvmreg_t *arg2 = RVM_CPUREG_PTR(cpu, ins->op2);
        rvmreg_t tmp = rvm_reg_create_long(0);
        rjs_object_t *a = NULL;
-       ruint index;
+       rlong index;
 
        rvm_opmap_invoke_binary_handler(cpu->opmap, RVM_OPID_CAST, cpu, &tmp, RVM_CPUREG_PTR(cpu, ins->op3), &tmp);
        index = RVM_REG_GETL(&tmp);
@@ -1519,7 +1519,7 @@ static void rvm_op_objkeylookupadd(rvmcpu_t *cpu, rvm_asmins_t *ins)
        if (rvm_reg_gettype(arg2) != RVM_DTYPE_JSOBJECT) {
                RVM_ABORT(cpu, RVM_E_ILLEGAL);
        }
-       index = r_harray_add(a->harray, RVM_CPUREG_GETP(cpu, ins->op3), RVM_CPUREG_GETL(cpu, ins->op1), NULL);
+       index = r_harray_lookup(a->harray, RVM_CPUREG_GETP(cpu, ins->op3), RVM_CPUREG_GETL(cpu, ins->op1));
        if (index < 0)
                index = r_harray_add(a->harray, RVM_CPUREG_GETP(cpu, ins->op3), RVM_CPUREG_GETL(cpu, ins->op1), NULL);
 
@@ -1554,14 +1554,19 @@ static void rvm_op_ldobjh(rvmcpu_t *cpu, rvm_asmins_t *ins)
        rvmreg_t *arg2 = RVM_CPUREG_PTR(cpu, ins->op2);
        rvmreg_t tmp = rvm_reg_create_long(0);
        rjs_object_t *a = NULL;
-       ruint index;
+       rlong index;
 
        rvm_opmap_invoke_binary_handler(cpu->opmap, RVM_OPID_CAST, cpu, &tmp, RVM_CPUREG_PTR(cpu, ins->op3), &tmp);
        index = RVM_REG_GETL(&tmp);
-       if (index < 0 || rvm_reg_gettype(arg2) != RVM_DTYPE_JSOBJECT)
+       if (rvm_reg_gettype(arg2) != RVM_DTYPE_JSOBJECT)
                RVM_ABORT(cpu, RVM_E_ILLEGAL);
        a = (rjs_object_t*)RVM_REG_GETP(arg2);
-       *arg1 = *((rvmreg_t*)r_carray_slot_expand(a->harray->members, index));
+       if (index < 0) {
+               RVM_REG_CLEAR(arg1);
+               RVM_REG_SETTYPE(arg1, RVM_DTYPE_UNDEF);
+       } else {
+               *arg1 = *((rvmreg_t*)r_carray_slot_expand(a->harray->members, index));
+       }
 }
 
 
@@ -1571,7 +1576,7 @@ static void rvm_op_stobjh(rvmcpu_t *cpu, rvm_asmins_t *ins)
        rvmreg_t *arg2 = RVM_CPUREG_PTR(cpu, ins->op2);
        rvmreg_t tmp = rvm_reg_create_long(0);
        rjs_object_t *a = NULL;
-       ruint index;
+       rlong index;
 
        rvm_opmap_invoke_binary_handler(cpu->opmap, RVM_OPID_CAST, cpu, &tmp, RVM_CPUREG_PTR(cpu, ins->op3), &tmp);
        index = RVM_REG_GETL(&tmp);
index 617c5a5..0008dd5 100644 (file)
@@ -144,10 +144,14 @@ Elision                                                   ::= ',' <S>? <:Elision:> | <S>? ','
 # 11.2 Left-Hand-Side Expressions
 NewKeyword                                             ::= 'new' - 'new' <IdentifierPart>
 
-MemberExpressionIndexBaseOp            ::= <:MemberExpression:>
-MemberExpressionIndexOp                        ::= <:MemberExpressionIndexBaseOp:> <S>? '[' <:S:>? <:Expression:> <:S:>? ']'
+MemberIdentifierNameOp                 ::= <:Identifier:>
+MemberIdentifierNameLookupOp   ::= <:Identifier:>
+MemberExpressionBaseOp                 ::= <:MemberExpression:>
+MemberExpressionIndexOp                        ::= <:MemberExpressionBaseOp:> <S>? '[' <:S:>? <:Expression:> <:S:>? ']'
+MemberExpressionNameOp                 ::= <:MemberExpressionBaseOp:> '.' <:MemberIdentifierNameOp:>
+
 MemberExpression                               ::= <:MemberExpressionIndexOp:>  |
-                                                                       <:MemberExpression:> '.' <:IdentifierName:> |
+                                                                       <:MemberExpressionNameOp:> |
                                                                        <:NewKeyword:> <S>? <:MemberExpression:> <S>? <:ArgumentsOp:> |
                                                                        <:FunctionExpression:> |
                                                                        <:PrimaryExpression:>
@@ -160,11 +164,12 @@ NewExpression                                     ::= <:NewArrayExpression:> |
 
 FunctionCallName                               ::= <:CallExpression:> | <:MemberExpression:>
 CallExpressionOp                               ::= <:FunctionCallName:> <S>? <:ArgumentsOp:>
-CallExpressionIndexBaseOp              ::= <:CallExpression:>
-CallExpressionIndexOp                  ::= <:CallExpressionIndexBaseOp:> <S>? '[' <S>? <:Expression:> <S>? ']'
+CallExpressionBaseOp                   ::= <:CallExpression:>
+CallExpressionIndexOp                  ::= <:CallExpressionBaseOp:> <S>? '[' <S>? <:Expression:> <S>? ']'
+CallExpressionNameOp                   ::= <:CallExpressionBaseOp:> '.' <:MemberIdentifierNameOp:>
 
 CallExpression                                 ::= <:CallExpressionIndexOp:> |
-                                                                       <:CallExpression:> '.' <:IdentifierName:> |
+                                                                       <:CallExpressionNameOp:> |
                                                                        <:CallExpressionOp:>
 
 ArgumentsOp                                            ::= '(' <S>? ')' |
@@ -181,10 +186,11 @@ LeftHandSideExpression                    ::= <:CallExpression:> | <:NewExpression:>
 
 
 # 11.2a Left-Hand-Side Expressions
-ValMemberExpressionIndexBaseOp ::= <:ValMemberExpression:>
-ValMemberExpressionIndexOp             ::= <:ValMemberExpressionIndexBaseOp:> <S>? '[' <:S:>? <:Expression:> <:S:>? ']'
+ValMemberExpressionBaseOp              ::= <:ValMemberExpression:>
+ValMemberExpressionIndexOp             ::= <:ValMemberExpressionBaseOp:> <S>? '[' <:S:>? <:Expression:> <:S:>? ']'
+ValMemberExpressionNameOp              ::= <:ValMemberExpressionBaseOp:> '.' <:MemberIdentifierNameLookupOp:>
 ValMemberExpression                            ::= <:ValMemberExpressionIndexOp:>  |
-                                                                       <:ValMemberExpression:> '.' <:IdentifierName:> |
+                                                                       <:ValMemberExpressionNameOp:> |
                                                                        <:NewKeyword:> <S>? <:ValMemberExpression:> <S>? <:ArgumentsOp:> |
                                                                        <:ValFunctionExpression:> |
                                                                        <:ValPrimaryExpression:>
@@ -197,11 +203,12 @@ ValNewExpression                          ::= <:NewArrayExpression:> |
 
 ValFunctionCallName                            ::= <:ValCallExpression:> | <:ValMemberExpression:>
 ValCallExpressionOp                            ::= <:ValFunctionCallName:> <S>? <:ArgumentsOp:>
-ValCallExpressionIndexBaseOp   ::= <:ValCallExpression:>
-ValCallExpressionIndexOp               ::= <:ValCallExpressionIndexBaseOp:> <S>? '[' <S>? <:Expression:> <S>? ']'
+ValCallExpressionBaseOp                        ::= <:ValCallExpression:>
+ValCallExpressionIndexOp               ::= <:ValCallExpressionBaseOp:> <S>? '[' <S>? <:Expression:> <S>? ']'
+ValCallExpressionNameOp                        ::= <:ValCallExpressionBaseOp:> '.' <:MemberIdentifierNameLookupOp:>
 
 ValCallExpression                              ::= <:ValCallExpressionIndexOp:> |
-                                                                       <:ValCallExpression:> '.' <:IdentifierName:> |
+                                                                       <:ValCallExpressionNameOp:> |
                                                                        <:ValCallExpressionOp:>
                
 ValLeftHandSideExpression              ::= <:ValCallExpression:> | <:ValNewExpression:>
index 43e187d..06336dd 100644 (file)
@@ -776,7 +776,7 @@ int codegen_memberexpressionbase_callback(const char *name, void *userdata, cons
 }
 
 
-int codegen_arrayelementaddress_callback(const char *name, void *userdata, const char *input, unsigned int size, unsigned int reason, const char *start, const char *end)
+int codegen_n_arrayelementaddress_callback(const char *name, void *userdata, const char *input, unsigned int size, unsigned int reason, const char *start, const char *end)
 {
        rvm_compiler_t *co = (rvm_compiler_t *)userdata;
        rulong off = rvm_codegen_getcodesize(co->cg);
@@ -791,6 +791,70 @@ int codegen_arrayelementaddress_callback(const char *name, void *userdata, const
 }
 
 
+int codegen_h_arrayelementaddress_callback(const char *name, void *userdata, const char *input, unsigned int size, unsigned int reason, const char *start, const char *end)
+{
+       rvm_compiler_t *co = (rvm_compiler_t *)userdata;
+       rulong off = rvm_codegen_getcodesize(co->cg);
+
+       rvm_codegen_addins(co->cg, rvm_asm(RVM_POP, R1, XX, XX, 0));    // Supposedly Array Address
+       rvm_codegen_addins(co->cg, rvm_asm(RVM_ADDROBJH, R0, R1, R0, 0));       // Get the address of the element at offset R0
+
+       codegen_print_callback(name, userdata, input, size, reason, start, end);
+       codegen_dump_code(rvm_codegen_getcode(co->cg, off), rvm_codegen_getcodesize(co->cg) - off);
+
+       return size;
+}
+
+
+int codegen_h_arraynamelookupadd_callback(const char *name, void *userdata, const char *input, unsigned int size, unsigned int reason, const char *start, const char *end)
+{
+       rvm_compiler_t *co = (rvm_compiler_t *)userdata;
+       rulong off = rvm_codegen_getcodesize(co->cg);
+
+       rvm_codegen_addins(co->cg, rvm_asm(RVM_LDS, R1, SP, XX, 0));    // Supposedly Array Address
+       rvm_codegen_addins(co->cg, rvm_asm(RVM_MOV, R0, DA, XX, size));
+       rvm_codegen_addins(co->cg, rvm_asmp(RVM_MOV, R2, DA, XX, (void*)input));
+       rvm_codegen_addins(co->cg, rvm_asm(RVM_OBJLKUPADD, R0, R1, R2, 0));     // Get the address of the element at offset R0
+
+       codegen_print_callback(name, userdata, input, size, reason, start, end);
+       codegen_dump_code(rvm_codegen_getcode(co->cg, off), rvm_codegen_getcodesize(co->cg) - off);
+
+       return size;
+}
+
+
+int codegen_h_arraynamelookup_callback(const char *name, void *userdata, const char *input, unsigned int size, unsigned int reason, const char *start, const char *end)
+{
+       rvm_compiler_t *co = (rvm_compiler_t *)userdata;
+       rulong off = rvm_codegen_getcodesize(co->cg);
+
+       rvm_codegen_addins(co->cg, rvm_asm(RVM_LDS, R1, SP, XX, 0));    // Supposedly Array Address
+       rvm_codegen_addins(co->cg, rvm_asm(RVM_MOV, R0, DA, XX, size));
+       rvm_codegen_addins(co->cg, rvm_asmp(RVM_MOV, R2, DA, XX, (void*)input));
+       rvm_codegen_addins(co->cg, rvm_asm(RVM_OBJLKUP, R0, R1, R2, 0));        // Get the address of the element at offset R0
+
+       codegen_print_callback(name, userdata, input, size, reason, start, end);
+       codegen_dump_code(rvm_codegen_getcode(co->cg, off), rvm_codegen_getcodesize(co->cg) - off);
+
+       return size;
+}
+
+
+int codegen_h_arrayelementvalue_callback(const char *name, void *userdata, const char *input, unsigned int size, unsigned int reason, const char *start, const char *end)
+{
+       rvm_compiler_t *co = (rvm_compiler_t *)userdata;
+       rulong off = rvm_codegen_getcodesize(co->cg);
+
+       rvm_codegen_addins(co->cg, rvm_asm(RVM_POP, R1, XX, XX, 0));    // Supposedly Array Address
+       rvm_codegen_addins(co->cg, rvm_asm(RVM_LDOBJH, R0, R1, R0, 0)); // Get the address of the element at offset R0
+
+       codegen_print_callback(name, userdata, input, size, reason, start, end);
+       codegen_dump_code(rvm_codegen_getcode(co->cg, off), rvm_codegen_getcodesize(co->cg) - off);
+
+       return size;
+}
+
+
 int codegen_swiidexist_callback(const char *name, void *userdata, const char *input, unsigned int size, unsigned int reason, const char *start, const char *end)
 {
        rvm_compiler_t *co = (rvm_compiler_t *)userdata;
@@ -1798,17 +1862,25 @@ void rpagen_load_rules(rpa_dbex_handle dbex, rvm_compiler_t *co)
 
        rpa_dbex_add_callback_exact(dbex, "LeftHandSideExpressionPush", RPA_REASON_MATCHED, codegen_push_r0_callback, co);
 
-       rpa_dbex_add_callback_exact(dbex, "MemberExpressionIndexBaseOp", RPA_REASON_MATCHED, codegen_memberexpressionbase_callback, co);
-       rpa_dbex_add_callback_exact(dbex, "MemberExpressionIndexOp", RPA_REASON_MATCHED, codegen_arrayelementaddress_callback, co);
+       rpa_dbex_add_callback_exact(dbex, "MemberExpressionBaseOp", RPA_REASON_MATCHED, codegen_memberexpressionbase_callback, co);
+       rpa_dbex_add_callback_exact(dbex, "MemberExpressionIndexOp", RPA_REASON_MATCHED, codegen_n_arrayelementaddress_callback, co);
+
+       rpa_dbex_add_callback_exact(dbex, "MemberExpressionNameOp", RPA_REASON_MATCHED, codegen_h_arrayelementaddress_callback, co);
+       rpa_dbex_add_callback_exact(dbex, "CallExpressionNameOp", RPA_REASON_MATCHED, codegen_h_arrayelementaddress_callback, co);
+       rpa_dbex_add_callback_exact(dbex, "MemberIdentifierNameOp", RPA_REASON_MATCHED, codegen_h_arraynamelookupadd_callback, co);
+       rpa_dbex_add_callback_exact(dbex, "MemberIdentifierNameLookupOp", RPA_REASON_MATCHED, codegen_h_arraynamelookup_callback, co);
+       rpa_dbex_add_callback_exact(dbex, "ValMemberExpressionNameOp", RPA_REASON_MATCHED, codegen_h_arrayelementvalue_callback, co);
+       rpa_dbex_add_callback_exact(dbex, "ValCallExpressionNameOp", RPA_REASON_MATCHED, codegen_h_arrayelementvalue_callback, co);
+
 
-       rpa_dbex_add_callback_exact(dbex, "ValMemberExpressionIndexBaseOp", RPA_REASON_MATCHED, codegen_push_r0_callback, co);
+       rpa_dbex_add_callback_exact(dbex, "ValMemberExpressionBaseOp", RPA_REASON_MATCHED, codegen_push_r0_callback, co);
        rpa_dbex_add_callback_exact(dbex, "ValMemberExpressionIndexOp", RPA_REASON_MATCHED, codegen_arrayelementvalue_callback, co);
 
        rpa_dbex_add_callback_exact(dbex, "CallExpressionIndexBaseOp", RPA_REASON_MATCHED, codegen_memberexpressionbase_callback, co);
-       rpa_dbex_add_callback_exact(dbex, "CallExpressionIndexOp", RPA_REASON_MATCHED, codegen_arrayelementaddress_callback, co);
+       rpa_dbex_add_callback_exact(dbex, "CallExpressionIndexOp", RPA_REASON_MATCHED, codegen_n_arrayelementaddress_callback, co);
 
 
-       rpa_dbex_add_callback_exact(dbex, "ValCallExpressionIndexBaseOp", RPA_REASON_MATCHED, codegen_push_r0_callback, co);
+       rpa_dbex_add_callback_exact(dbex, "ValCallExpressionBaseOp", RPA_REASON_MATCHED, codegen_push_r0_callback, co);
        rpa_dbex_add_callback_exact(dbex, "ValCallExpressionIndexOp", RPA_REASON_MATCHED, codegen_arrayelementvalue_callback, co);
 
        rpa_dbex_add_callback_exact(dbex, "ConditionalExpression", RPA_REASON_MATCHED, codegen_conditionalexp_callback, co);