diff options
Diffstat (limited to 'include')
| -rw-r--r-- | include/lex.h | 4 | ||||
| -rw-r--r-- | include/lib/arena.h | 31 | ||||
| -rw-r--r-- | include/lib/vector.h | 2 | ||||
| -rw-r--r-- | include/parser.h | 79 | ||||
| -rw-r--r-- | include/passdbg.h | 9 |
5 files changed, 122 insertions, 3 deletions
diff --git a/include/lex.h b/include/lex.h index bdfd32f..ab09baf 100644 --- a/include/lex.h +++ b/include/lex.h @@ -30,6 +30,7 @@ #define TOKEN_MINUS 22 #define TOKEN_STAR 23 #define TOKEN_SLASH 24 +#define TOKEN_BANG 25 const char* lex_get_token_name(int id); @@ -40,8 +41,7 @@ const char* lex_get_token_name(int id); struct token { int type; -// size_t line; -// size_t linepos; + size_t line; size_t length; char *lexeme; }; diff --git a/include/lib/arena.h b/include/lib/arena.h new file mode 100644 index 0000000..9d3cb38 --- /dev/null +++ b/include/lib/arena.h @@ -0,0 +1,31 @@ +/** + * @file arena.h + * @author x221e + * @brief linear arena-allocation without relocation + * @description + * This will be a linear arena allocation, + * no free functionality exists right now. + * + * @todo create a larger arena structure that would hold regions + */ + +#ifndef ARENA_H +#define ARENA_H + +#include <stddef.h> + +// 2 MiB regions +#define REGION_MAX_CAPACITY 1024*1024*2 + +struct region { // or arena? + size_t capacity; + size_t size; + void *end; + void *start; +}; + +int region_init(struct region *r); +void *region_alloc(struct region *r, size_t b); +int region_pop(struct region *r, size_t b); + +#endif diff --git a/include/lib/vector.h b/include/lib/vector.h index 33e5b97..e0cc523 100644 --- a/include/lib/vector.h +++ b/include/lib/vector.h @@ -16,6 +16,6 @@ struct vector { int vector_init(struct vector *v); int vector_resize(struct vector *v, size_t nc); int vector_emplace_back(struct vector *v, void *p); -int vector_deinit(struct vector *v); +int vector_free(struct vector *v); #endif diff --git a/include/parser.h b/include/parser.h new file mode 100644 index 0000000..a927475 --- /dev/null +++ b/include/parser.h @@ -0,0 +1,79 @@ +/** + * @file parser.h + * @author x221e + * @brief parser + * @description + * I am opting-in to AST producing compiler design. It is not strictly + * needed in this context, however, it will produce optimization benefits + * in the future. + * + * @warning DEFINETLY NEEDS ARENA ALLOC IMPL // prototyping one under lib/ + */ + +#ifndef PARSER_H +#define PARSER_H + +#include <stddef.h> + +#include <lex.h> + +typedef struct vector vector; + +struct parser { + struct region *tokens; + struct vector *result; //TODO: replace with arena,, temporary + struct region *buffer; + size_t size; + size_t pos; + + int error; +}; + +enum node_type { // Or should I use macros??? + N_INVALID = -1, + N_EXPR = 0, + N_LITERAL = 1, + N_UNARY, + N_BINARY, +}; + +enum data_type { + DT_INVALID = -1, + DT_UNSIGNED64, + DT_UNSIGNED32, + DT_UNSIGNED16, + DT_UNSIGNED8, +}; + +struct node_primary { + enum node_type ntype; + enum data_type type; + + int is_number; + union { + size_t number; + char* str; + } value; +}; + +struct node_unary { + enum node_type ntype; + + struct token operator; + void *expr; +}; + +struct node_binary { + enum node_type ntype; + struct token operator; + void *left; + void *right; +}; + +struct node { + enum node_type ntype; +}; + +void parser_parse(struct parser *p); + +#endif diff --git a/include/passdbg.h b/include/passdbg.h new file mode 100644 index 0000000..15643d8 --- /dev/null +++ b/include/passdbg.h @@ -0,0 +1,9 @@ +#ifndef PASSDBG_H +#define PASSDBG_H + +void passdbg_primary(void *n); +void passdbg_unary(void *n); +void passdbg_binary(void *n); +void passdbg_walk(void *n); + +#endif |
