aboutsummaryrefslogtreecommitdiff
path: root/include/compiler.h
blob: 3a31ad9ee4336b4c18cb2b3b6c89589b4863f04e (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
#ifndef AMALGAM_COMPILER_H
#define AMALGAM_COMPILER_H

#include "std/misc.h"
#include "std/buffer.h"
#include "std/buffer_view.h"
#include "std/scoped_allocator.h"
#include "std/thread.h"
#include "compiler_options.h"
#include "ast.h"

#define AMAL_COMPILER_OK 0
/* General error */
#define AMAL_COMPILER_ERR -1

typedef struct {
    LhsExpr *i8;
    LhsExpr *i16;
    LhsExpr *i32;
    LhsExpr *i64;
    LhsExpr *u8;
    LhsExpr *u16;
    LhsExpr *u32;
    LhsExpr *u64;
    LhsExpr *isize;
    LhsExpr *usize;
    LhsExpr *f32;
    LhsExpr *f64;
    LhsExpr *str;
} amal_default_types;

struct amal_compiler {
    amal_default_types default_types;
    amal_compiler_options options;
    ScopedAllocator allocator;
    Scope root_scope;
    Buffer/*<Parser*>*/ parsers;
    Buffer/*<FileScopeReference*>*/ queued_files;
    HashMap/*<BufferView, FileScopeReference*>*/ file_scopes;
    ParserThreadData *threads;
    int usable_thread_count;
    bool started;
    bool used;
    amal_mutex mutex;
    int generic_work_object_index;
};

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);
CHECK_RESULT int amal_compiler_internal_load_file(amal_compiler *self, const char *filepath, FileScopeReference **file_scope);
/* TODO: amal_compiler_unload_file */

#endif