aboutsummaryrefslogtreecommitdiff
path: root/src/all.h
diff options
context:
space:
mode:
authorElis Eriksson <spelis@spelis.li>2026-07-01 22:39:28 +0200
committerElis Eriksson <spelis@spelis.li>2026-07-01 22:43:49 +0200
commitb2a53020c9e19b6eb7c6b18afb940bdcf0b604cf (patch)
tree454deffc4365e9d17969d377f13231c06e0c4674 /src/all.h
parent29766e048cabc8db71cb735c424e0fdfff468198 (diff)
downloadbfc-main.tar
bfc-main.tar.gz
bfc-main.tar.bz2
bfc-main.tar.lz
bfc-main.tar.xz
bfc-main.tar.zst
bfc-main.zip
remove utility (ivec, node_vec, str) headersHEADmain
also omit the lexer entirely, plus the parser type.
Diffstat (limited to 'src/all.h')
-rw-r--r--src/all.h84
1 files changed, 54 insertions, 30 deletions
diff --git a/src/all.h b/src/all.h
index c35c8b7..7456824 100644
--- a/src/all.h
+++ b/src/all.h
@@ -1,33 +1,27 @@
#pragma once
-#include "ivec.h"
-#include "node_vec.h"
-#include "str.h"
#include <stdbool.h>
#include <stddef.h>
+#include <stdio.h>
-// Lexer
-
-typedef enum {
- LEX_PINC,
- LEX_PDEC,
- LEX_VINC,
- LEX_VDEC,
- LEX_OUT,
- LEX_IN,
- LEX_LB,
- LEX_RB,
- LEX_EOF
-} lex_tok_e;
+typedef struct {
+ long long *_data;
+ size_t _cap;
+ size_t len;
+} ivec;
typedef struct {
- str *src;
- size_t pos;
- ivec tokens;
-} lexer_t;
+ char *data;
+ size_t length;
+ size_t capacity;
+} str;
+
+typedef struct ast_node ast_node_t;
-lexer_t lex_init(str *src);
-void lex_run(lexer_t *lx);
-void lex_free(lexer_t *lx);
+typedef struct {
+ ast_node_t **_data;
+ size_t _cap;
+ size_t len;
+} node_vec;
// Parser/AST
@@ -52,13 +46,7 @@ struct ast_node {
ast_node_t *next;
};
-typedef struct {
- lexer_t *lx;
- size_t pos;
-} parser_t;
-
-parser_t parser_init(lexer_t *lx);
-ast_node_t *parse_program(parser_t *p);
+ast_node_t *parse(const char *src);
ast_node_t *optimize_ast(ast_node_t *ast);
void ast_free(ast_node_t *node);
void ast_dump(ast_node_t *node, int depth);
@@ -66,3 +54,39 @@ void ast_dump(ast_node_t *node, int depth);
// codegen
str gen_code(ast_node_t *ast);
+
+void iv_free(ivec *v);
+size_t iv_push(ivec *v, long long data);
+long long iv_get(ivec *v, size_t idx);
+long long iv_rem_shift(ivec *v, size_t idx);
+long long iv_rem(ivec *v, size_t idx);
+long long iv_has(ivec *v, long long x,
+ int (*comp)(const long long, const long long));
+void iv_shrink(ivec *v);
+
+void node_vec_free(node_vec *v);
+
+size_t node_vec_push(node_vec *v, ast_node_t *data);
+
+ast_node_t *node_vec_get(node_vec *v, size_t idx);
+
+ast_node_t *node_vec_rem_shift(node_vec *v, size_t idx);
+
+ast_node_t *node_vec_rem(node_vec *v, size_t idx);
+
+ast_node_t *node_vec_has(node_vec *v, ast_node_t *x,
+ int (*comp)(const ast_node_t *, const ast_node_t *));
+
+void node_vec_shrink(node_vec *v);
+
+void free_str(str *s);
+
+void str_append(str *s, const char *from);
+void str_append_c(str *s, char c);
+void str_append_len(str *s, const char *from, size_t len);
+
+void str_append_read(str *s, int fd);
+void str_append_fread(str *s, FILE *file);
+void str_append_fread_len(str *s, size_t size, FILE *file);
+
+void str_appendf(str *s, const char *fmt, ...);