-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompile.h
More file actions
43 lines (34 loc) · 913 Bytes
/
Copy pathcompile.h
File metadata and controls
43 lines (34 loc) · 913 Bytes
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
#pragma once
#include <stdbool.h>
#include <stddef.h>
#include "vm.h"
#include "b_ast.h"
typedef struct VarPos {
unsigned int scope, pos;
} VarPos;
typedef struct VarDict {
unsigned int v;
bool has;
struct VarDict **chs;
} VarDict;
VarDict *VarDict_new();
void VarDict_insert(VarDict *dict, char *key, unsigned int var);
unsigned int *VarDict_find(VarDict *dict, char *key);
void VarDict_free(VarDict *dict);
typedef struct VarScope {
VarDict *vars;
struct VarScope *parent;
} VarScope;
VarScope *VarScope_new(VarScope *parent, VarDict *vars);
VarPos *VarScope_find(VarScope *scope, char *name);
void VarScope_free(VarScope *scope);
typedef struct Seq(size_t) PcList;
typedef struct Compiler {
VarScope *scope;
ByteCodeList code;
PcList w_jmps;
PcList w_begin;
} Compiler;
Compiler *Compiler_new();
void Compiler_free(Compiler *c);
size_t compile_program(Compiler *c, ASTNode *node);