RPA Toolkit
Added support for GC managed keys in rmap_t. Removed the old rvm_gc_t in favour of...
authorMartin Stoilov <martin@rpasearch.com>
Fri, 10 Jun 2011 04:39:11 +0000 (21:39 -0700)
committerMartin Stoilov <martin@rpasearch.com>
Fri, 10 Jun 2011 04:39:11 +0000 (21:39 -0700)
18 files changed:
rjs/rjs.c
rjs/rjsexec.c
rlib/rgc.c
rlib/rgc.h
rlib/rmap.c
rlib/rmap.h
rlib/robject.c
rlib/robject.h
rlib/rstring.c
rlib/rstring.h
rvm/build/linux/rvm.mk
rvm/rvmcpu.c
rvm/rvmcpu.h
rvm/rvmgc.c [deleted file]
rvm/rvmgc.h [deleted file]
rvm/rvmoperatoradd.c
rvm/rvmreg.c
tests/testmisc/rmap-test.c

index abcf2c0..720674a 100644 (file)
--- a/rjs/rjs.c
+++ b/rjs/rjs.c
@@ -40,7 +40,7 @@ rjs_engine_t *rjs_engine_create()
                goto error;
        tp = rvm_cpu_alloc_global(jse->cpu);
        rvm_reg_setjsobject(tp, (robject_t *)r_map_create(sizeof(rvmreg_t), 7));
-       rvm_gc_add(jse->cpu->gc, (robject_t*)RVM_REG_GETP(tp));
+       r_gc_add(jse->cpu->gc, (robject_t*)RVM_REG_GETP(tp));
        rvm_cpu_setreg(jse->cpu, TP, tp);
        return jse;
 error:
@@ -215,7 +215,7 @@ static rint rjs_compiler_argarray_setup(rjs_compiler_t *co)
                return -1;
        }
        a = r_map_create(sizeof(rvmreg_t), 7);
-       rvm_gc_add(co->cpu->gc, (robject_t*)a);
+       r_gc_add(co->cpu->gc, (robject_t*)a);
        r_map_add_s(a, "count", &count);
        rvm_reg_setjsobject((rvmreg_t*)v->data.ptr, (robject_t*)a);
        return 0;
index cc45036..b72e6e5 100644 (file)
@@ -72,7 +72,7 @@ static void rjs_exec_ltrim(rvmcpu_t *cpu, rvm_asmins_t *ins)
                ptr++;
        }
        dest = r_string_create_strsize(ptr, size);
-       rvm_gc_add(cpu->gc, (robject_t*)dest);
+       r_gc_add(cpu->gc, (robject_t*)dest);
        rvm_reg_setstring(RVM_CPUREG_PTR(cpu, R0), dest);
 }
 
@@ -108,7 +108,7 @@ static void rjs_exec_rtrim(rvmcpu_t *cpu, rvm_asmins_t *ins)
                ptr--;
        }
        dest = r_string_create_strsize(src->s.str, size);
-       rvm_gc_add(cpu->gc, (robject_t*)dest);
+       r_gc_add(cpu->gc, (robject_t*)dest);
        rvm_reg_setstring(RVM_CPUREG_PTR(cpu, R0), dest);
 }
 
@@ -153,7 +153,7 @@ static void rjs_exec_trim(rvmcpu_t *cpu, rvm_asmins_t *ins)
                ptr--;
        }
        dest = r_string_create_strsize(start, size);
-       rvm_gc_add(cpu->gc, (robject_t*)dest);
+       r_gc_add(cpu->gc, (robject_t*)dest);
        rvm_reg_setstring(RVM_CPUREG_PTR(cpu, R0), dest);
 }
 
index 471380e..22af00a 100644 (file)
@@ -19,6 +19,12 @@ rgc_t *r_gc_create()
 }
 
 
+void r_gc_destroy(rgc_t *gc)
+{
+       r_object_destroy((robject_t *)gc);
+}
+
+
 void r_gc_cleanup(robject_t *obj)
 {
        rgc_t *gc = (rgc_t*)obj;
@@ -53,7 +59,7 @@ 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;
+       r_object_gcset(obj, gc);
 }
 
 
