blob: 1ed98f3ce707bbf370625c2f9145f01c3a9c368c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
#ifndef AMALGAM_COMPILER_H
#define AMALGAM_COMPILER_H
#include "std/misc.h"
#include "std/buffer.h"
#include "std/buffer_view.h"
#include "std/arena_allocator.h"
#include "std/thread_pool.h"
#include "compiler_options.h"
#include "ast.h"
#include "program.h"
#define AMAL_COMPILER_OK 0
/* General error */
#define AMAL_COMPILER_ERR -1
#define AMAL_COMPILER_WORK_FAIL_ABORT -2
#define NUM_ARITHMETIC_TYPES 10
typedef struct {
LhsExpr lhs_expr;
bool is_signed;
} amal_default_type;
typedef struct {
amal_default_type *i8;
amal_default_type *i16;
amal_default_type *i32;
amal_default_type *i64;
amal_default_type *u8;
amal_default_type *u16;
amal_default_type *u32;
amal_default_type *u64;
amal_default_type *isize;
amal_default_type *usize;
amal_default_type *f32;
amal_default_type *f64;
amal_default_type *str;
amal_default_type *arithmetic_types[NUM_ARITHMETIC_TYPES];
} amal_default_types;
bool is_arithmetic_type(LhsExpr *expr, amal_compiler *compiler);
struct amal_compiler {
amal_default_types default_types;
amal_compiler_options options;
amal_program *program;
ArenaAllocator allocator;
Scope root_scope;
Buffer/*<Parser*>*/ parsers;
HashMapType(BufferView, FileScopeReference*) file_scopes;
bool started;
amal_mutex mutex;
amal_thread_pool stage_task_thread_pool;
};
void amal_compiler_options_init(amal_compiler_options *self);
/*
If @options is NULL, then default values are used.
@options are copied.
You should run @amal_program_deinit even @amal_compiler_load_file fails, to cleanup memory.
This function creates a copy of @filepath so it doesn't have to survive longer than this function call.
The file has to be in utf-8 format and it can optionally have utf-8 BOM.
*/
CHECK_RESULT int amal_compiler_load_file(amal_compiler_options *options, amal_program *program, const char *filepath);
CHECK_RESULT int amal_compiler_internal_load_file(amal_compiler *self, const char *filepath, FileScopeReference **file_scope);
/*
Returns a reference to the parsers tokenizer that contains the code reference, or NULL.
Note: The lifetime of the tokenizer returned is the same as the lifetime of the parser that owns it.
Should only be called once code has been parsed (in AST stage or later), in which case it's thread-safe.
*/
Tokenizer* amal_compiler_find_tokenizer_by_code_reference(amal_compiler *self, const char *code_ref);
#endif
|