aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/compiler.h12
-rw-r--r--include/compiler_options.h11
-rw-r--r--include/parser.h1
-rw-r--r--include/std/buffer.h2
-rw-r--r--include/tokenizer.h4
5 files changed, 26 insertions, 4 deletions
diff --git a/include/compiler.h b/include/compiler.h
index b80d7c1..3a31ad9 100644
--- a/include/compiler.h
+++ b/include/compiler.h
@@ -6,7 +6,7 @@
#include "std/buffer_view.h"
#include "std/scoped_allocator.h"
#include "std/thread.h"
-#include "defs.h"
+#include "compiler_options.h"
#include "ast.h"
#define AMAL_COMPILER_OK 0
@@ -31,6 +31,7 @@ typedef struct {
struct amal_compiler {
amal_default_types default_types;
+ amal_compiler_options options;
ScopedAllocator allocator;
Scope root_scope;
Buffer/*<Parser*>*/ parsers;
@@ -39,17 +40,22 @@ struct amal_compiler {
ParserThreadData *threads;
int usable_thread_count;
bool started;
+ bool used;
amal_mutex mutex;
int generic_work_object_index;
};
-CHECK_RESULT int amal_compiler_init(amal_compiler *self);
+void amal_compiler_options_init(amal_compiler_options *self);
+
+/* If @options is NULL, then default values are used */
+CHECK_RESULT int amal_compiler_init(amal_compiler *self, const amal_compiler_options *options);
CHECK_RESULT int amal_compiler_deinit(amal_compiler *self);
/*
This function creates a copy of @filepath in the same thread it's called from
so it doesn't have to survive longer than this function call.
*/
-CHECK_RESULT int amal_compiler_load_file(amal_compiler *self, const char *filepath, FileScopeReference **file_scope);
+CHECK_RESULT int amal_compiler_load_file(amal_compiler *self, const char *filepath);
+CHECK_RESULT int amal_compiler_internal_load_file(amal_compiler *self, const char *filepath, FileScopeReference **file_scope);
/* TODO: amal_compiler_unload_file */
#endif
diff --git a/include/compiler_options.h b/include/compiler_options.h
new file mode 100644
index 0000000..1854372
--- /dev/null
+++ b/include/compiler_options.h
@@ -0,0 +1,11 @@
+#ifndef AMALGAM_COMPILER_OPTIONS_H
+#define AMALGAM_COMPILER_OPTIONS_H
+
+typedef void(*amal_compiler_error_callback)(const char *err_msg, int err_msg_len, void *userdata);
+
+typedef struct {
+ amal_compiler_error_callback error_callback;
+ void *error_callback_userdata;
+} amal_compiler_options;
+
+#endif
diff --git a/include/parser.h b/include/parser.h
index 0261800..8a339ff 100644
--- a/include/parser.h
+++ b/include/parser.h
@@ -41,6 +41,7 @@ struct Parser {
bool has_func_parent;
ScopedAllocator *allocator; /* borrowed. Copied from @compiler for faster access to allocator */
amal_compiler *compiler;
+ SsaCompilerContext *ssa_context;
bool started;
TokenizerError error;
ErrorContext error_context;
diff --git a/include/std/buffer.h b/include/std/buffer.h
index a1bfb01..723ef6c 100644
--- a/include/std/buffer.h
+++ b/include/std/buffer.h
@@ -20,6 +20,8 @@ CHECK_RESULT int buffer_init(Buffer *self, struct ScopedAllocator *allocator);
CHECK_RESULT int buffer_append(Buffer *self, const void *data, usize size);
void* buffer_get(Buffer *self, usize index, usize type_size);
CHECK_RESULT int buffer_pop(Buffer *self, void *data, usize size);
+/* Set buffer size to 0, doesn't reallocate */
+void buffer_clear(Buffer *self);
void* buffer_start(Buffer *self);
void* buffer_end(Buffer *self);
usize __buffer_get_size(Buffer *self, usize type_size);
diff --git a/include/tokenizer.h b/include/tokenizer.h
index 3944ed1..d10b789 100644
--- a/include/tokenizer.h
+++ b/include/tokenizer.h
@@ -5,6 +5,7 @@
#include "std/misc.h"
#include "std/defs.h"
#include "binop_type.h"
+#include "compiler_options.h"
#define TOKENIZER_OK 0
/* General error */
@@ -55,6 +56,7 @@ typedef struct {
} value;
bool number_is_integer;
ScopedAllocator *allocator; /* borrowed */
+ const amal_compiler_options *compiler_options; /* borrowed */
} Tokenizer;
typedef struct {
@@ -62,7 +64,7 @@ typedef struct {
char* str;
} TokenizerError;
-CHECK_RESULT int tokenizer_init(Tokenizer *self, ScopedAllocator *allocator, BufferView code, BufferView code_name);
+CHECK_RESULT int tokenizer_init(Tokenizer *self, ScopedAllocator *allocator, BufferView code, BufferView code_name, const amal_compiler_options *compiler_options);
CHECK_RESULT int tokenizer_accept(Tokenizer *self, Token expected_token);
/*
@result is set to 0 if the next token is equal to @expected_token,