typedef void *rpointer;
typedef const void *rconstpointer;
-
/*
* Architecture dependent types. These types have to be redifined
* for every architecture
$(OUTDIR)/ratomic.o \
$(OUTDIR)/rspinlock.o \
$(OUTDIR)/rarray.o \
+ $(OUTDIR)/rlist.o \
+ $(OUTDIR)/rhash.o \
$(OUTDIR)/rstring.o \
rarray_t *array;
if ((array = (rarray_t*)r_malloc(sizeof(*array))) == NULL)
return NULL;
- return r_array_init(array, elt_size);
+ r_memset(array, 0, sizeof(*array));
+ if (!r_array_init(array, elt_size)) {
+ r_array_destroy(array);
+ return NULL;
+ }
+ return array;
}
--- /dev/null
+#include "rmem.h"
+#include "rhash.h"
+
+
+
+rhash_t *r_hash_create(ruint nbits, r_hash_equalfunc eqfunc, r_hash_hashfun hfunc)
+{
+ rhash_t *hash;
+
+ hash = (rhash_t*)r_malloc(sizeof(*hash));
+ if (!hash)
+ return NULL;
+ r_memset(hash, 0, sizeof(*hash));
+ if (!r_hash_init(hash, nbits, eqfunc, hfunc)) {
+ r_hash_destroy(hash);
+ return NULL;
+ }
+ return hash;
+}
+
+
+rhash_t *r_hash_init(rhash_t *hash, ruint nbits, r_hash_equalfunc eqfunc, r_hash_hashfun hfunc)
+{
+ hash->nbits = nbits;
+ hash->eqfunc = eqfunc;
+ hash->hfunc = hfunc;
+ hash->buckets = (rlist_t*)r_malloc(sizeof(rlist_t) * r_hash_size(hash));
+ return NULL;
+}
+
+
+void r_hash_destroy(rhash_t *hash)
+{
+ r_free(hash);
+}
+
+
+void r_hash_cleanup(rhash_t *hash)
+{
+ r_free(hash->buckets);
+}
--- /dev/null
+#ifndef _RHASH_H_
+#define _RHASH_H_
+
+#include "rtypes.h"
+#include "rlist.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+typedef struct rhash_s rhash_t;
+typedef rboolean (*r_hash_equalfunc)(rconstpointer p1, rconstpointer p2);
+typedef ruint (*r_hash_hashfun)(rconstpointer key);
+
+struct rhash_s {
+ rlist_t *buckets;
+ ruint nbits;
+ r_hash_equalfunc eqfunc;
+ r_hash_hashfun hfunc;
+};
+
+
+#define r_hash_size(__h__) (1 << (__h__)->nbits)
+#define r_hash_mask(__h__) (R_HASH_SIZE(__h__) - 1)
+rhash_t *r_hash_create(ruint nbits, r_hash_equalfunc eqfunc, r_hash_hashfun hfunc);
+rhash_t *r_hash_init(rhash_t *hash, ruint nbits, r_hash_equalfunc eqfunc, r_hash_hashfun hfunc);
+void r_hash_destroy(rhash_t *hash);
+void r_hash_cleanup(rhash_t *hash);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
--- /dev/null
+#include "rlist.h"
+
+
+void rpa_list_init(rlist_t *ptr)
+{
+ ptr->next = ptr;
+ ptr->prev = ptr;
+}
+
+
+void rpa_list_add(rlist_t *pNew, rlist_t *pPrev, rlist_t *pNext)
+{
+ pNext->prev = pNew;
+ pNew->next = pNext;
+ pNew->prev = pPrev;
+ pPrev->next = pNew;
+}
+
+
+void rpa_list_addh(rlist_t *pHead, rlist_t *pNew)
+{
+ rpa_list_add(pNew, pHead, (pHead)->next);
+}
+
+
+void rpa_list_addt(rlist_t *pHead, rlist_t *pNew)
+{
+ rpa_list_add(pNew, (pHead)->prev, pHead);
+}
+
+
+void rpa_list_unlink(rlist_t *pPrev, rlist_t *pNext)
+{
+ pNext->prev = pPrev;
+ pPrev->next = pNext;
+}
+
+
+void rpa_list_del(rlist_t *pEntry)
+{
+ rpa_list_unlink((pEntry)->prev, (pEntry)->next);
+}
+
+
+rlist_t *rpa_list_first(rlist_t *pHead)
+{
+ return (((pHead)->next != (pHead)) ? (pHead)->next: ((void*)0));
+}
+
+
+rlist_t *rpa_list_last(rlist_t *pHead)
+{
+ return (((pHead)->prev != (pHead)) ? (pHead)->prev: ((void*)0));
+}
+
+
+rlist_t *rpa_list_prev(rlist_t *pHead, rlist_t *pElem)
+{
+ return (pElem && pElem->prev != pHead) ? (pElem)->prev: ((void*)0);
+}
+
+
+rlist_t *rpa_list_next(rlist_t *pHead, rlist_t *pElem)
+{
+ return (pElem && pElem->next != pHead) ? pElem->next: ((void*)0);
+}
+
+
+void rpa_list_splice(rlist_t *pList, rlist_t *pHead)
+{
+ rlist_t *pFirst;
+
+ pFirst = pList->next;
+ if (pFirst != pList) {
+ rlist_t *pLast = pList->prev;
+ rlist_t *pAt = pHead->next;
+ pFirst->prev = pHead;
+ pHead->next = pFirst;
+ pLast->next = pAt;
+ pAt->prev = pLast;
+ }
+}
+
+
+int rpa_list_count(rlist_t *pHead)
+{
+ rlist_t *pCur;
+ int n = 0;
+
+ r_list_foreach(pCur, pHead)
+ n++;
+ return n;
+}
--- /dev/null
+#ifndef _RLIST_H_
+#define _RLIST_H_
+
+#include "rtypes.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+typedef struct rlist_s rlist_t, rlink_t, rhead_t;
+
+#define R_LIST_HEAD(__name__) {&(__name__), &(__name__) }
+#define r_list(__name__) t __name__ = { &(__name__), &(__name__) }
+#define r_list_empty(__head__) ((__head__)->next == ((void*)0) || (__head__)->next == __head__)
+#define r_list_entry(_ptr, _type, __member__) ((_type *)((char *)(_ptr)-(ruint)(&((_type *)0)->__member__)))
+#define r_list_foreach(__pos__, __head__) for (__pos__ = (__head__)->next; __pos__ != (__head__); __pos__ = (__pos__)->next)
+#define r_list_foreachreverse(__pos__, __head__) for (__pos__ = (__head__)->prev; __pos__ != (__head__); __pos__ = (__pos__)->prev)
+#define r_list_fo_eachsafe(__pos__, __n__, __head__) \
+ for (__pos__ = (__head__)->next, __n__ = __pos__->next; __pos__ != (__head__); __pos__ = __n__, __n__ = __pos__->next)
+
+struct rlist_s {
+ rlist_t *next;
+ rlist_t *prev;
+};
+
+
+void r_list_init(rlist_t *ptr);
+void r_list_check(rlist_t *ptr);
+void r_list_add(rlist_t *pNew, rlist_t *pPrev, rlist_t *pNext);
+void r_list_addh(rlist_t *pHead, rlist_t *pNew);
+void r_list_addt(rlist_t *pHead, rlist_t *pNew);
+void r_list_unlink(rlist_t *pPrev, rlist_t *pNext);
+void r_list_del(rlist_t *pEntry);
+rlist_t *r_list_first(rlist_t *pHead);
+rlist_t *r_list_last(rlist_t *pHead);
+rlist_t *r_list_prev(rlist_t *pHead, rlist_t *pElem);
+rlist_t *r_list_next(rlist_t *pHead, rlist_t *pElem);
+void r_list_splice(rlist_t *pList, rlist_t *pHead);
+int r_list_count(rlist_t *pHead);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
buffer[50] = '\0';
rvm_printf("%s", buffer);
- rvm_printf("0x%lx, 0x%lx, 0x%lx, 0x%lx, 0x%lx, 0x%lx, 0x%lx, 0x%lx, 0x%lx, SP=0x%lx, LR=%ld, PC=%ld, S( %c%c%c%c )",
+ rvm_printf("0x%lx, 0x%lx, 0x%lx, 0x%lx, 0x%lx, 0x%lx, 0x%lx, 0x%lx, 0x%lx, SP=%ld, LR=%ld, PC=%ld, S( %c%c%c%c )",
RVM_GET_REGU(vm, 0), RVM_GET_REGU(vm, 1), RVM_GET_REGU(vm, 2), RVM_GET_REGU(vm, 3),
RVM_GET_REGU(vm, 4), RVM_GET_REGU(vm, 5), RVM_GET_REGU(vm, 6), RVM_GET_REGU(vm, 7),
- RVM_GET_REGU(vm, 8), RVM_GET_REGU(vm, SP), RVM_GET_REGU(vm, LR), (long int)RVM_GET_REGU(vm, PC),
+ RVM_GET_REGU(vm, 8), (long int)RVM_GET_REGU(vm, SP), (long int)RVM_GET_REGU(vm, LR), (long int)RVM_GET_REGU(vm, PC),
vm->status & RVM_STATUS_V ? 'V' : '_',
vm->status & RVM_STATUS_C ? 'C' : '_',
vm->status & RVM_STATUS_N ? 'N' : '_',
};
-enum {
- RVM_DTYPE_WORD = 0,
- RVM_DTYPE_POINTER,
- RVM_DTYPE_DOUBLE,
- RVM_DTYPE_STRING,
- RVM_DTYPE_STRINGPTR,
- RVM_DTYPE_RELOCPTR,
-};
+#define RVM_DTYPE_WORD 0
+#define RVM_DTYPE_POINTER 1
+#define RVM_DTYPE_DOUBLE 2
+#define RVM_DTYPE_STRING 3
+#define RVM_DTYPE_STRINGPTR 4
+#define RVM_DTYPE_RELOCPTR 5
+#define RVM_DTYPE_USER 64
+#define RVM_DTYPE_USERDEF(__n__) (RVM_DTYPE_USER + (__n__))
#define RVM_REGISTER_BITS (8 * sizeof(rword))