aboutsummaryrefslogtreecommitdiff
path: root/include/parser.h
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2019-02-27 22:26:35 +0100
committerdec05eba <dec05eba@protonmail.com>2020-07-25 14:36:46 +0200
commit76d85a10f6cda93eba29dad5372e8160af7289c8 (patch)
treecfec3043ec45a5e83494ec109e87c239dad6cc47 /include/parser.h
parent8201cd9f40897cf6b8e6973b28a8661108702ab1 (diff)
Use multiple threads to parse
Diffstat (limited to 'include/parser.h')
-rw-r--r--include/parser.h40
1 files changed, 33 insertions, 7 deletions
diff --git a/include/parser.h b/include/parser.h
index e90871f..9b41e5e 100644
--- a/include/parser.h
+++ b/include/parser.h
@@ -1,25 +1,51 @@
#ifndef AMALGAM_PARSER_H
#define AMALGAM_PARSER_H
-#include "buffer.h"
-#include "buffer_view.h"
+#include "std/buffer.h"
+#include "std/buffer_view.h"
+#include "std/scoped_allocator.h"
+#include "std/thread.h"
#include "tokenizer.h"
-#include "scoped_allocator.h"
+#include "defs.h"
#define PARSER_OK 0
/* General error */
#define PARSER_ERR -1
#define PARSER_UNEXPECTED_TOKEN -2
+typedef enum {
+ PARSER_THREAD_STATUS_NEW,
+ PARSER_THREAD_STATUS_IDLE,
+ PARSER_THREAD_STATUS_RUNNING
+} ParserThreadStatus;
+
+struct ParserThreadData {
+ amal_thread thread;
+ ParserThreadStatus status;
+ ScopedAllocator allocator;
+};
+
typedef struct {
Tokenizer tokenizer;
- ScopedAllocator allocator;
Buffer ast_objects;
+ ScopedAllocator *allocator; /* borrowed. Copied from @compiler for faster access to allocator */
+ amal_compiler *compiler;
+ bool started;
} Parser;
-CHECK_RESULT int parser_init(Parser *self);
-void parser_deinit(Parser *self);
+CHECK_RESULT int parser_thread_data_init(ParserThreadData *self);
+CHECK_RESULT int parser_thread_data_deinit(ParserThreadData *self);
+CHECK_RESULT int parser_thread_data_start(ParserThreadData *self, AmalThreadCallbackFunc callback_func, void *userdata);
+CHECK_RESULT int parser_thread_data_join(ParserThreadData *self, void **result);
+
+CHECK_RESULT int parser_init(Parser *self, amal_compiler *compiler, ScopedAllocator *allocator);
-CHECK_RESULT int parser_parse_buffer(Parser *self, BufferView code_buffer);
+/*
+@buffer_name will be the path to the file when using parser_parse_file and when parsing a buffer
+you can name the buffer anything you want to identify it.
+*/
+CHECK_RESULT int parser_parse_buffer(Parser *self, BufferView code_buffer, BufferView buffer_name);
+/* Parses a file and the dependencies that are included using @import */
+CHECK_RESULT int parser_parse_file(Parser *self, BufferView filepath);
#endif