index 4468cd0..7de29a9 100644 (file)
@@ -18,15 +18,16 @@ typedef struct rgc_s {
 
 robject_t *r_gc_init(robject_t *obj, ruint32 type, r_object_cleanupfun cleanup, r_object_copyfun copy);
 rgc_t *r_gc_create();
+void r_gc_destroy(rgc_t *gc);
+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);
 
 /*
  * 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
index be74d10..c535c14 100644 (file)
@@ -9,7 +9,7 @@ typedef struct r_mapnode_s {
        rlink_t hash;
        rsize_t index;
        rlong nbucket;
-       rstr_t *key;
+       rstring_t *key;
        union {
                rpointer p;
                rchar data[0];
@@ -38,7 +38,8 @@ static rulong r_map_rstrhash(const rstr_t *key)
 
 void r_mapnode_init(r_mapnode_t *node, const rchar *key, rsize_t size)
 {
-       node->key = r_rstrdup(key, size);
+//     node->key = r_rstrdup(key, size);
+       node->key = r_string_create_strsize(key, size);
        r_list_init(&node->active);
        r_list_init(&node->hash);
 }
@@ -75,12 +76,14 @@ void r_map_cleanup(robject_t *obj)
 
        while (!r_list_empty(&map->active)) {
                node = r_list_entry(r_list_first(&map->active), r_mapnode_t, active);
-               r_free(node->key);
+               if (!r_object_gcget((robject_t*)node->key))
+                       r_string_destroy(node->key);
                r_list_del(&node->active);
        }
        while (!r_list_empty(&map->inactive)) {
                node = r_list_entry(r_list_first(&map->inactive), r_mapnode_t, active);
-               r_free(node->key);
+               if (!r_object_gcget((robject_t*)node->key))
+                       r_string_destroy(node->key);
                r_list_del(&node->active);
        }
 
@@ -131,41 +134,67 @@ void r_map_destroy(rmap_t *map)
 }
 
 
-rlong r_map_add(rmap_t *map, const rchar *name, rsize_t namesize, rconstpointer pval)
+rlong r_map_gckey_add(rmap_t *map, rgc_t* gc, const rchar *name, rsize_t namesize, rconstpointer pval)
 {
        r_mapnode_t *node;
 
        node = r_map_getfreenode(map, name, namesize);
        if (pval)
                r_memcpy(node->value.data, pval, map->elt_size);
-       node->nbucket = (r_map_rstrhash(node->key) & r_map_hashmask(map));
+       node->nbucket = (r_map_rstrhash(R_STRING2RSTR(node->key)) & r_map_hashmask(map));
        r_list_addt(&map->hash[node->nbucket], &node->hash);
        r_list_addt(&map->active, &node->active);
+       if (gc)
+               r_gc_add(gc, (robject_t*)node->key);
        return node->index;
 }
 
 
-rlong r_map_add_s(rmap_t *map, const rchar *name, rconstpointer pval)
+rlong r_map_gckey_add_s(rmap_t *map, rgc_t* gc, const rchar *name, rconstpointer pval)
 {
-       return r_map_add(map, name, r_strlen(name), pval);
+       return r_map_gckey_add(map, gc, name, r_strlen(name), pval);
 }
 
 
-rlong r_map_add_l(rmap_t *map, long name, rconstpointer pval)
+rlong r_map_gckey_add_d(rmap_t *map, rgc_t* gc, double name, rconstpointer pval)
 {
        rchar key[128];
        r_memset(key, 0, sizeof(key));
-       r_snprintf(key, sizeof(key) - 1, "%ld", name);
-       return r_map_add_s(map, key, pval);
+       r_snprintf(key, sizeof(key) - 1, "%.15f", name);
+       return r_map_gckey_add_s(map, gc, key, pval);
 }
 
 
-rlong r_map_add_d(rmap_t *map, double name, rconstpointer pval)
+rlong r_map_gckey_add_l(rmap_t *map, rgc_t* gc, long name, rconstpointer pval)
 {
        rchar key[128];
        r_memset(key, 0, sizeof(key));
-       r_snprintf(key, sizeof(key) - 1, "%.15f", name);
-       return r_map_add_s(map, key, pval);
+       r_snprintf(key, sizeof(key) - 1, "%ld", name);
+       return r_map_gckey_add_s(map, gc, key, pval);
+}
+
+
+rlong r_map_add(rmap_t *map, const rchar *name, rsize_t namesize, rconstpointer pval)
+{
+       return r_map_gckey_add(map, NULL, name, namesize, pval);
+}
+
+
+rlong r_map_add_s(rmap_t *map, const rchar *name, rconstpointer pval)
+{
+       return r_map_gckey_add_s(map, NULL, name, pval);
+}
+
+
+rlong r_map_add_l(rmap_t *map, long name, rconstpointer pval)
+{
+       return r_map_gckey_add_l(map, NULL, name, pval);
+}
+
+
+rlong r_map_add_d(rmap_t *map, double name, rconstpointer pval)
+{
+       return r_map_gckey_add_d(map, NULL, name, pval);
 }
 
 
@@ -181,12 +210,12 @@ r_mapnode_t *r_map_node(rmap_t *map, rulong index)
 }
 
 
-const rchar *r_map_key(rmap_t *map, rulong index)
+rstring_t *r_map_key(rmap_t *map, rulong index)
 {
        r_mapnode_t *node = r_map_node(map, index);
        if (!node)
                return NULL;
-       return node->key->str;
+       return node->key;
 }
 
 
@@ -214,7 +243,8 @@ rint r_map_delete(rmap_t *map, rulong index)
        r_mapnode_t *node = r_map_node(map, index);
        if (!node)
                return -1;
-       r_free(node->key);
+       if (!r_object_gcget((robject_t*)node->key))
+               r_string_destroy(node->key);
        node->key = NULL;
        r_list_del(&node->hash);
        r_list_init(&node->hash);
@@ -247,7 +277,7 @@ rlong r_map_lookup(rmap_t *map, rlong current, const rchar *name, rsize_t namesi
        }
        for ( ; pos ; pos = r_list_next(bucket, pos)) {
                node = r_list_entry(pos, r_mapnode_t, hash);
-               if (r_map_rstrequal(node->key, &lookupstr)) {
+               if (r_map_rstrequal(R_STRING2RSTR(node->key), &lookupstr)) {
                        found = node->index;
                        break;
                }
@@ -304,7 +334,7 @@ rlong r_map_taillookup(rmap_t *map, rlong current, const rchar *name, rsize_t na
        }
        for ( ; pos ; pos = r_list_prev(bucket, pos)) {
                node = r_list_entry(pos, r_mapnode_t, hash);
-               if (r_map_rstrequal(node->key, &lookupstr)) {
+               if (r_map_rstrequal(R_STRING2RSTR(node->key), &lookupstr)) {
                        found = node->index;
                        break;
                }
index f3431bd..60efd57 100644 (file)
@@ -5,6 +5,7 @@
 #include "rhash.h"
 #include "rlist.h"
 #include "rstring.h"
+#include "rgc.h"
 #include "robject.h"
 
 #ifdef __cplusplus
@@ -38,8 +39,20 @@ rlong r_map_add(rmap_t *map, const rchar *name, rsize_t namesize, rconstpointer
 rlong r_map_add_s(rmap_t *map, const rchar *name, rconstpointer pval);
 rlong r_map_add_d(rmap_t *map, double name, rconstpointer pval);
 rlong r_map_add_l(rmap_t *map, long name, rconstpointer pval);
+
+/*
+ * The following functions allow the created keys (rstring_t objects) to be added to
+ * GC list and not being destroyed by the rmap_t, but leave it to the users of rmap_t
+ * to decide when to destroy those keys. These is useful for scripting languages with
+ * GC memory management. Another possibility would be to get the key as a rstrit_t* and
+ * make rmap_t completely get out of the memory management business.
+ */
+rlong r_map_gckey_add(rmap_t *map, rgc_t* gc, const rchar *name, rsize_t namesize, rconstpointer pval);
+rlong r_map_gckey_add_s(rmap_t *map, rgc_t* gc, const rchar *name, rconstpointer pval);
+rlong r_map_gckey_add_d(rmap_t *map, rgc_t* gc, double name, rconstpointer pval);
+rlong r_map_gckey_add_l(rmap_t *map, rgc_t* gc, long name, rconstpointer pval);
 rlong r_map_setvalue(rmap_t *map, rlong index, rconstpointer pval);
