RPA Toolkit
implemented java script objects
authorMartin Stoilov <martin@rpasearch.com>
Thu, 27 Jan 2011 04:18:45 +0000 (20:18 -0800)
committerMartin Stoilov <martin@rpasearch.com>
Thu, 27 Jan 2011 04:18:45 +0000 (20:18 -0800)
rvm/rvmcpu.c
tests/ecma262.rpa
tests/ecma262org.rpa
tests/rpagen-test.c

index 18af6ae..7e9a1dc 100644 (file)
@@ -985,6 +985,8 @@ int rvm_asm_dump_reg_to_str(unsigned char reg, char *str, ruint size)
 
        if (reg == XX)
                ret = rvm_snprintf(str, size, "XX ");
+       else if (reg == TP)
+               ret = rvm_snprintf(str, size, "TP ");
        else if (reg == FP)
                ret = rvm_snprintf(str, size, "FP ");
        else if (reg == SP)
@@ -995,10 +997,8 @@ int rvm_asm_dump_reg_to_str(unsigned char reg, char *str, ruint size)
                ret = rvm_snprintf(str, size, "PC ");
        else if (reg == DA)
                ret = rvm_snprintf(str, size, "DA ");
-       else if (reg >= 0 && reg < RVM_REGS_NUM/2)
+       else
                ret = rvm_snprintf(str, size, "R%d ",  reg);
-       else if (reg >= RVM_REGS_NUM/2)
-               ret = rvm_snprintf(str, size, "S%d ",  reg & ((1 << (RVM_OPERAND_BITS-1))-1));
 
        return ret;
 }
@@ -1129,10 +1129,10 @@ static void rvm_cpu_dumpregs(rvm_asmins_t *pi, rvmcpu_t *vm)
        buffer[50] = '\0';
        rvm_printf("%s", buffer);
 
