Newer
Older
Michal Štěpánek
committed
#pragma once
#include "parser.h"
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
typedef struct String {
u32 len;
u32 capacity;
u8 * str;
} String;
typedef struct Function {
Str name;
u8 parameters;
u16 locals;
String bc;
} Function;
typedef struct Class {
u16 fields;
u16 * indexes;
} Class;
void string_init ( String * str );
void string_destroy ( String * str );
void string_write_byte ( String * str, const u8 data );
void string_write_u16 ( String * str, const u16 data );
void string_write_i32 ( String * str, const i32 data );
typedef struct Constants {
Str * strings;
i32 * integers;
bool bools [2];
i32 null_pos;
Function * functions;
Class * classes;
} Constants;
typedef struct Globals {
Str * names;
} Globals;
typedef struct LocalScope {
LocalScope * prev;
Str * names;
u16 * locals;
} LocalScope;
typedef struct BCCompilerState {
Constants constants;
Globals globals;
LocalScope scope;
} BCCompilerState;
void ast_to_bc ( Ast * ast, String * bc );
void generate_bc ( Ast * ast, String * bc );