-const rchar *r_map_key(rmap_t *map, rulong index);
+rstring_t *r_map_key(rmap_t *map, rulong index);
 rpointer r_map_value(rmap_t *map, rulong index);
 rint r_map_delete(rmap_t *map, rulong index);
 
index 07d25cd..567550b 100644 (file)
@@ -80,3 +80,15 @@ ruint32 r_object_typeget(robject_t *obj)
 {
        return obj->type;
 }
+
+
+void r_object_gcset(robject_t *obj, rpointer gc)
+{
+       obj->gc = gc;
+}
+
+
+rpointer r_object_gcget(robject_t *obj)
+{
+       return obj->gc;
+}
index 236333e..62d8c21 100644 (file)
@@ -45,6 +45,8 @@ void r_object_cleanup(robject_t *obj);
 void r_object_init(robject_t *obj, ruint32 type, r_object_cleanupfun cleanup, r_object_copyfun copy);
 void r_object_typeset(robject_t *obj, ruint32 type);
 ruint32 r_object_typeget(robject_t *obj);
+void r_object_gcset(robject_t *obj, rpointer gc);
+rpointer r_object_gcget(robject_t *obj);
 
 /*
  * Virtual methods
index d66fc8d..ba0849f 100644 (file)
@@ -303,6 +303,12 @@ rstring_t *r_string_create_strsize(const rchar *str, ruint size)
 }
 
 
+void r_string_destroy(rstring_t *string)
+{
+       r_object_destroy((robject_t*)string);
+}
+
+
 const char *r_string_ansi(const rstring_t *str)
 {
        if (!str)
index 1a5d20e..9eeb1c2 100644 (file)
@@ -47,7 +47,8 @@ typedef struct rstring_s {
        rstr_t s;
 } rstring_t;
 
-#define R_STRING2PTR(__p__) ((rstring_t *)(__p__))->s.str
+#define R_STRING2ANSI(__p__) ((rstring_t *)(__p__))->s.str
+#define R_STRING2RSTR(__p__) &((rstring_t *)(__p__))->s
 #define r_string_empty(__p__) (!((__p__) && ((rstring_t *)(__p__))->s.size)) ? 1 : 0
 rstring_t *r_string_create();
 rstring_t *r_string_create_from_ansistr(const rchar *str);
@@ -55,6 +56,7 @@ rstring_t *r_string_create_from_double(rdouble d);
 rstring_t *r_string_create_from_long(rlong l);
 rstring_t *r_string_create_strsize(const char *str, ruint size);
 rstring_t *r_string_create_from_rstr(const rstr_t *str);
+void r_string_destroy(rstring_t *string);
 robject_t *r_string_init(robject_t *obj, ruint32 type, r_object_cleanupfun cleanup, r_object_copyfun copy);
 void r_string_assign(rstring_t *string, const rstr_t *str);
 void r_string_cat(rstring_t *string, const rstr_t *str);
index ff91826..131bf00 100644 (file)
@@ -12,7 +12,6 @@ RVM_OBJECTS +=        $(OUTDIR)/rvmrelocmap.o
 RVM_OBJECTS += $(OUTDIR)/rvmcodegen.o
 RVM_OBJECTS += $(OUTDIR)/rvmreg.o
 RVM_OBJECTS += $(OUTDIR)/rvmscope.o
-RVM_OBJECTS += $(OUTDIR)/rvmgc.o
 RVM_OBJECTS += $(OUTDIR)/rvmoperatorbin.o
 RVM_OBJECTS += $(OUTDIR)/rvmoperatoradd.o
 RVM_OBJECTS += $(OUTDIR)/rvmoperatorand.o
index 5b237fc..cb7afcd 100644 (file)
@@ -1507,7 +1507,7 @@ static void rvm_op_allocstr(rvmcpu_t *cpu, rvm_asmins_t *ins)
        if (!s) {
                RVM_ABORT(cpu, RVM_E_ILLEGAL);
        }
-       rvm_gc_add(cpu->gc, (robject_t*)s);
+       r_gc_add(cpu->gc, (robject_t*)s);
        rvm_reg_setstring(arg1, s);
 }
 
@@ -1519,7 +1519,7 @@ static void rvm_op_mapalloc(rvmcpu_t *cpu, rvm_asmins_t *ins)
        if (!a) {
                RVM_ABORT(cpu, RVM_E_ILLEGAL);
        }
-       rvm_gc_add(cpu->gc, (robject_t*)a);
+       r_gc_add(cpu->gc, (robject_t*)a);
        rvm_reg_setjsobject(arg1, (robject_t*)a);
 }
 
@@ -1533,7 +1533,7 @@ static void rvm_op_allocarr(rvmcpu_t *cpu, rvm_asmins_t *ins)
                RVM_ABORT(cpu, RVM_E_ILLEGAL);
        }
        r_carray_setlength(a, size);
-       rvm_gc_add(cpu->gc, (robject_t*)a);
+       r_gc_add(cpu->gc, (robject_t*)a);
        rvm_reg_setarray(arg1, (robject_t*)a);
 }
 
@@ -1579,13 +1579,13 @@ static void rvm_op_mapadd(rvmcpu_t *cpu, rvm_asmins_t *ins)
                RVM_ABORT(cpu, RVM_E_NOTOBJECT);
        }
        if (RVM_REG_GETTYPE(arg3) == RVM_DTYPE_LONG || RVM_REG_GETTYPE(arg3) == RVM_DTYPE_UNSIGNED) {
-               index = r_map_add_l(a, RVM_REG_GETL(arg3), NULL);
+               index = r_map_gckey_add_l(a, cpu->gc, RVM_REG_GETL(arg3), NULL);
        } else if (RVM_REG_GETTYPE(arg3) == RVM_DTYPE_DOUBLE) {
-               index = r_map_add_d(a, RVM_REG_GETD(arg3), NULL);
+               index = r_map_gckey_add_d(a, cpu->gc, RVM_REG_GETD(arg3), NULL);
        } else if (RVM_REG_GETTYPE(arg3) == RVM_DTYPE_STRING) {
-               index = r_map_add(a, ((rstring_t *)RVM_CPUREG_GETP(cpu, ins->op3))->s.str, ((rstring_t *)RVM_CPUREG_GETP(cpu, ins->op3))->s.size, NULL);
+               index = r_map_gckey_add(a, cpu->gc, ((rstring_t *)RVM_CPUREG_GETP(cpu, ins->op3))->s.str, ((rstring_t *)RVM_CPUREG_GETP(cpu, ins->op3))->s.size, NULL);
        } else if (RVM_REG_GETTYPE(arg3) == RVM_DTYPE_POINTER) {
-               index = r_map_add(a, (rchar*)RVM_CPUREG_GETP(cpu, ins->op3), RVM_CPUREG_GETL(cpu, ins->op1), NULL);
+               index = r_map_gckey_add(a, cpu->gc, (rchar*)RVM_CPUREG_GETP(cpu, ins->op3), RVM_CPUREG_GETL(cpu, ins->op1), NULL);
        } else {
                RVM_ABORT(cpu, RVM_E_ILLEGAL);
        }
@@ -1610,19 +1610,19 @@ static void rvm_op_maplookupadd(rvmcpu_t *cpu, rvm_asmins_t *ins)
        if (RVM_REG_GETTYPE(arg3) == RVM_DTYPE_LONG || RVM_REG_GETTYPE(arg3) == RVM_DTYPE_UNSIGNED) {
                index = r_map_lookup_l(a, -1, RVM_REG_GETL(arg3));
                if (index < 0)
-                       index = r_map_add_l(a, RVM_REG_GETL(arg3), NULL);
+                       index = r_map_gckey_add_l(a, cpu->gc, RVM_REG_GETL(arg3), NULL);
        } else if (RVM_REG_GETTYPE(arg3) == RVM_DTYPE_DOUBLE) {
                index = r_map_lookup_d(a, -1, RVM_REG_GETD(arg3));
                if (index < 0)
-                       index = r_map_add_d(a, RVM_REG_GETD(arg3), NULL);
+                       index = r_map_gckey_add_d(a, cpu->gc, RVM_REG_GETD(arg3), NULL);
        } else if (RVM_REG_GETTYPE(arg3) == RVM_DTYPE_STRING) {
                index = r_map_lookup(a, -1, ((rstring_t *)RVM_CPUREG_GETP(cpu, ins->op3))->s.str, ((rstring_t *)RVM_CPUREG_GETP(cpu, ins->op3))->s.size);
                if (index < 0)
-                       index = r_map_add(a, ((rstring_t *)RVM_CPUREG_GETP(cpu, ins->op3))->s.str, ((rstring_t *)RVM_CPUREG_GETP(cpu, ins->op3))->s.size, NULL);
+                       index = r_map_gckey_add(a, cpu->gc, ((rstring_t *)RVM_CPUREG_GETP(cpu, ins->op3))->s.str, ((rstring_t *)RVM_CPUREG_GETP(cpu, ins->op3))->s.size, NULL);
        } else if (RVM_REG_GETTYPE(arg3) == RVM_DTYPE_POINTER) {
                index = r_map_lookup(a, -1, (rchar*)RVM_CPUREG_GETP(cpu, ins->op3), RVM_CPUREG_GETL(cpu, ins->op1));
                if (index < 0)
-                       index = r_map_add(a, (rchar*)RVM_CPUREG_GETP(cpu, ins->op3), RVM_CPUREG_GETL(cpu, ins->op1), NULL);
+                       index = r_map_gckey_add(a, cpu->gc, (rchar*)RVM_CPUREG_GETP(cpu, ins->op3), RVM_CPUREG_GETL(cpu, ins->op1), NULL);
        } else {
                RVM_ABORT(cpu, RVM_E_ILLEGAL);
        }
@@ -1905,7 +1905,7 @@ rvmcpu_t *rvm_cpu_create(rulong stacksize)
        cpu->stack = r_malloc(stacksize * sizeof(rvmreg_t));
        cpu->data = r_carray_create(sizeof(rvmreg_t));
        cpu->opmap = rvm_opmap_create();
-       cpu->gc = rvm_gc_create();
+       cpu->gc = r_gc_create();
        rvm_op_binary_init(cpu->opmap);
        rvm_op_cast_init(cpu->opmap);
        rvm_op_not_init(cpu->opmap);
@@ -1923,8 +1923,8 @@ rvmcpu_t *rvm_cpu_create_default()
 
 void rvm_cpu_destroy(rvmcpu_t *cpu)
 {
-       rvm_gc_deallocate_all(cpu->gc);
-       rvm_gc_destroy(cpu->gc);
+       r_gc_deallocateall(cpu->gc);
+       r_gc_destroy(cpu->gc);
        r_object_destroy((robject_t*)cpu->switables);
        r_free(cpu->stack);
        r_object_destroy((robject_t*)cpu->data);
index b34edff..6c89c48 100644 (file)
@@ -25,7 +25,7 @@
 #include "rarray.h"
 #include "rcarray.h"
 #include "rvmreg.h"
-#include "rvmgc.h"
+#include "rgc.h"
 
 
 #ifdef __cplusplus
@@ -321,7 +321,7 @@ struct rvmcpu_s {
        rcarray_t *data;
        struct rvm_opmap_s *opmap;
        rvmreg_t *thisptr;
-       rvm_gc_t *gc;
+       rgc_t *gc;
        void *userdata1;
        void *userdata2;
        void *userdata3;
diff --git a/rvm/rvmgc.c b/rvm/rvmgc.c
deleted file mode 100644 (file)
index 895ec92..0000000
+++ /dev/null
@@ -1,129 +0,0 @@
-#include "rmem.h"
-#include "rvmgc.h"
-
-
-rvm_gc_t *rvm_gc_create()
-{
-       rvm_gc_t *gc;
-
-       gc = (rvm_gc_t *)r_zmalloc(sizeof(*gc));
-       rvm_gc_init(gc);
-       return gc;
-}
-
-
-rvm_gc_t *rvm_gc_init(rvm_gc_t *gc)
-{
-       r_list_init(&gc->head[0]);
-       r_list_init(&gc->head[1]);
-       gc->active = 0;
-       return gc;
-}
-
-
-void rvm_gc_cleanup(rvm_gc_t *gc)
-{
-       r_memset(gc, 0, sizeof(gc));
-}
-
-void rvm_gc_destroy(rvm_gc_t *gc)
-{
-       rvm_gc_cleanup(gc);
-       r_free(gc);
-}
-
-rhead_t *rvm_gc_activelist(rvm_gc_t *gc)
-{
-       return &gc->head[gc->active];
-}
-
-
-rhead_t *rvm_gc_inactivelist(rvm_gc_t *gc)
-{
-       return &gc->head[(gc->active + 1) & 1];
-}
-
-
-void rvm_gc_savelifes(rvm_gc_t *gc, rvmreg_t *array, ruint size)
-{
-
-}
-
-
-
-
-void rvm_gc_deallocate(rvm_gc_t *gc)
-{
-       rlink_t *pos;
-       rlist_t *inactiv = rvm_gc_inactivelist(gc);
-       robject_t *obj;
-
-       /*
-        * First pass: remove GC managed data from arrays
-        */
-       r_list_foreach(pos, inactiv) {
-               obj = r_list_entry(pos, robject_t, lnk);
-               rvm_reg_array_unref_gcdata(obj);
-       }
-
-       while ((pos = r_list_first(inactiv)) != NULL) {
-               obj = r_list_entry(pos, robject_t, lnk);
-               r_list_del(pos);
-               r_list_init(pos);
-               r_object_destroy(obj);
-       }
-       gc->active = (gc->active + 1) & 1;
-}
-
-
-void rvm_gc_deallocate_all(rvm_gc_t *gc)
-{
-       gc->active = (gc->active + 1) & 1;
-       rvm_gc_deallocate(gc);
-       gc->active = (gc->active + 1) & 1;
-}
-
-
-int rvm_gc_add(rvm_gc_t *gc, robject_t *obj)
-{
-       rlist_t *activ = rvm_gc_activelist(gc);
-
-       if (!r_list_empty(&obj->lnk))
-               return 0;
-       r_list_addt(activ, &obj->lnk);
-#if 0
-       if (obj->type == R_OBJECT_ARRAY) {
-               /*
-                * Go through the data and add to gc. If the array is gc managed
-                * all the data in the array MUST be gc managed too.
-                */
-               int i;
-               rarray_t *array = (rarray_t*)obj;
-               for (i = 0; i < r_array_length(array); i++) {
-                       rvmreg_t *r = (rvmreg_t *)r_array_slot(array, i);
-                       if (rvm_reg_tstflag(r, RVM_INFOBIT_ROBJECT)) {
-                               rvm_gc_add(gc, RVM_REG_GETP(r));
-                       }
-               }
-       } else if (obj->type == R_OBJECT_HARRAY) {
-               /*
-                * Go through the data and add to gc. If the array is gc managed
-                * all the data in the array MUST be gc managed too.
-                */
-               int i;
-               rarray_t *array = ((rharray_t*)obj)->members;
-               for (i = 0; i < r_array_length(array); i++) {
-                       rvmreg_t *r = (rvmreg_t *)r_array_slot(array, i);
-                       if (rvm_reg_tstflag(r, RVM_INFOBIT_ROBJECT)) {
-                               rvm_gc_add(gc, RVM_REG_GETP(r));
-                       }
-               }
-
-       } else {
-               /*
-                * Nothing to do
-                */
-       }
-#endif
-       return 0;
-}
diff --git a/rvm/rvmgc.h b/rvm/rvmgc.h
deleted file mode 100644 (file)
index 2547ba4..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-#ifndef _RVMGC_H_
-#define _RVMGC_H_
-
-#include "rtypes.h"
-#include "rlist.h"
-#include "robject.h"
-#include "rvmreg.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef struct rvm_gc_s {
-       rhead_t head[2];
-       ruint active;
-
-} rvm_gc_t;
-
-void rvm_gc_destroy(rvm_gc_t *gc);
-rvm_gc_t *rvm_gc_create();
-rvm_gc_t *rvm_gc_init(rvm_gc_t *gc);
-void rvm_gc_cleanup(rvm_gc_t *gc);
-
-void rvm_gc_savelifes(rvm_gc_t *gc, rvmreg_t *array, ruint size);
-int rvm_gc_add(rvm_gc_t *gc, robject_t *obj);
-rhead_t *rvm_gc_activelist(rvm_gc_t *gc);
-rhead_t *rvm_gc_inactivelist(rvm_gc_t *gc);
-void rvm_gc_deallocate(rvm_gc_t *gc);
-void rvm_gc_deallocate_all(rvm_gc_t *gc);
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
index bccb1f5..ebdefa8 100644 (file)
@@ -43,7 +43,7 @@ void rvm_op_concat_string_string(rvmcpu_t *cpu, rushort opid, rvmreg_t *res, con
        rstring_t *d = r_string_create_from_rstr(&s1->s);
        r_string_cat(d, &s2->s);
 
-       rvm_gc_add(cpu->gc, (robject_t*)d);
+       r_gc_add(cpu->gc, (robject_t*)d);
        rvm_reg_setstring(res, d);
 }
 
