RPA Toolkit
Work on the astnode and astval...continued, added rast-test
authorMartin Stoilov <martin@rpasearch.com>
Fri, 4 Feb 2011 04:17:49 +0000 (20:17 -0800)
committerMartin Stoilov <martin@rpasearch.com>
Fri, 4 Feb 2011 04:17:49 +0000 (20:17 -0800)
15 files changed:
rast/build/linux/rast.mk
rast/rastnode.c
rast/rastnode.h
rlib/build/linux/rlib.mk
rlib/rgc.c [new file with mode: 0644]
rlib/rgc.h [new file with mode: 0644]
rlib/rharray.c
rlib/rharray.h
rlib/rhash.c
rlib/rhash.h
rlib/robject.c
rlib/robject.h
rpa/rpadbex.c
tests/build/linux/robject-tests.mk
tests/rast-test.c [new file with mode: 0644]

index cad40d7..e24f7d3 100644 (file)
@@ -4,7 +4,6 @@ RAST_SO = $(OUTDIR)/librast.so.1.0
 
 RAST_OBJECTS = \
        $(OUTDIR)/rastnode.o \
-       $(OUTDIR)/rastgc.o \
 
 
 ifeq ($(OS), linux)
index 35c0e98..feb1c09 100644 (file)
@@ -1,4 +1,5 @@
 #include "rastnode.h"
+#include "rgc.h"
 
 
 robject_t *r_astnode_init(robject_t *obj, ruint32 type, r_object_cleanupfun cleanup, r_object_copyfun copy)
@@ -19,6 +20,18 @@ rastnode_t *r_astnode_create()
 }
 
 
