RPA Toolkit
Fixed empty strings. Added RJS_SWI_ABORT macro.
authorMartin Stoilov <martin@rpasearch.com>
Thu, 26 May 2011 04:58:24 +0000 (21:58 -0700)
committerMartin Stoilov <martin@rpasearch.com>
Thu, 26 May 2011 04:58:24 +0000 (21:58 -0700)
rjs/ecma262.rpa
rjs/rjs.h
rjs/rjscompiler.c
rjs/rjscompiler.h
rjs/rjsexec.c
rjs/rjsuids.h

index 9b8a836..3ac4cb0 100644 (file)
@@ -88,6 +88,7 @@
 #!emitid WhileExpressionCompare                        UID_WHILEEXPRESSIONCOMPARE                      58
 #!emitid DoWhileExpressionCompare              UID_DOWHILEEXPRESSIONCOMPARE            59
 #!emitid Program                                               UID_PROGRAM                                             60
+#!emitid StringLiteral                                 UID_STRINGLITERAL                                       61
 
 #!abort SC
 
index 2090c84..d8d46f8 100644 (file)
--- a/rjs/rjs.h
+++ b/rjs/rjs.h
@@ -30,6 +30,8 @@ typedef struct rjs_engine_s {
 #define RJS_VERSION_STRING "0.51.1"
 #define RJS_SWI_PARAM(__cpu__, __n__) RVM_STACK_ADDR((__cpu__)->stack, RVM_CPUREG_GETU(__cpu__, FP) + (__n__))
 #define RJS_SWI_PARAMS(__cpu__) (RVM_CPUREG_GETU((__cpu__), SP) - RVM_CPUREG_GETU((__cpu__), FP))
+#define RJS_SWI_ABORT(__j__, __e__) do { rjs_engine_abort((__j__), (__e__)); return; } while (0)
+
 
 const rchar *rjs_version();
 
index 0d518f0..d11833c 100644 (file)
@@ -11,8 +11,12 @@ static rint rjs_compiler_playchildrecords(rjs_compiler_t *co, rarray_t *records,
 void rjs_compiler_debughead(rjs_compiler_t *co, rarray_t *records, rlong rec)
 {
        if (co->debug) {
-               rpa_record_dump(records, rec);
+               rparecord_t *prec = (rparecord_t *) r_array_slot(records, rec);
                co->headoff = rvm_codegen_getcodesize(co->cg);
+               if (prec->type & RPA_RECORD_START) {
+                       rpa_record_dump(records, rec);
+               }
+
        }
 }
 
@@ -20,7 +24,11 @@ void rjs_compiler_debughead(rjs_compiler_t *co, rarray_t *records, rlong rec)
 void rjs_compiler_debugtail(rjs_compiler_t *co, rarray_t *records, rlong rec)
 {
        if (co->debug) {
+               rparecord_t *prec = (rparecord_t *) r_array_slot(records, rec);
                rvm_asm_dump(rvm_codegen_getcode(co->cg, co->headoff), rvm_codegen_getcodesize(co->cg) - co->headoff);
+               if (prec->type & RPA_RECORD_END) {
+                       rpa_record_dump(records, rec);
+               }
        }
 
 }
@@ -499,16 +507,8 @@ rint rjs_compiler_rh_stringcharacters(rjs_compiler_t *co, rarray_t *records, rlo
 {
        rparecord_t *prec;
        prec = (rparecord_t *)r_array_slot(records, rec);
-       rvmreg_t *strreg = rvm_cpu_alloc_global(co->cpu);
-       rstring_t *s = r_string_create_strsize((const rchar*)prec->input, prec->inputsiz);
-       rvm_gc_add(co->cpu->gc, (robject_t*)s);
-       rvm_reg_setstring(strreg, s);
 
        rjs_compiler_debughead(co, records, rec);
-//     rvm_codegen_addins(co->cg, rvm_asmp(RVM_MOV, R1, DA, XX, (void*)prec->input));
-//     rvm_codegen_addins(co->cg, rvm_asm(RVM_MOV, R2, DA, XX, prec->inputsiz));
-//     rvm_codegen_addins(co->cg, rvm_asm(RVM_ALLOCSTR, R0, R1, R2, 0));
-       rvm_codegen_addins(co->cg, rvm_asmp(RVM_LDRR, R0, DA, XX, strreg));
        rjs_compiler_debugtail(co, records, rec);
 
        if (rjs_compiler_playchildrecords(co, records, rec) < 0)
@@ -517,6 +517,36 @@ rint rjs_compiler_rh_stringcharacters(rjs_compiler_t *co, rarray_t *records, rlo
        rec = rpa_recordtree_get(records, rec, RPA_RECORD_END);
        prec = (rparecord_t *)r_array_slot(records, rec);
        rjs_compiler_debughead(co, records, rec);
+       co->stringcharacters.str = (rchar*)prec->input;
+       co->stringcharacters.size = prec->inputsiz;
+       rjs_compiler_debugtail(co, records, rec);
+       return 0;
+}
+
+
+rint rjs_compiler_rh_stringliteral(rjs_compiler_t *co, rarray_t *records, rlong rec)
+{
+       rparecord_t *prec;
+       prec = (rparecord_t *)r_array_slot(records, rec);
+       rvmreg_t *strreg;
+       rstring_t *s;
+
+       rjs_compiler_debughead(co, records, rec);
+       co->stringcharacters.str = NULL;
+       co->stringcharacters.size = 0;
+       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);
+       strreg = rvm_cpu_alloc_global(co->cpu);
+       s = r_string_create_from_rstr(&co->stringcharacters);
+       rvm_gc_add(co->cpu->gc, (robject_t*)s);
+       rvm_reg_setstring(strreg, s);
+       rvm_codegen_addins(co->cg, rvm_asmp(RVM_LDRR, R0, DA, XX, strreg));
        rjs_compiler_debugtail(co, records, rec);
        return 0;
 }
@@ -1543,6 +1573,8 @@ rjs_compiler_t *rjs_compiler_create(rvmcpu_t *cpu)
        co->handlers[UID_DECIMALINTEGERLITERAL] = rjs_compiler_rh_decimalintegerliteral;
        co->handlers[UID_DECIMALNONINTEGERLITERAL] = rjs_compiler_rh_decimalnonintegerliteral;
        co->handlers[UID_STRINGCHARACTERS] = rjs_compiler_rh_stringcharacters;
+       co->handlers[UID_STRINGLITERAL] = rjs_compiler_rh_stringliteral;
+
        co->handlers[UID_ADDITIVEEXPRESSIONOP] = rjs_compiler_rh_binaryexpressionop;
        co->handlers[UID_MULTIPLICATIVEEXPRESSIONOP] = rjs_compiler_rh_binaryexpressionop;
        co->handlers[UID_BITWISEANDOP] = rjs_compiler_rh_binaryexpressionop;
@@ -1569,7 +1601,6 @@ rjs_compiler_t *rjs_compiler_create(rvmcpu_t *cpu)
        co->handlers[UID_ARGUMENT] = rjs_compiler_rh_argument;
        co->handlers[UID_ARGUMENTS] = rjs_compiler_rh_arguments;
        co->handlers[UID_RETURNSTATEMENT] = rjs_compiler_rh_returnstatement;
-       co->handlers[UID_STRINGCHARACTERS] = rjs_compiler_rh_stringcharacters;
        co->handlers[UID_IFSTATEMENT] = rjs_compiler_rh_ifstatement;
        co->handlers[UID_IFCONDITIONOP] = rjs_compiler_rh_ifconditionop;
        co->handlers[UID_IFTRUESTATEMENT] = rjs_compiler_rh_iftruestatement;
index 95c8e90..ae12dae 100644 (file)
@@ -90,6 +90,7 @@ struct rjs_compiler_s {
        rjs_error_t *error;
        rarray_t *coctx;
        rchar *temp;
+       rstr_t stringcharacters;
        const rchar *script;
        rsize_t scriptsize;
        rlong headoff;
index a9957bd..cc45036 100644 (file)
@@ -48,23 +48,16 @@ static void rjs_exec_ltrim(rvmcpu_t *cpu, rvm_asmins_t *ins)
        rvmreg_t *r = NULL, *l = NULL;
        rstring_t *src, *dest;
 
-       if (RJS_SWI_PARAMS(cpu) == 0) {
-               rjs_engine_abort(rjs_engine_get(cpu), NULL);
-               return;
-       }
+       if (RJS_SWI_PARAMS(cpu) == 0)
+               RJS_SWI_ABORT(rjs_engine_get(cpu), NULL);
        r = (rvmreg_t *) RJS_SWI_PARAM(cpu, 1);
        if (RJS_SWI_PARAMS(cpu) > 1) {
                l = (rvmreg_t *) RJS_SWI_PARAM(cpu, 2);
-               if (rvm_reg_gettype(l) != RVM_DTYPE_STRING) {
-                       rjs_engine_abort(rjs_engine_get(cpu), NULL);
-                       return;
-               }
+               if (rvm_reg_gettype(l) != RVM_DTYPE_STRING)
+                       RJS_SWI_ABORT(rjs_engine_get(cpu), NULL);
        }
-       if (rvm_reg_gettype(r) != RVM_DTYPE_STRING) {
-               rjs_engine_abort(rjs_engine_get(cpu), NULL);
-               return;
-       }
-
+       if (rvm_reg_gettype(r) != RVM_DTYPE_STRING)
+               RJS_SWI_ABORT(rjs_engine_get(cpu), NULL);
        if (l)
                list = ((rstring_t *)RVM_REG_GETP(l))->s.str;
        else
@@ -91,23 +84,16 @@ static void rjs_exec_rtrim(rvmcpu_t *cpu, rvm_asmins_t *ins)
        rvmreg_t *r = NULL, *l = NULL;
        rstring_t *src, *dest;
 
-       if (RJS_SWI_PARAMS(cpu) == 0) {
-               rjs_engine_abort(rjs_engine_get(cpu), NULL);
-               return;
-       }
+       if (RJS_SWI_PARAMS(cpu) == 0)
+               RJS_SWI_ABORT(rjs_engine_get(cpu), NULL);
        r = (rvmreg_t *) RJS_SWI_PARAM(cpu, 1);
        if (RJS_SWI_PARAMS(cpu) > 1) {
                l = (rvmreg_t *) RJS_SWI_PARAM(cpu, 2);
-               if (rvm_reg_gettype(l) != RVM_DTYPE_STRING) {
-                       rjs_engine_abort(rjs_engine_get(cpu), NULL);
-                       return;
-               }
-       }
-       if (rvm_reg_gettype(r) != RVM_DTYPE_STRING) {
-               rjs_engine_abort(rjs_engine_get(cpu), NULL);
-               return;
+               if (rvm_reg_gettype(l) != RVM_DTYPE_STRING)
+                       RJS_SWI_ABORT(rjs_engine_get(cpu), NULL);
        }
-
+       if (rvm_reg_gettype(r) != RVM_DTYPE_STRING)
+               RJS_SWI_ABORT(rjs_engine_get(cpu), NULL);
        if (l)
                list = ((rstring_t *)RVM_REG_GETP(l))->s.str;
        else
@@ -134,23 +120,17 @@ static void rjs_exec_trim(rvmcpu_t *cpu, rvm_asmins_t *ins)
        rvmreg_t *r = NULL, *l = NULL;
        rstring_t *src, *dest;
 
-       if (RJS_SWI_PARAMS(cpu) == 0) {
-               rjs_engine_abort(rjs_engine_get(cpu), NULL);
-               return;
-       }
+       if (RJS_SWI_PARAMS(cpu) == 0)
+               RJS_SWI_ABORT(rjs_engine_get(cpu), NULL);
+
        r = (rvmreg_t *) RJS_SWI_PARAM(cpu, 1);
        if (RJS_SWI_PARAMS(cpu) > 1) {
                l = (rvmreg_t *) RJS_SWI_PARAM(cpu, 2);
-               if (rvm_reg_gettype(l) != RVM_DTYPE_STRING) {
-                       rjs_engine_abort(rjs_engine_get(cpu), NULL);
-                       return;
-               }
-       }
-       if (rvm_reg_gettype(r) != RVM_DTYPE_STRING) {
-               rjs_engine_abort(rjs_engine_get(cpu), NULL);
-               return;
+               if (rvm_reg_gettype(l) != RVM_DTYPE_STRING)
+                       RJS_SWI_ABORT(rjs_engine_get(cpu), NULL);
        }
-
+       if (rvm_reg_gettype(r) != RVM_DTYPE_STRING)
+               RJS_SWI_ABORT(rjs_engine_get(cpu), NULL);
        if (l)
                list = ((rstring_t *)RVM_REG_GETP(l))->s.str;
        else
index 949d858..800ea31 100644 (file)
@@ -1,10 +1,4 @@
 #define UID_SYNTAXERROR 1
-#define UID_FUNCTIONSYNTAXERROR 1
-#define UID_BLOCKSYNTAXERROR 1
-#define UID_GLOBALSYNTAXERROR 1
-#define UID_INDEXSYNTAXERROR 1
-#define UID_MULTIPLICATIVESYNTAXERROR 1
-#define UID_ADDITIVESYNTAXERROR 1
 #define UID_BINARYOPERATOR 2
 #define UID_ADDITIVEOPERATOR 2
 #define UID_MULTIPLICATIVEOPERATOR 2
@@ -81,3 +75,4 @@
 #define UID_WHILEEXPRESSIONCOMPARE 58
 #define UID_DOWHILEEXPRESSIONCOMPARE 59
 #define UID_PROGRAM 60
+#define UID_STRINGLITERAL 61