@@ -56,7 +56,7 @@ void rvm_op_concat_long_string(rvmcpu_t *cpu, rushort opid, rvmreg_t *res, const
        r_string_cat(d, &s2->s);
        r_object_destroy((robject_t*)s1);
 
-       rvm_gc_add(cpu->gc, (robject_t*)d);
+       r_gc_add(cpu->gc, (robject_t*)d);
        rvm_reg_setstring(res, d);
 }
 
@@ -69,7 +69,7 @@ void rvm_op_concat_string_long(rvmcpu_t *cpu, rushort opid, rvmreg_t *res, const
        r_string_cat(d, &s2->s);
        r_object_destroy((robject_t*)s2);
 
-       rvm_gc_add(cpu->gc, (robject_t*)d);
+       r_gc_add(cpu->gc, (robject_t*)d);
        rvm_reg_setstring(res, d);
 }
 
@@ -82,7 +82,7 @@ void rvm_op_concat_double_string(rvmcpu_t *cpu, rushort opid, rvmreg_t *res, con
        r_string_cat(d, &s2->s);
        r_object_destroy((robject_t*)s1);
 
-       rvm_gc_add(cpu->gc, (robject_t*)d);
+       r_gc_add(cpu->gc, (robject_t*)d);
        rvm_reg_setstring(res, d);
 }
 
@@ -95,6 +95,6 @@ void rvm_op_concat_string_double(rvmcpu_t *cpu, rushort opid, rvmreg_t *res, con
        r_string_cat(d, &s2->s);
        r_object_destroy((robject_t*)s2);
 
-       rvm_gc_add(cpu->gc, (robject_t*)d);
+       r_gc_add(cpu->gc, (robject_t*)d);
        rvm_reg_setstring(res, d);
 }
index 9f740b1..d1b4a83 100644 (file)
@@ -400,14 +400,14 @@ int rvm_reg_str2num(rvmreg_t *dst, const rvmreg_t *src)
        rdouble d;
        rlong l;
 
-       l = r_strtol(R_STRING2PTR(RVM_REG_GETP(src)), &lptr, 10);
+       l = r_strtol(R_STRING2ANSI(RVM_REG_GETP(src)), &lptr, 10);
        if (!lptr)
                return -1;
        if (*lptr != '.') {
                rvm_reg_setlong(dst, l);
                return 0;
        }
-       d = r_strtod(R_STRING2PTR(RVM_REG_GETP(src)), &dptr);
+       d = r_strtod(R_STRING2ANSI(RVM_REG_GETP(src)), &dptr);
        if (!dptr)
                return -1;
        rvm_reg_setdouble(dst, d);
