Create simple, bump allocator store
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
add_library(imp
|
||||
memory_stream.c
|
||||
store.c
|
||||
token.c
|
||||
)
|
||||
target_include_directories(imp PUBLIC include)
|
||||
|
||||
16
lib/include/store.h
Normal file
16
lib/include/store.h
Normal file
@@ -0,0 +1,16 @@
|
||||
#ifndef STORE_H
|
||||
#define STORE_H
|
||||
|
||||
#include "expr.h"
|
||||
|
||||
#define STORE_SIZE 256U
|
||||
|
||||
typedef struct {
|
||||
expr_t *free;
|
||||
expr_t buffer[STORE_SIZE];
|
||||
} store_t;
|
||||
|
||||
void store_init(store_t *store);
|
||||
expr_t *store_alloc(store_t *store);
|
||||
|
||||
#endif
|
||||
14
lib/store.c
Normal file
14
lib/store.c
Normal file
@@ -0,0 +1,14 @@
|
||||
#include "store.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
void store_init(store_t *store)
|
||||
{
|
||||
memset(store, 0, sizeof(store_t));
|
||||
store->free = store->buffer;
|
||||
}
|
||||
|
||||
expr_t *store_alloc(store_t *store)
|
||||
{
|
||||
return store->free++;
|
||||
}
|
||||
Reference in New Issue
Block a user