1 |
|
|
#include "gwion_util.h" |
2 |
|
|
#include "gwion_ast.h" |
3 |
|
|
#include "gwion_env.h" |
4 |
|
|
#include "vm.h" |
5 |
|
|
#include "gwion.h" |
6 |
|
|
#include "instr.h" |
7 |
|
|
#include "emit.h" |
8 |
|
|
#include "escape.h" |
9 |
|
|
|
10 |
|
809 |
static ANEW ANN VM_Code emit_code(const Emitter emit) { |
11 |
|
809 |
Code* const c = emit->code; |
12 |
|
809 |
const VM_Code code = new_vm_code(emit->gwion->mp, &c->instr, c->stack_depth, |
13 |
|
|
c->flag, c->name); |
14 |
|
809 |
return code; |
15 |
|
|
} |
16 |
|
|
|
17 |
|
733 |
ANEW Emitter new_emitter(MemPool p) { |
18 |
|
733 |
Emitter emit = (Emitter)mp_calloc(p, Emitter); |
19 |
|
733 |
vector_init(&emit->stack); |
20 |
|
733 |
emit->info = (struct EmitterInfo_*)mp_calloc(p, EmitterInfo); |
21 |
|
733 |
vector_init(&emit->info->pure); |
22 |
|
733 |
emit->info->escape = escape_table(p); |
23 |
|
733 |
emit->info->emit_code = emit_code; |
24 |
|
733 |
emit->info->finalyzer = EOC; |
25 |
|
733 |
return emit; |
26 |
|
|
} |
27 |
|
|
|
28 |
|
732 |
ANN void free_emitter(MemPool p, Emitter a) { |
29 |
|
732 |
vector_release(&a->stack); |
30 |
|
732 |
vector_release(&a->info->pure); |
31 |
|
732 |
mp_free2(p, 256, a->info->escape); |
32 |
|
732 |
mp_free(p, EmitterInfo, a->info); |
33 |
|
732 |
mp_free(p, Emitter, a); |
34 |
|
732 |
} |
35 |
|
|
|
36 |
|
|
__attribute__((returns_nonnull)) |
37 |
|
19403 |
ANN2(1) Instr emit_add_instr(const Emitter emit, const f_instr f) { |
38 |
|
19403 |
const Instr instr = mp_calloc(emit->gwion->mp, Instr); |
39 |
✓✓ |
19403 |
if((m_uint)f < 255) |
40 |
|
19180 |
instr->opcode = (m_uint)f; |
41 |
|
|
else { |
42 |
|
223 |
instr->opcode = eOP_MAX; |
43 |
|
223 |
instr->execute = f; |
44 |
|
|
} |
45 |
|
19403 |
vector_add(&emit->code->instr, (vtype)instr); |
46 |
|
19403 |
return instr; |
47 |
|
|
} |