RPA Toolkit
added optimization to reduce the size of the garbage records
authorMartin Stoilov <martin@rpasearch.com>
Sun, 24 Apr 2011 23:40:32 +0000 (16:40 -0700)
committerMartin Stoilov <martin@rpasearch.com>
Sun, 24 Apr 2011 23:40:32 +0000 (16:40 -0700)
rgrep/ecma262.rpa
rpa2/rparecord.c
rpa2/rparecord.h
rpa2/rpavm.c

index d3fc18c..6f6045f 100644 (file)
@@ -1,4 +1,71 @@
 #!emitall
+#!emitnone
+#!emit BitwiseANDOp
+#!emit BitwiseXOROp
+#!emit BitwiseOROp
+#!emit AdditiveExpressionOp
+
+#!emit MultiplicativeExpressionOp
+#!emit ShiftExpressionOp
+#!emit EqualityExpressionOp
+#!emit RelationalExpressionOp
+#!emit LogicalOROp
+#!emit LogicalANDOp
+
+#!emit AssignmentOperator
+#!emit EqualityOperator
+#!emit RelationalOperator
+#!emit AdditiveOperator
+#!emit MultiplicativeOperator
+#!emit ShiftOperator
+#!emit BitwiseANDOperator
+#!emit BitwiseXOROperator
+#!emit BitwiseOROperator
+#!emit LogicalANDOperator
+#!emit LogicalOROperator
+#!emit LogicalNotOperator
+#!emit BitwiseNotOperator
+#!emit UnaryOperatorOpcode
+#!emit PrintOp
+
+
+#!emit PostfixOperator
+#!emit PostfixExpressionOp
+#!emit PrefixExpressionOp
+
+
+#!emit UnaryExpressionOp
+#!emit LogicalNotExpressionOp
+#!emit BitwiseNotExpressionOp
+
+#!emit DecimalIntegerLiteral
+#!emit DecimalNonIntegerLiteral
+#!emit BlockBegin
+#!emit BlockEnd
+
+#!emit DoKeyword
+#!emit IterationDo
+
+#!emit sqstring
+#!emit dqstring
+#!emit DoubleStringCharacters
+#!emit SingleStringCharacters
+#!emit Program
+#!emit Initialiser
+#!emit AssignmentExpressionOp
+
+#!emit VariableAllocate
+#!emit VariableAllocateAndInit
+
+#!emit ReturnOp
+
+#!emit SwiId
+#!emit SwiIdExist
+
+#!emit PostfixExpressionValOp
+#!emit LeftHandSideExpressionPush
+
+
 
 # 6 Source Text
 SourceCharacter                ::= .
index 0706270..3a8ea8e 100644 (file)
@@ -2,6 +2,19 @@
 #include "rstring.h"
 #include "rparecord.h"
 
+static rparecord_t *rpa_record_get(rarray_t *records, rlong rec)
+{
+       rparecord_t *prec;
+
+       if (!records)
+               return NULL;
+       if (rec < 0 || rec >= r_array_length(records))
+               return NULL;
+       prec = (rparecord_t *)r_array_slot(records, rec);
+       return prec;
+
+}
+
 
 rlong rpa_recordtree_get(rarray_t *records, rlong rec, rulong type)
 {
@@ -194,6 +207,31 @@ rlong rpa_recordtree_rotateup(rarray_t *records, rlong parent)
 }
 
 
+rlong rpa_recordtree_copy(rarray_t *dst, rarray_t *src, rlong rec)
+{
+       rparecord_t *prec;
+       rlong size, i;
+       rec = rpa_recordtree_get(src, rec, RPA_RECORD_START);
+       size = rpa_recordtree_size(src, rec);
+
+       for (i = 0; i < size; i++) {
+               prec = rpa_record_get(src, i);
+               r_array_add(dst, prec);
+       }
+       return size;
+}
+
+
+rlong rpa_recordtree_walk(rarray_t *src, rlong rec, rpa_recordtree_callback callaback, rpointer userdata)
+{
+       rlong size;
+       rec = rpa_recordtree_get(src, rec, RPA_RECORD_START);
+       size = rpa_recordtree_size(src, rec);
+
+       return size;
+}
+
+
 static void rpa_recordptr_setusertype(rparecord_t *prec, ruint32 usertype, rvalset_t op)
 {
        switch (op) {
index 8dd9ec3..6e16b69 100644 (file)
@@ -38,6 +38,9 @@ typedef struct rparecord_s {
 } rparecord_t;
 
 
+typedef rlong (*rpa_recordtree_callback)(rarray_t *records, rlong rec, rpointer userdata);
+
+rlong rpa_recordtree_walk(rarray_t *src, rlong rec, rpa_recordtree_callback callaback, rpointer userdata);
 rlong rpa_recordtree_get(rarray_t *records, rlong rec, rulong type);
 rlong rpa_recordtree_firstchild(rarray_t *records, rlong rec, rulong type);
 rlong rpa_recordtree_lastchild(rarray_t *records, rlong rec, rulong type);
@@ -46,6 +49,7 @@ rlong rpa_recordtree_prev(rarray_t *records, rlong rec, rulong type);
 rlong rpa_recordtree_parent(rarray_t *records, rlong rec, rulong type);
 rlong rpa_recordtree_rotatedown(rarray_t *records, rlong parent);                      /* Rotate children down, the last child becomes the first */
 rlong rpa_recordtree_size(rarray_t *records, rlong rec);                                       /* Size of the tree */
+rlong rpa_recordtree_copy(rarray_t *dst, rarray_t *src, rlong rec);
 
 void rpa_record_dumpindented(rarray_t *records, rlong rec, rint level);
 void rpa_record_dump(rarray_t *records, rlong rec);
index cb429a4..ffa7b71 100644 (file)
@@ -385,8 +385,23 @@ static void rpavm_swi_setcache(rvmcpu_t *cpu, rvm_asmins_t *ins)
                prec = (rparecord_t *)r_array_slot(stat->records, startrec);
 //             r_printf("Set the cache for: %s (%ld, %ld), top = %ld, ret = %ld, ruleid=%ld\n", prec->rule, startrec, endrec, prec->top, r0, ruleid);
                rpa_cache_set(stat->cache, top, ruleid, r0, startrec, endrec);
+
+               /*
+                * The next optimization is supposed to reduce the size of
+                * garbage records.
+                */
+               if (stat->cursize < endrec + 1)
+                       stat->cursize = endrec + 1;
        } else {
                rpa_cache_set(stat->cache, top, ruleid, r0, 0, 0);
+               /*
+                * The next optimization is supposed to reduce the size of
+                * garbage records.
+                */
+               if (stat->cursize < endrec + 1) {
+                       r_array_setlength(stat->records, endrec + 1);
+                       stat->cursize = endrec + 1;
+               }
        }
 }