@@ -420,7 +420,7 @@ int rvm_reg_str2long(rvmreg_t *dst, const rvmreg_t *src)
        rchar *dptr;
        rdouble d;
 
-       d = r_strtod(R_STRING2PTR(RVM_REG_GETP(src)), &dptr);
+       d = r_strtod(R_STRING2ANSI(RVM_REG_GETP(src)), &dptr);
        if (!dptr)
                return -1;
        rvm_reg_setlong(dst, (long)d);
@@ -433,7 +433,7 @@ int rvm_reg_str2double(rvmreg_t *dst, const rvmreg_t *src)
        rchar *dptr;
        rdouble d;
 
-       d = r_strtod(R_STRING2PTR(RVM_REG_GETP(src)), &dptr);
+       d = r_strtod(R_STRING2ANSI(RVM_REG_GETP(src)), &dptr);
        if (!dptr)
                return -1;
        rvm_reg_setdouble(dst, d);
index 5d8e0cc..662a630 100644 (file)
@@ -14,7 +14,7 @@ rlong test_rmap_add(rmap_t *map, const rchar *name, rlong val)
 void test_rmap_print(rmap_t * map, rulong index)
 {
        if (r_map_value(map, index))
-               fprintf(stdout, "(Index: %3ld) Key: %s, Value: %ld\n", index, r_map_key(map, index), *((rlong*)r_map_value(map, index)));
+               fprintf(stdout, "(Index: %3ld) Key: %s, Value: %ld\n", index, R_STRING2ANSI(r_map_key(map, index)), *((rlong*)r_map_value(map, index)));
        else
                fprintf(stdout, "Invalid Index: %ld\n", index);
 }
@@ -27,7 +27,7 @@ void test_rmap_lookup(rmap_t * map, const rchar *name)
        do {
                index = r_map_lookup_s(map, index, name);
                if (index >= 0)
-                       fprintf(stdout, "(Lookup index: %3ld) Key: %s, Value: %ld\n", index, r_map_key(map, index), *((rlong*)r_map_value(map, index)));
+                       fprintf(stdout, "(Lookup index: %3ld) Key: %s, Value: %ld\n", index, R_STRING2ANSI(r_map_key(map, index)), *((rlong*)r_map_value(map, index)));
        } while (index >= 0);
 }
 
@@ -39,7 +39,7 @@ void test_rmap_taillookup(rmap_t * map, const rchar *name)
        do {
                index = r_map_taillookup_s(map, index, name);
                if (index >= 0)
-                       fprintf(stdout, "(Tail Lookup index: %3ld) Key: %s, Value: %ld\n", index, r_map_key(map, index), *((rlong*)r_map_value(map, index)));
+                       fprintf(stdout, "(Tail Lookup index: %3ld) Key: %s, Value: %ld\n", index, R_STRING2ANSI(r_map_key(map, index)), *((rlong*)r_map_value(map, index)));
        } while (index >= 0);
 
 }