Allow different parse stack heads to lex differently
This commit is contained in:
parent
484721b0c2
commit
64874449e4
4 changed files with 152 additions and 76 deletions
|
|
@ -7,6 +7,7 @@ extern "C" {
|
|||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
|
||||
typedef struct {
|
||||
void *contents;
|
||||
|
|
@ -24,6 +25,24 @@ static inline Vector vector_new(size_t element_size, size_t capacity) {
|
|||
};
|
||||
}
|
||||
|
||||
static inline void *vector_get(Vector *self, size_t index) {
|
||||
assert(index < self->size);
|
||||
return (void *)((char *)self->contents + index * self->element_size);
|
||||
}
|
||||
|
||||
static inline void vector_clear(Vector *self) {
|
||||
self->size = 0;
|
||||
}
|
||||
|
||||
static inline void vector_erase(Vector *self, size_t index) {
|
||||
assert(index < self->size);
|
||||
char *contents = (char *)self->contents;
|
||||
memmove(contents + index * self->element_size,
|
||||
contents + (index + 1) * self->element_size,
|
||||
(self->size - index - 1) * self->element_size);
|
||||
self->size--;
|
||||
}
|
||||
|
||||
static inline void vector_push(Vector *self, void *entry) {
|
||||
if (self->size == self->capacity) {
|
||||
self->capacity += 4;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue