split xvect module

This commit is contained in:
Yuichi Nishiwaki 2014-03-20 23:09:45 +09:00
parent 53cd2942d1
commit cfde253f26
4 changed files with 5 additions and 72 deletions

3
.gitmodules vendored
View File

@ -7,3 +7,6 @@
[submodule "extlib/xrope"] [submodule "extlib/xrope"]
path = extlib/xrope path = extlib/xrope
url = git://github.com/wasabiz/xrope.git url = git://github.com/wasabiz/xrope.git
[submodule "extlib/xvect"]
path = extlib/xvect
url = git://github.com/wasabiz/xvect.git

1
extlib/xvect Submodule

@ -0,0 +1 @@
Subproject commit 973b9f3d89ff4669d08f1bc28e205bd9834bef10

View File

@ -35,6 +35,7 @@ extern "C" {
#include <stdint.h> #include <stdint.h>
#include <assert.h> #include <assert.h>
#include "xvect/xvect.h"
#include "xhash/xhash.h" #include "xhash/xhash.h"
#include "xfile/xfile.h" #include "xfile/xfile.h"
#include "xrope/xrope.h" #include "xrope/xrope.h"

View File

@ -15,78 +15,6 @@
# error enable PIC_NONE_IS_FALSE # error enable PIC_NONE_IS_FALSE
#endif #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 { typedef struct analyze_scope {
bool varg; bool varg;
xvect args, locals; /* rest args variable is counted as a local */ xvect args, locals; /* rest args variable is counted as a local */