add xvect
This commit is contained in:
parent
1548a17b35
commit
0b4cb76834
|
@ -15,6 +15,78 @@
|
||||||
# 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, void *);
|
||||||
|
static inline void xv_set(xvect *, size_t, void *);
|
||||||
|
|
||||||
|
static inline void xv_push(xvect *, void *);
|
||||||
|
static inline void xv_peek(xvect *, void *);
|
||||||
|
static inline void xv_pop(xvect *, void *);
|
||||||
|
|
||||||
|
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, void *dst)
|
||||||
|
{
|
||||||
|
memcpy(dst, x->data + i * x->width, 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, void *dst)
|
||||||
|
{
|
||||||
|
xv_get(x, x->size, dst);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void
|
||||||
|
xv_pop(xvect *x, void *dst)
|
||||||
|
{
|
||||||
|
xv_get(x, --x->size, dst);
|
||||||
|
}
|
||||||
|
|
||||||
typedef struct analyze_scope {
|
typedef struct analyze_scope {
|
||||||
/* rest args variable is counted by localc */
|
/* rest args variable is counted by localc */
|
||||||
bool varg;
|
bool varg;
|
||||||
|
|
Loading…
Reference in New Issue