-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontext.h
73 lines (51 loc) · 1.66 KB
/
context.h
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
//
// Created by fathi on 10/20/2024.
//
#ifndef TIGE_CONTEXT_H
#define TIGE_CONTEXT_H
#include <stdlib.h>
#include "parser.h"
#include "lexer.h"
#include "symbol_table.h"
#include "vm.h"
#include "bytecode_buffer.h"
typedef struct Context Context;
typedef struct FunctionEntry {
char *name; // Key: Function name
Function *function; // Value: Pointer to Function Object
UT_hash_handle hh; // Makes this structure hashable
} FunctionEntry;
struct Context {
// code information
char* source;
size_t source_length;
// Lexer and parser instances
Lexer lexer;
Parser parser;
ASTNode* ast;
ErrorList* error_list;
// scope checking for the compilation phase
SymbolTable* symbols;
// total allocated memory
size_t total_mem;
// the virtual machine that will execute our bytecode
VM* vm;
// the compiled code from AST
BytecodeBuffer* code;
// Functions map
FunctionEntry *functions;
};
bool register_function(Context *context, const char *name, Function* function_obj);
Function *get_function(Context *context, const char *name);
void ctx_init(Context* ctx, const char* source_code);
bool ctx_is_initialized(Context *context);
void ctx_start_parsing(Context *context);
bool ctx_check_errors(Context *context);
void ctx_clean_parse_info(Context *context);
bool ctx_is_vm_initialized(Context *context);
void ctx_create_vm(Context *context);
VM *ctx_get_active_vm(Context *context);
void ctx_get_compiled_code(Context *context, BytecodeBuffer **buf);
void vm_swap_code_buffer(VM *vm, BytecodeBuffer *buffer);
void ctx_destroy(Context* context);
#endif //TIGE_CONTEXT_H