split xvect module
This commit is contained in:
parent
53cd2942d1
commit
cfde253f26
|
@ -7,3 +7,6 @@
|
|||
[submodule "extlib/xrope"]
|
||||
path = extlib/xrope
|
||||
url = git://github.com/wasabiz/xrope.git
|
||||
[submodule "extlib/xvect"]
|
||||
path = extlib/xvect
|
||||
url = git://github.com/wasabiz/xvect.git
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Subproject commit 973b9f3d89ff4669d08f1bc28e205bd9834bef10
|
|
@ -35,6 +35,7 @@ extern "C" {
|
|||
#include <stdint.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "xvect/xvect.h"
|
||||
#include "xhash/xhash.h"
|
||||
#include "xfile/xfile.h"
|
||||
#include "xrope/xrope.h"
|
||||
|
|
|
@ -15,78 +15,6 @@
|
|||
# error enable PIC_NONE_IS_FALSE
|
||||
#endif
|
||||
|
||||
typedef struct xvect {
|
||||
char *data;
|
||||
size_t size, capa, width;
|
||||
} xvect;
|
||||
|
||||
static inline void xv_init(xvect *, size_t);
|
||||
static inline void xv_destroy(xvect *);
|
||||
|
||||
static inline void xv_reserve(xvect *, size_t);
|
||||
|
||||
static inline void *xv_get(xvect *, size_t);
|
||||
static inline void xv_set(xvect *, size_t, void *);
|
||||
|
||||
static inline void xv_push(xvect *, void *);
|
||||
static inline void *xv_peek(xvect *);
|
||||
static inline void *xv_pop(xvect *);
|
||||
|
||||
static inline void
|
||||
xv_init(xvect *x, size_t width)
|
||||
{
|
||||
x->data = NULL;
|
||||
x->size = 0;
|
||||
x->capa = 0;
|
||||
x->width = width;
|
||||
}
|
||||
|
||||
static inline void
|
||||
xv_destroy(xvect *x)
|
||||
{
|
||||
free(x->data);
|
||||
}
|
||||
|
||||
static inline void
|
||||
xv_reserve(xvect *x, size_t newcapa)
|
||||
{
|
||||
x->data = realloc(x->data, newcapa * x->width);
|
||||
x->capa = newcapa;
|
||||
}
|
||||
|
||||
static inline void *
|
||||
xv_get(xvect *x, size_t i)
|
||||
{
|
||||
return x->data + i * x->width;
|
||||
}
|
||||
|
||||
static inline void
|
||||
xv_set(xvect *x, size_t i, void *src)
|
||||
{
|
||||
memcpy(x->data + i * x->width, src, x->width);
|
||||
}
|
||||
|
||||
static inline void
|
||||
xv_push(xvect *x, void *src)
|
||||
{
|
||||
if (x->capa <= x->size + 1) {
|
||||
xv_reserve(x, x->size * 2 + 1);
|
||||
}
|
||||
xv_set(x, x->size++, src);
|
||||
}
|
||||
|
||||
static inline void *
|
||||
xv_peek(xvect *x)
|
||||
{
|
||||
return xv_get(x, x->size);
|
||||
}
|
||||
|
||||
static inline void *
|
||||
xv_pop(xvect *x)
|
||||
{
|
||||
return xv_get(x, --x->size);
|
||||
}
|
||||
|
||||
typedef struct analyze_scope {
|
||||
bool varg;
|
||||
xvect args, locals; /* rest args variable is counted as a local */
|
||||
|
|
Loading…
Reference in New Issue