-       rvm_printf("0x%lx(t: %d), 0x%lx, 0x%lx, 0x%lx, 0x%lx, 0x%lx, 0x%lx, 0x%lx, 0x%lx, FP=%ld, SP=%ld, LR=%ld, PC=%ld, DA=0x%lx, S( %c%c%c%c )",
-               RVM_CPUREG_GETU(vm, 0), RVM_CPUREG_GETTYPE(vm, 0), RVM_CPUREG_GETU(vm, 1), RVM_CPUREG_GETU(vm, 2), RVM_CPUREG_GETU(vm, 3),
+       rvm_printf("0x%lx, 0x%lx, 0x%lx, 0x%lx, 0x%lx, 0x%lx, 0x%lx, 0x%lx, 0x%lx, TP=%p, FP=%ld, SP=%ld, LR=%ld, PC=%ld, DA=0x%lx, S( %c%c%c%c )",
+               RVM_CPUREG_GETU(vm, 0), RVM_CPUREG_GETU(vm, 1), RVM_CPUREG_GETU(vm, 2), RVM_CPUREG_GETU(vm, 3),
                RVM_CPUREG_GETU(vm, 4), RVM_CPUREG_GETU(vm, 5), RVM_CPUREG_GETU(vm, 6), RVM_CPUREG_GETU(vm, 7),
-               RVM_CPUREG_GETU(vm, 8), (long int)RVM_CPUREG_GETU(vm, FP), (long int)RVM_CPUREG_GETU(vm, SP),
+               RVM_CPUREG_GETU(vm, 8), RVM_CPUREG_GETP(vm, TP), (long int)RVM_CPUREG_GETU(vm, FP), (long int)RVM_CPUREG_GETU(vm, SP),
                (long int)RVM_CPUREG_GETU(vm, LR), (long int)RVM_CPUREG_GETU(vm, PC), RVM_CPUREG_GETU(vm, DA),
                vm->status & RVM_STATUS_V ? 'V' : '_',
                vm->status & RVM_STATUS_C ? 'C' : '_',
index d92b0dd..25d9292 100644 (file)
@@ -1,10 +1,3 @@
-# Temporary staff
-NewKeyword                             ::= 'new'
-ArrayKeyword                   ::= 'Array'
-NewArrayNoSize                 ::= <S>? <:NewKeyword:> <S> <:ArrayKeyword:> <S>? '(' <S>? ')'
-NewArraySize                   ::= <S>? <:NewKeyword:> <S> <:ArrayKeyword:> <S>? '(' <S>? <:AssignmentExpression:> <S>? ')'
-NewArrayExpression             ::= <:NewArraySize:> | <:NewArrayNoSize:>
-
 # 6 Source Text
 SourceCharacter                ::= .
 
@@ -97,23 +90,24 @@ HexIntegerLiteral                           ::= '0' [xX] <:HexDigit:>+
 HexDigit                                               ::= [0-9a-fA-F]
 
 # 7.8.4 String Literals
-StringLiteral                                  ::= '\"' <:DoubleStringCharacters:>? '\"' |
-                                                               ['] <:SingleStringCharacters:>? [']
+StringLiteral                                  ::= '"' <:DoubleStringCharacters:>? '"' |
+                                                               "'" <:SingleStringCharacters:>? "'"
 
 DoubleStringCharacters                 ::= <DoubleStringCharacter>+
 SingleStringCharacters                 ::= <SingleStringCharacter>+
 
 DoubleStringCharacter                  ::= '\\' <:EscapeSequence:> |
                                                                <:LineContinuation:> |
-                                                               <:SourceCharacter:> - ('\"' | '\\' | <:LineTerminator:>)
+                                                               <:SourceCharacter:> - ('"' | '\\' | <:LineTerminator:>)
 
 SingleStringCharacter                  ::= '\\' <:EscapeSequence:> |
                                                                <:LineContinuation:> |
-                                                               <:SourceCharacter:> - (['] | '\\' | <:LineTerminator:>)
+                                                               <:SourceCharacter:> - ("'" | '\\' | <:LineTerminator:>)
 
 BracketExpressionOp                            ::= '(' <S>? <:Expression:> <S>? ')'
+ThisOp                                                 ::= 'this'
 
-PrimaryExpression                              ::= 'this' | 
+PrimaryExpression                              ::= <:ThisOp:> | 
                                                                '(' <S>? <:Expression:> <S>? ')' |
                                                                <:LiteralOp:> |
                                                                (<;SwiIdExist;> & <:SwiId:>) |
@@ -146,16 +140,17 @@ MemberExpressionNewOp                     ::= <:NewKeyword:> <S>? <:CallExpression:>
 
 MemberExpression                               ::= <:MemberExpressionIndexOp:>  |
                                                                        <:MemberExpressionNameOp:> |
-                                                                       <:MemberExpressionNewOp:> |
                                                                        <:FunctionExpression:> |
                                                                        <:PrimaryExpression:>
 
+NewExpressionCallName                  ::= <:MemberExpression:>
+NewExpressionCallOp                            ::= <:NewKeyword:> <S>? <:NewExpressionCallName:> <S>? <:ArgumentsOp:>?
+NewArrayExpressionOp                   ::= <S>? 'new' <S> ( 'Array' | 'Object') <S>? <ArgumentsOp>?
 
-NewExpression                                  ::= <:NewArrayExpression:> |
-                                                                       <:NewKeyword:> <S>? <:NewExpression:> |
+NewExpression                                  ::= <:NewArrayExpressionOp:> |
+                                                                       <:NewExpressionCallOp:> |
                                                                        <:MemberExpression:>
 
-
 FunctionCallName                               ::= <:CallExpression:> | <:MemberExpression:>
 CallExpressionOp                               ::= <:FunctionCallName:> <S>? <:ArgumentsOp:>
 CallExpressionBaseOp                   ::= <:CallExpression:>
index 3d30ffb..a2b972f 100644 (file)
@@ -199,8 +199,8 @@ PropertyAssignment  ::= <:PropertyName:>  <S>? ':'  <S>? <:AssignmentExpression:>
 
 
 PropertyName           ::= <:IdentifierName:> |
-                           <:StringLiteral:> |
-                           <:NumericLiteral:>
+                                               <:StringLiteral:> |
+                                               <:NumericLiteral:>
 
 PropertySetParameterList::= <:Identifier:>
 
index cdab06e..7a4b817 100644 (file)
@@ -844,6 +844,20 @@ int codegen_swiid_callback(rpa_stat_handle stat, const char *name, void *userdat
 }
 
 
+int codegen_opthis_callback(rpa_stat_handle stat, const char *name, void *userdata, const char *input, unsigned int size, unsigned int reason)
+{
+       rvm_compiler_t *co = (rvm_compiler_t *)userdata;
+       rulong off = rvm_codegen_getcodesize(co->cg);
+
+       rvm_codegen_addins(co->cg, rvm_asm(RVM_MOV, R0, TP, XX, 0));
+       codegen_print_callback(stat, name, userdata, input, size, reason);
+       codegen_dump_code(rvm_codegen_getcode(co->cg, off), rvm_codegen_getcodesize(co->cg) - off);
+
+       return size;
+
+}
+
+
 int codegen_opidentifier_callback(rpa_stat_handle stat, const char *name, void *userdata, const char *input, unsigned int size, unsigned int reason)
 {
        rvm_compiler_t *co = (rvm_compiler_t *)userdata;
@@ -942,28 +956,12 @@ int codegen_varalloc_callback(rpa_stat_handle stat, const char *name, void *user
 }
 
 
-int codegen_newarraysize_callback(rpa_stat_handle stat, const char *name, void *userdata, const char *input, unsigned int size, unsigned int reason)
+int codegen_opnewarray_callback(rpa_stat_handle stat, const char *name, void *userdata, const char *input, unsigned int size, unsigned int reason)
 {
        rvm_compiler_t *co = (rvm_compiler_t *)userdata;
        rulong off = rvm_codegen_getcodesize(co->cg);
 
-       rvm_codegen_addins(co->cg, rvm_asm(RVM_MOV, R1, R0, XX, 0));
-       rvm_codegen_addins(co->cg, rvm_asm(RVM_ALLOCOBJ, R0, R1, XX, 0));
-
-       codegen_print_callback(stat, name, userdata, input, size, reason);
-       codegen_dump_code(rvm_codegen_getcode(co->cg, off), rvm_codegen_getcodesize(co->cg) - off);
-
-       return size;
-}
-
-
-int codegen_newarraynosize_callback(rpa_stat_handle stat, const char *name, void *userdata, const char *input, unsigned int size, unsigned int reason)
-{
-       rvm_compiler_t *co = (rvm_compiler_t *)userdata;
-       rulong off = rvm_codegen_getcodesize(co->cg);
-
-       rvm_codegen_addins(co->cg, rvm_asm(RVM_MOV, R1, DA, XX, 0));
-       rvm_codegen_addins(co->cg, rvm_asm(RVM_ALLOCOBJ, R0, R1, XX, 0));
+       rvm_codegen_addins(co->cg, rvm_asm(RVM_ALLOCOBJ, R0, DA, XX, 0));
 
        codegen_print_callback(stat, name, userdata, input, size, reason);
        codegen_dump_code(rvm_codegen_getcode(co->cg, off), rvm_codegen_getcodesize(co->cg) - off);
@@ -1035,10 +1033,22 @@ int codegen_newkeyword_callback(rpa_stat_handle stat, const char *name, void *us
 }
 
 
-int codegen_newexpression_callback(rpa_stat_handle stat, const char *name, void *userdata, const char *input, unsigned int size, unsigned int reason)
+int codegen_newexpressioncallop_callback(rpa_stat_handle stat, const char *name, void *userdata, const char *input, unsigned int size, unsigned int reason)
 {
        rvm_compiler_t *co = (rvm_compiler_t *)userdata;
        rulong off = rvm_codegen_getcodesize(co->cg);
+       rvm_funcall_t *funcall = r_array_empty(co->funcall) ? NULL : (rvm_funcall_t *) r_array_slot(co->funcall, r_array_length(co->funcall) - 1);
+
+
+       rvm_codegen_addins(co->cg, rvm_asm(RVM_ALLOCOBJ, TP, DA, XX, 0));
+       rvm_codegen_addins(co->cg, rvm_asm(RVM_SUB, FP, SP, DA, funcall->params));
+       rvm_codegen_addins(co->cg, rvm_asm(RVM_LDS, R1, FP, XX, 0));
+       rvm_codegen_addins(co->cg, rvm_asm(RVM_STS, LR, FP, XX, 0));
+       rvm_codegen_addins(co->cg, rvm_asm(RVM_CALL, R1, DA, XX, -rvm_codegen_getcodesize(co->cg)));
+       rvm_codegen_addins(co->cg, rvm_asm(RVM_MOV, SP, FP, XX, 0));
+       rvm_codegen_addins(co->cg, rvm_asm(RVM_MOV, R0, TP, XX, 0));
+       rvm_codegen_addins(co->cg, rvm_asm(RVM_POPM, DA, XX, XX, BITS(TP,LR)));
+
 
 
        codegen_print_callback(stat, name, userdata, input, size, reason);
@@ -1052,6 +1062,7 @@ int codegen_funcallname_callback(rpa_stat_handle stat, const char *name, void *u
 {
        rvm_compiler_t *co = (rvm_compiler_t *)userdata;
        rulong off = rvm_codegen_getcodesize(co->cg);
+       rvm_asmins_t *last = rvm_codegen_getcode(co->cg, off - 1);
        rvm_funcall_t funcall = {input, size, 0};
 
        r_array_add(co->funcall, &funcall);
@@ -1062,7 +1073,17 @@ int codegen_funcallname_callback(rpa_stat_handle stat, const char *name, void *u
         * and FP will point there. After the call we save the LR at that spot
         * as we don't need the RO anymore.
         */
-       rvm_codegen_addins(co->cg, rvm_asm(RVM_PUSHM, DA, XX, XX, BIT(TP)|BIT(FP)|BIT(SP)));
+
+       if (last->op1 == R0 && last->op2 == R1 && (last->opcode == RVM_LDOBJN || last->opcode == RVM_LDOBJH)) {
+               /*
+                * The function call id is comming from an object, so we set the this pointer (TP)
+                * to point to the object (R1)
+                */
+               rvm_codegen_addins(co->cg, rvm_asm(RVM_PUSHM, DA, XX, XX, BIT(TP)|BIT(FP)|BIT(SP)));
+               rvm_codegen_addins(co->cg, rvm_asm(RVM_MOV, TP, R1, XX, 0));
+       } else {
+               rvm_codegen_addins(co->cg, rvm_asm(RVM_PUSHM, DA, XX, XX, BIT(TP)|BIT(FP)|BIT(SP)));
+       }
        rvm_codegen_addins(co->cg, rvm_asm(RVM_PUSH, R0, XX, XX, 0));
 
        codegen_print_callback(stat, name, userdata, input, size, reason);
@@ -1566,27 +1587,6 @@ int codegen_iterationforop_callback(rpa_stat_handle stat, const char *name, void
 }
 
 
-int codegen_newexpressionop_callback(rpa_stat_handle stat, const char *name, void *userdata, const char *input, unsigned int size, unsigned int reason)
-{
-       rvm_compiler_t *co = (rvm_compiler_t *)userdata;
-       rulong off = rvm_codegen_getcodesize(co->cg);
-
-       if (reason & RPA_REASON_START) {
-
-       } else  if (reason & RPA_REASON_MATCHED) {
-
-       }
-
-
-       rvm_codegen_addins(co->cg, rvm_asm(RVM_NOP, XX, XX, XX, 0));
-
-
-       codegen_print_callback(stat, name, userdata, input, size, reason);
-       codegen_dump_code(rvm_codegen_getcode(co->cg, off), rvm_codegen_getcodesize(co->cg) - off);
-       return size;
-}
-
-
 void codegen_unmap_file(rstr_t *buf)
 {
        if (buf) {
@@ -1813,6 +1813,7 @@ void rpagen_load_rules(rpa_dbex_handle dbex, rvm_compiler_t *co)
 
        ////////////////
 
+       rpa_dbex_add_callback_exact(dbex, "ThisOp", RPA_REASON_MATCHED, codegen_opthis_callback, co);
        rpa_dbex_add_callback_exact(dbex, "IdentifierOp", RPA_REASON_MATCHED, codegen_opidentifier_callback, co);
        rpa_dbex_add_callback_exact(dbex, "MemberIdentifierNameOp", RPA_REASON_MATCHED, codegen_h_arraynamelookup_callback, co);
        rpa_dbex_add_callback_exact(dbex, "MemberExpressionBaseOp", RPA_REASON_MATCHED, codegen_push_r0_callback, co);
@@ -1827,8 +1828,7 @@ void rpagen_load_rules(rpa_dbex_handle dbex, rvm_compiler_t *co)
 
 
        rpa_dbex_add_callback_exact(dbex, "ConditionalExpression", RPA_REASON_MATCHED, codegen_conditionalexp_callback, co);
-       rpa_dbex_add_callback_exact(dbex, "NewArraySize", RPA_REASON_MATCHED, codegen_newarraysize_callback, co);
-       rpa_dbex_add_callback_exact(dbex, "NewArrayNoSize", RPA_REASON_MATCHED, codegen_newarraynosize_callback, co);
+       rpa_dbex_add_callback_exact(dbex, "NewArrayExpressionOp", RPA_REASON_MATCHED, codegen_opnewarray_callback, co);
        rpa_dbex_add_callback_exact(dbex, "compile_error", RPA_REASON_MATCHED, codegen_compile_error_callback, co);
 
        rpa_dbex_add_callback_exact(dbex, "ArgumentsOp", RPA_REASON_ALL, codegen_costate_callback, co);
@@ -1844,7 +1844,9 @@ void rpagen_load_rules(rpa_dbex_handle dbex, rvm_compiler_t *co)
        rpa_dbex_add_callback_exact(dbex, "FunctionCallName", RPA_REASON_MATCHED, codegen_funcallname_callback, co);
        rpa_dbex_add_callback_exact(dbex, "CallExpressionOp", RPA_REASON_MATCHED, codegen_funcallexpression_callback, co);
        rpa_dbex_add_callback_exact(dbex, "NewKeyword", RPA_REASON_MATCHED, codegen_newkeyword_callback, co);
-       rpa_dbex_add_callback_exact(dbex, "MemberExpressionNewOp", RPA_REASON_MATCHED, codegen_newexpression_callback, co);
+
+       rpa_dbex_add_callback_exact(dbex, "NewExpressionCallName", RPA_REASON_MATCHED, codegen_funcallname_callback, co);
+       rpa_dbex_add_callback_exact(dbex, "NewExpressionCallOp", RPA_REASON_MATCHED, codegen_newexpressioncallop_callback, co);
 
 
        rpa_dbex_add_callback_exact(dbex, "IfConditionOp", RPA_REASON_MATCHED, codegen_ifconditionop_callback, co);
@@ -1867,7 +1869,6 @@ void rpagen_load_rules(rpa_dbex_handle dbex, rvm_compiler_t *co)
        rpa_dbex_add_callback_exact(dbex, "BreakOp", RPA_REASON_MATCHED, codegen_breakkeyword_callback, co);
        rpa_dbex_add_callback_exact(dbex, "ContinueOp", RPA_REASON_MATCHED, codegen_continuekeyword_callback, co);
 
-       rpa_dbex_add_callback_exact(dbex, "NewExpressionOp", RPA_REASON_ALL, codegen_newexpressionop_callback, co);
 
        if (verboseinfo)
                rpa_dbex_add_callback(dbex, ".*", RPA_REASON_MATCHED, codegen_print_callback, co);