Create expression struct and memory pool
This commit is contained in:
27
lib/include/expression.h
Normal file
27
lib/include/expression.h
Normal file
@@ -0,0 +1,27 @@
|
||||
#ifndef EXPRESSION_H
|
||||
#define EXPRESSION_H
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
typedef enum {
|
||||
OPERATOR_ADD,
|
||||
OPERATOR_SUBTRACT,
|
||||
OPERATOR_MULTIPLY,
|
||||
OPERATOR_DIVIDE,
|
||||
} operator_t;
|
||||
|
||||
struct _expression_t;
|
||||
typedef struct {
|
||||
operator_t operator;
|
||||
const struct _expression_t *operands[2];
|
||||
} application_t;
|
||||
|
||||
typedef struct _expression_t {
|
||||
bool is_number;
|
||||
union {
|
||||
application_t application;
|
||||
int number;
|
||||
};
|
||||
} expression_t;
|
||||
|
||||
#endif
|
||||
16
lib/include/memory_pool.h
Normal file
16
lib/include/memory_pool.h
Normal file
@@ -0,0 +1,16 @@
|
||||
#ifndef MEMORY_POOL_H
|
||||
#define MEMORY_POOL_H
|
||||
|
||||
#include "expression.h"
|
||||
|
||||
#define MEMORY_POOL_SIZE 128U
|
||||
|
||||
typedef struct {
|
||||
expression_t buffer[MEMORY_POOL_SIZE];
|
||||
expression_t *free_pointer;
|
||||
} memory_pool_t;
|
||||
|
||||
void init_memory_pool(memory_pool_t *pool);
|
||||
expression_t *allocate_expression(memory_pool_t *pool);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user