+void r_astnode_addchild(rastnode_t *node, rastnode_t *child)
+{
+       if (node->val.type != R_ASTVAL_ARRAY) {
+               rcarray_t *arr = r_carray_create(sizeof(rastval_t));
+               if (((robject_t*)child)->gc)
+                       r_gc_add((rgc_t*)((robject_t*)child)->gc, (robject_t*)arr);
+               R_ASTVAL_SET_ARRAY(&node->val, arr);
+       }
+       r_carray_add(node->val.v.arr, &child);
+}
+
+
 void r_astnode_cleanup(robject_t *obj)
 {
        rastnode_t *node = (rastnode_t*)obj;
index 7d0514d..0285452 100644 (file)
@@ -14,14 +14,6 @@ extern "C" {
 typedef struct rastnode_s rastnode_t;
 
 
-typedef enum {
-       R_AST_NONE = 0,
-       R_AST_STRING,
-       R_AST_DOUBLE,
-       R_AST_LONG,
-} r_asttype_t;
-
-
 typedef struct rastsource_s {
        rpointer ptr;
        rulong size;
@@ -33,6 +25,7 @@ typedef struct rastsource_s {
 #define R_ASTVAL_POINTER 3
 #define R_ASTVAL_STRING 4
 #define R_ASTVAL_ARRAY 5
+#define R_ASTVAL_NODE 6
 
 typedef struct rastval_s {
        union {
@@ -47,9 +40,12 @@ typedef struct rastval_s {
        ruint type;
 } rastval_t;
 
+#define R_ASTVAL_SET_ARRAY(__p__, __a__) do { (__p__)->v.arr = __a__; (__p__)->type =  R_ASTVAL_ARRAY; } while (0)
+
 
 struct rastnode_s {
        robject_t obj;
+       rastnode_t *parent;
        rastval_t val;
        rastsource_t src;
        rharray_t *props;
@@ -58,6 +54,7 @@ struct rastnode_s {
 
 robject_t *r_astnode_init(robject_t *obj, ruint32 type, r_object_cleanupfun cleanup, r_object_copyfun copy);
 rastnode_t *r_astnode_create();
+void r_astnode_addchild(rastnode_t *node, rastnode_t *child);
 
 /*
  * Virtual methods implementation
index 70a6dac..f003a81 100644 (file)
@@ -5,6 +5,7 @@ RLIB_SO = $(OUTDIR)/librlib.so.1.0
 
 RLIB_OBJECTS +=        $(OUTDIR)/rref.o
 RLIB_OBJECTS +=        $(OUTDIR)/robject.o
+RLIB_OBJECTS +=        $(OUTDIR)/rgc.o
 RLIB_OBJECTS +=        $(OUTDIR)/rmem.o
 RLIB_OBJECTS +=        $(OUTDIR)/rmath.o
 RLIB_OBJECTS +=        $(OUTDIR)/ratomic.o
diff --git a/rlib/rgc.c b/rlib/rgc.c
new file mode 100644 (file)
index 0000000..471380e
--- /dev/null
@@ -0,0 +1,63 @@
+#include "rgc.h"
+
+
+robject_t *r_gc_init(robject_t *obj, ruint32 type, r_object_cleanupfun cleanup, r_object_copyfun copy)
+{
+       rgc_t *gc = (rgc_t*)obj;
+
+       r_object_init(obj, type, cleanup, copy);
+       r_list_init(&gc->head[0]);
+       return obj;
+}
+
+
+rgc_t *r_gc_create()
+{
+       rgc_t *gc = (rgc_t*)r_object_create(sizeof(*gc));
+       r_gc_init((robject_t*)gc, R_OBJECT_GC, r_gc_cleanup, r_gc_copy);
+       return gc;
+}
+
+
+void r_gc_cleanup(robject_t *obj)
+{
+       rgc_t *gc = (rgc_t*)obj;
+       r_gc_deallocateall(gc);
+       r_object_cleanup(obj);
+}
+
+
+robject_t *r_gc_copy(const robject_t *obj)
+{
+
+       return NULL;
+}
+
+
+void r_gc_deallocateall(rgc_t *gc)
+{
+       robject_t *obj;
+       rhead_t *head = r_gc_head(gc);
+
+       while (!r_list_empty(head)) {
+               obj = r_list_entry(r_list_first(head), robject_t, lnk);
+               r_list_del(&obj->lnk);
+               obj->gc = NULL;
+               r_object_destroy(obj);
+       }
+}
+
+
+void r_gc_add(rgc_t *gc, robject_t *obj)
+{
+       rhead_t *head = r_gc_head(gc);
+
+       r_list_addt(head, &obj->lnk);
+       obj->gc = (rpointer)gc;
+}
+
+
+rhead_t *r_gc_head(rgc_t *gc)
+{
+       return &gc->head[gc->active];
+}
diff --git a/rlib/rgc.h b/rlib/rgc.h
new file mode 100644 (file)
index 0000000..4468cd0
--- /dev/null
@@ -0,0 +1,36 @@
+#ifndef _RASTGC_H_
+#define _RASTGC_H_
+
+#include "robject.h"
+#include "rlist.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+typedef struct rgc_s {
+       robject_t obj;
+       rhead_t head[2];
+       ruint active;
+} rgc_t;
+
+
+robject_t *r_gc_init(robject_t *obj, ruint32 type, r_object_cleanupfun cleanup, r_object_copyfun copy);
+rgc_t *r_gc_create();
+
+/*
+ * Virtual methods implementation
+ */
+void r_gc_cleanup(robject_t *obj);
+robject_t *r_gc_copy(const robject_t *obj);
+void r_gc_deallocateall(rgc_t *gc);
+void r_gc_add(rgc_t *gc, robject_t *obj);
+rhead_t *r_gc_head(rgc_t *gc);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
index 059f1de..a5d9672 100644 (file)
@@ -133,6 +133,22 @@ rlong r_harray_add_s(rharray_t *harray, const rchar *name, rconstpointer pval)
 }
 
 
+rlong r_harray_replace(rharray_t *harray, const rchar *name, ruint namesize, rconstpointer pval)
+{
+       rlong index = r_harray_lookup(harray, name, namesize);
+
+       if (index < 0)
+               return r_harray_add(harray, name, namesize, pval);
+       index = r_carray_replace(harray->members, index,  pval);
+       return index;
+}
+
+rlong r_harray_replace_s(rharray_t *harray, const rchar *name, rconstpointer pval)
+{
+       return r_harray_replace(harray, name, r_strlen(name), pval);
+}
+
+
 rlong r_harray_lookup(rharray_t *harray, const rchar *name, ruint namesize)
 {
        rulong found;
@@ -151,6 +167,25 @@ rlong r_harray_lookup_s(rharray_t *harray, const rchar *name)
 }
 
 
+rlong r_harray_taillookup(rharray_t *harray, const rchar *name, ruint namesize)
+{
+       rulong found;
+
+       rstr_t lookupstr = {(char*)name, namesize};
+       found = r_hash_taillookup_indexval(harray->hash, &lookupstr);
+       if (found == R_HASH_INVALID_INDEXVAL)
+               return -1;
+       return (rlong)found;
+}
+
+
+rlong r_harray_taillookup_s(rharray_t *harray, const rchar *name)
+{
+       return r_harray_lookup(harray, name, r_strlen(name));
+}
+
+
+
 rhash_node_t* r_harray_nodelookup(rharray_t *harray, rhash_node_t *cur, const rchar *name, ruint namesize)
 {
        rstr_t lookupstr = {(char*)name, namesize};
@@ -164,6 +199,19 @@ rhash_node_t* r_harray_nodelookup_s(rharray_t *harray, rhash_node_t *cur, const
 }
 
 
+rhash_node_t* r_harray_nodetaillookup(rharray_t *harray, rhash_node_t *cur, const rchar *name, ruint namesize)
+{
+       rstr_t lookupstr = {(char*)name, namesize};
+       return r_hash_nodetaillookup(harray->hash, cur, &lookupstr);
+}
+
+
+rhash_node_t* r_harray_nodetaillookup_s(rharray_t *harray, rhash_node_t *cur, const rchar *name)
+{
+       return r_harray_nodetaillookup(harray, cur, name, r_strlen(name));
+}
+
+
 rint r_harray_set(rharray_t *harray, rlong index, rconstpointer pval)
 {
        if (index < 0)
index cd4522a..e98b548 100644 (file)
@@ -26,10 +26,16 @@ rharray_t *r_harray_create(ruint elt_size);
 robject_t *r_harray_init(robject_t *obj, ruint32 type, r_object_cleanupfun cleanup, r_object_copyfun copy, ruint elt_size);
 rlong r_harray_add(rharray_t *harray, const rchar *name, ruint namesize, rconstpointer pval);
 rlong r_harray_add_s(rharray_t *harray, const rchar *name, rconstpointer pval);
+rlong r_harray_replace(rharray_t *harray, const rchar *name, ruint namesize, rconstpointer pval);
+rlong r_harray_replace_s(rharray_t *harray, const rchar *name, rconstpointer pval);
 rlong r_harray_lookup(rharray_t *harray, const rchar *name, ruint namesize);
 rlong r_harray_lookup_s(rharray_t *harray, const rchar *name);
+rlong r_harray_taillookup(rharray_t *harray, const rchar *name, ruint namesize);
+rlong r_harray_taillookup_s(rharray_t *harray, const rchar *name);
 rhash_node_t* r_harray_nodelookup(rharray_t *harray, rhash_node_t *cur, const rchar *name, ruint namesize);
 rhash_node_t* r_harray_nodelookup_s(rharray_t *harray, rhash_node_t *cur, const rchar *name);
+rhash_node_t* r_harray_nodetaillookup(rharray_t *harray, rhash_node_t *cur, const rchar *name, ruint namesize);
+rhash_node_t* r_harray_nodetaillookup_s(rharray_t *harray, rhash_node_t *cur, const rchar *name);
 rpointer r_harray_get(rharray_t *harray, rulong index);
 rint r_harray_set(rharray_t *harray, rlong index, rconstpointer pval);
 
index a1b4a27..fad43ee 100644 (file)
@@ -29,13 +29,31 @@ static void r_hash_node_destroy(rhash_node_t *node)
 }
 
 
+rhash_node_t *r_hash_nodetaillookup(rhash_t* hash, rhash_node_t *cur, rconstpointer key)
+{
+       ruint nbucket = hash->hfunc(key) & r_hash_mask(hash);
+       rhead_t *bucket = &hash->buckets[nbucket];
+       rhash_node_t *node;
+       rlink_t *pos;
+
+       for (pos = cur ? r_list_prev(bucket, &cur->lnk) : r_list_last(bucket); pos ; pos = r_list_prev(bucket, pos)) {
+               node = r_list_entry(pos, rhash_node_t, lnk);
+               if (hash->eqfunc(node->key, key)) {
+                       return node;
+               }
+       }
+       return NULL;
+}
+
+
 rhash_node_t *r_hash_nodelookup(rhash_t* hash, rhash_node_t *cur, rconstpointer key)
 {
        ruint nbucket = hash->hfunc(key) & r_hash_mask(hash);
+       rhead_t *bucket = &hash->buckets[nbucket];
        rhash_node_t *node;
        rlink_t *pos;
 
-       for (pos = cur ? cur->lnk.next : (&hash->buckets[nbucket])->next; pos != (&hash->buckets[nbucket]); pos = (pos)->next) {
+       for (pos = cur ? r_list_next(bucket, &cur->lnk) : r_list_first(bucket); pos ; pos = r_list_next(bucket, pos)) {
                node = r_list_entry(pos, rhash_node_t, lnk);
                if (hash->eqfunc(node->key, key)) {
                        return node;
@@ -207,6 +225,15 @@ rulong r_hash_lookup_indexval(rhash_t* hash, rconstpointer key)
 }
 
 
+rulong r_hash_taillookup_indexval(rhash_t* hash, rconstpointer key)
+{
+       rhash_node_t *node = r_hash_nodetaillookup(hash, NULL, key);
+       if (node)
+               return node->value.index;
+       return R_HASH_INVALID_INDEXVAL;
+}
+
+
 rpointer r_hash_value(rhash_node_t *node)
 {
        return node->value.ptr;
index 072dacc..000f031 100644 (file)
@@ -39,7 +39,9 @@ void r_hash_removeall(rhash_t* hash);
 rpointer r_hash_lookup(rhash_t* hash, rconstpointer key);
 void r_hash_insert_indexval(rhash_t* hash, rconstpointer key, rulong index);
 rulong r_hash_lookup_indexval(rhash_t* hash, rconstpointer key);
+rulong r_hash_taillookup_indexval(rhash_t* hash, rconstpointer key);
 rhash_node_t *r_hash_nodelookup(rhash_t* hash, rhash_node_t *cur, rconstpointer key);
+rhash_node_t *r_hash_nodetaillookup(rhash_t* hash, rhash_node_t *cur, rconstpointer key);
 rpointer r_hash_value(rhash_node_t *node);
 rulong r_hash_indexval(rhash_node_t *node);
 
index f8c03bf..0847977 100644 (file)
@@ -14,7 +14,7 @@ robject_t *r_object_create(rsize_t size)
 void r_object_init(robject_t *obj, ruint32 type, r_object_cleanupfun cleanup, r_object_copyfun copy)
 {
        r_list_init(&obj->lnk);
-       obj->lst = NULL;
+       obj->gc = NULL;
        obj->type = type;
        obj->cleanup = cleanup;
        obj->copy = copy;
index 8d89613..4a89af1 100644 (file)
@@ -17,6 +17,7 @@ extern "C" {
 #define R_OBJECT_HASH 5
 #define R_OBJECT_REF 6
 #define R_OBJECT_JSOBJECT 7
+#define R_OBJECT_GC 8
 #define R_OBJECT_USER 256
 
 
@@ -29,7 +30,7 @@ typedef robject_t* (*r_object_copyfun)(const robject_t *ptr);
 
 struct robject_s {
        rlink_t lnk;
-       rlist_t *lst;
+       rpointer *gc;
        ruint32 type;
        ruint32 size;
        r_object_cleanupfun cleanup;
index 4651fbb..331fa3a 100644 (file)
@@ -63,7 +63,6 @@ void rpa_dbex_close_do(rpa_dbex_handle hDbex)
 void rpa_dbex_close(rpa_dbex_handle hDbex)
 {
        rpa_dbex_close_do(hDbex);
-//     rpa_dbex_connect_callbacks(hDbex);
 }
 
 
index 3853230..1a33d4c 100644 (file)
@@ -2,16 +2,18 @@ ROBJECT_SRCDIR = $(SRCDIR)/robject
 RLIB_SRCDIR = $(SRCDIR)/rlib
 RVM_SRCDIR = $(SRCDIR)/rvm
 RPA_SRCDIR = $(SRCDIR)/rpa
+RAST_SRCDIR = $(SRCDIR)/rast
 TESTS_SRCDIR = $(SRCDIR)/tests
-INCLUDE = -I$(SRCDIR)/arch/$(OS)/$(ARCHDIR) -I$(ROBJECT_SRCDIR) -I$(RLIB_SRCDIR) -I$(RVM_SRCDIR) -I$(RPA_SRCDIR)
+INCLUDE = -I$(SRCDIR)/arch/$(OS)/$(ARCHDIR) -I$(ROBJECT_SRCDIR) -I$(RLIB_SRCDIR) -I$(RVM_SRCDIR) -I$(RPA_SRCDIR) -I$(RAST_SRCDIR)
 LIBS =  -L$(ROBJECT_SRCDIR)/build/$(OS)/$(ARCHDIR)/out 
 LIBS += -L$(RLIB_SRCDIR)/build/$(OS)/$(ARCHDIR)/out 
 LIBS += -L$(RVM_SRCDIR)/build/$(OS)/$(ARCHDIR)/out 
 LIBS += -L$(RPA_SRCDIR)/build/$(OS)/$(ARCHDIR)/out 
-LIBS += -lrvm -lrpa -lrpasx -lrlib -lpthread -lm --static
-
+LIBS += -L$(RAST_SRCDIR)/build/$(OS)/$(ARCHDIR)/out 
+LIBS += -lrvm -lrpa -lrpasx -lrast -lrlib -lpthread -lm --static
 
 
+TESTS  += $(OUTDIR)/rast-test
 TESTS  += $(OUTDIR)/rpagen-test
 TESTS  += $(OUTDIR)/calc-test
 TESTS  += $(OUTDIR)/funcarg-test
@@ -57,6 +59,9 @@ $(OUTDIR)/%.o: $(TESTS_SRCDIR)/%.c
 $(OUTDIR)/rpagen-test : $(OUTDIR)/ecma262.o $(OUTDIR)/rpagen-test.o
        $(CC) $(CFLAGS)  -o $@ $^ $(LIBS)
 
+$(OUTDIR)/rast-test : $(OUTDIR)/ecma262.o $(OUTDIR)/rast-test.o
+       $(CC) $(CFLAGS)  -o $@ $^ $(LIBS)
+
 $(OUTDIR)/%: $(TESTS_SRCDIR)/%.c
        + $(CC) $(CFLAGS) -o $(OUTDIR)/$* $(TESTS_SRCDIR)/$*.c $(LIBS) $(INCLUDE)
 
diff --git a/tests/rast-test.c b/tests/rast-test.c
new file mode 100644 (file)
index 0000000..03db075
--- /dev/null
@@ -0,0 +1,244 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/mman.h>
+#include "rmem.h"
+#include "rjsobject.h"
+#include "rvmcpu.h"
+#include "rpadbex.h"
+#include "rpaerror.h"
+#include "rvmcodegen.h"
+#include "rvmcodemap.h"
+#include "rvmscope.h"
+#include "rvmoperator.h"
+#include "rgc.h"
+#include "rastnode.h"
+
+
+typedef struct rastcompiler_s {
+       rpa_dbex_handle dbex;
+       rgc_t *gc;
+       rastnode_t *root;
+       rint optimized;
+} rastcompiler_t;
+
+void r_astcompiler_loadrules(rastcompiler_t *aco);
+
+
+static int debuginfo = 0;
+static int parseinfo = 0;
+static int verboseinfo = 0;
+static int compileonly = 0;
+
+
+rastcompiler_t *r_astcompiler_create()
+{
+       rastcompiler_t *aco;
+
+       aco = r_malloc(sizeof(*aco));
+       r_memset(aco, 0, sizeof(*aco));
+       aco->gc = r_gc_create();
+       return aco;
+}
+
+
+void r_astcompiler_destroy(rastcompiler_t *aco)
+{
+       if (aco) {
+               r_object_destroy((robject_t*)aco->gc);
+       }
+       r_free(aco);
+}
+
+
+void r_astcompiler_dumptree(rastcompiler_t *aco)
+{
+
+}
+
+
+void codegen_unmap_file(rstr_t *buf)
+{
+       if (buf) {
+               munmap(buf->str, buf->size);
+               r_free(buf);
+       }
+}
+
+
+rstr_t *codegen_map_file(const char *filename)
+{
+       struct stat st;
+       rstr_t *str;
+       char *buffer;
+
+
+       int fd = open(filename, O_RDONLY);
+       if (fd < 0) {
+               return (void*)0;
+       }
+       if (fstat(fd, &st) < 0) {
+               close(fd);
+               return (void*)0;
+       }
+       buffer = (char*)mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0);
+       if (buffer == (void*)-1) {
+               close(fd);
+               return (void*)0;
+       }
+       str = (rstr_t *)r_malloc(sizeof(*str));
+       if (!str)
+               goto error;
+       r_memset(str, 0, sizeof(*str));
+       str->str = buffer;
+       str->size = st.st_size;
+       close(fd);
+       return str;
+
+error:
+       munmap(buffer, st.st_size);
+       close(fd);
+       return str;
+}
+
+
+inline int r_astcompiler_dumpnotification(rpa_stat_handle stat, const char *name, void *userdata, const char *input, unsigned int size, unsigned int reason)
+{
+       rastcompiler_t *aco = (rastcompiler_t *)userdata;
+
+       fprintf(stdout, "%s: ", name);
+       fprintf(stdout, "\n");
+       return size;
+}
+
+
+inline int r_astcompiler_notify(rpa_stat_handle stat, const char *name, void *userdata, const char *input, unsigned int size, unsigned int reason)
+{
+       rastcompiler_t *aco = (rastcompiler_t *)userdata;
+
+       if (parseinfo)
+               r_astcompiler_dumpnotification(stat, name, userdata, input, size, reason);
+
+       if (reason & RPA_REASON_START) {
+
+       } else if (reason & RPA_REASON_MATCHED) {
+
+       } else {
+
+       }
+
+       return size;
+}
+
+
+int main(int argc, char *argv[])
+{
+       int res, i;
+       rstr_t *script = NULL, *unmapscript = NULL;
+       rastcompiler_t *aco = r_astcompiler_create();
+       aco->dbex = rpa_dbex_create();
+
+
+       for (i = 1; i < argc; i++) {
+               if (r_strcmp(argv[i], "-L") == 0) {
+               } else if (r_strcmp(argv[i], "-d") == 0) {
+                       debuginfo = 1;
+               } else if (r_strcmp(argv[i], "-p") == 0) {
+                       parseinfo = 1;
+               } else if (r_strcmp(argv[i], "-P") == 0) {
+                       parseinfo = 1;
+                       verboseinfo = 1;
+               } else if (r_strcmp(argv[i], "-c") == 0) {
+                       compileonly = 1;
+               } else if (r_strcmp(argv[i], "-o") == 0) {
+                       aco->optimized = 1;
+               } else if (r_strcmp(argv[i], "-m") == 0) {
+
+               }
+       }
+
+       r_astcompiler_loadrules(aco);
+
+       for (i = 1; i < argc; i++) {
+               if (r_strcmp(argv[i], "-e") == 0) {
+                       if (++i < argc) {
+                               rstr_t script = { argv[i], r_strlen(argv[i]) };
+                               res = rpa_dbex_parse(aco->dbex, rpa_dbex_default_pattern(aco->dbex), script.str, script.str, script.str + script.size);
+                               if (res <= 0)
+                                       goto end;
+                       }
+                       goto exec;
+               }
+       }
+
+       for (i = 1; i < argc; i++) {
+               if (r_strcmp(argv[i], "-f") == 0) {
+
+                       if (++i < argc) {
+                               script = codegen_map_file(argv[i]);
+                               if (script) {
+                                       res = rpa_dbex_parse(aco->dbex, rpa_dbex_default_pattern(aco->dbex), script->str, script->str, script->str + script->size);
+                                       unmapscript = script;
+                                       if (res <= 0)
+                                               goto end;
+                               }
+
+                       }
+                       goto exec;
+               }
+       }
+
+
+exec:
+       r_astcompiler_dumptree(aco);
+
+
+end:
+       if (unmapscript)
+               codegen_unmap_file(unmapscript);
+       rpa_dbex_destroy(aco->dbex);
+       r_astcompiler_destroy(aco);
+
+       if (debuginfo) {
+               r_printf("Max alloc mem: %ld\n", r_debug_get_maxmem());
+               r_printf("Leaked mem: %ld\n", r_debug_get_allocmem());
+       }
+       return 0;
+}
+
+
+
+extern char _binary_____________tests_ecma262_rpa_start[];
+extern char _binary_____________tests_ecma262_rpa_end[];
+extern unsigned long *_binary_____________tests_ecma262_rpa_size;
+
+void r_astcompiler_loadrules(rastcompiler_t *aco)
+{
+       int ret, line;
+       int inputsize = _binary_____________tests_ecma262_rpa_end - _binary_____________tests_ecma262_rpa_start;
+       const char *buffer = _binary_____________tests_ecma262_rpa_start;
+       const char *pattern = buffer;
+
+       rpa_dbex_open(aco->dbex);
+       rpa_dbex_add_callback(aco->dbex, ".*", RPA_REASON_ALL, r_astcompiler_notify, aco);
+
+       while ((ret = rpa_dbex_load(aco->dbex, pattern, inputsize)) > 0) {
+               inputsize -= ret;
+               pattern += ret;
+       }
+       if (ret < 0) {
+               for (line = 1; pattern >= buffer; --pattern) {
+                       if (*pattern == '\n')
+                               line += 1;
+               }
+               fprintf(stdout, "Line: %d, RPA LOAD ERROR: %s\n", line, (rpa_dbex_get_error(aco->dbex) == RPA_E_SYNTAX_ERROR) ? "Syntax Error." : "Pattern Loading failed.");
+               goto error;
+       }
+
+error:
+       rpa_dbex_close(aco->dbex);
+}