From cfde253f260961772a2ebd73d81d18d250b573e9 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Thu, 20 Mar 2014 23:09:45 +0900 Subject: [PATCH] split xvect module --- .gitmodules | 3 ++ extlib/xvect | 1 + include/picrin.h | 1 + src/codegen.c | 72 ------------------------------------------------ 4 files changed, 5 insertions(+), 72 deletions(-) create mode 160000 extlib/xvect diff --git a/.gitmodules b/.gitmodules index 578e58a1..e676f24f 100644 --- a/.gitmodules +++ b/.gitmodules @@ -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 diff --git a/extlib/xvect b/extlib/xvect new file mode 160000 index 00000000..973b9f3d --- /dev/null +++ b/extlib/xvect @@ -0,0 +1 @@ +Subproject commit 973b9f3d89ff4669d08f1bc28e205bd9834bef10 diff --git a/include/picrin.h b/include/picrin.h index 8ae0be90..e2fa4212 100644 --- a/include/picrin.h +++ b/include/picrin.h @@ -35,6 +35,7 @@ extern "C" { #include #include +#include "xvect/xvect.h" #include "xhash/xhash.h" #include "xfile/xfile.h" #include "xrope/xrope.h" diff --git a/src/codegen.c b/src/codegen.c index 8632a028..f6a877fc 100644 --- a/src/codegen.c +++ b/src/codegen.c @@ -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 */