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 |
|
856 |
static ANEW ANN VM_Code emit_code(const Emitter emit) { |
11 |
|
856 |
Code* const c = emit->code; |
12 |
|
856 |
const VM_Code code = new_vm_code(emit->gwion->mp, &c->instr, c->stack_depth, |
13 |
|
|
c->flag, c->name); |
14 |
|
856 |
return code; |
15 |
|
|
} |
16 |
|
|
|
17 |
|
715 |
ANEW Emitter new_emitter(MemPool p) { |
18 |
|
715 |
Emitter emit = (Emitter)mp_calloc(p, Emitter); |
19 |
|
715 |
vector_init(&emit->stack); |
20 |
|
715 |
emit->info = (struct EmitterInfo_*)mp_calloc(p, EmitterInfo); |
21 |
|
715 |
vector_init(&emit->info->pure); |
22 |
|
715 |
emit->info->escape = escape_table(p); |
23 |
|
715 |
emit->info->emit_code = emit_code; |
24 |
|
715 |
emit->info->finalyzer = EOC; |
25 |
|
715 |
return emit; |
26 |
|
|
} |
27 |
|
|
|
28 |
|
714 |
ANN void free_emitter(MemPool p, Emitter a) { |
29 |
|
714 |
vector_release(&a->stack); |
30 |
|
714 |
vector_release(&a->info->pure); |
31 |
|
714 |
mp_free2(p, 256, a->info->escape); |
32 |
|
714 |
mp_free(p, EmitterInfo, a->info); |
33 |
|
714 |
mp_free(p, Emitter, a); |
34 |
|
714 |
} |
35 |
|
|
|
36 |
|
|
__attribute__((returns_nonnull)) |
37 |
|
19922 |
ANN2(1) Instr emit_add_instr(const Emitter emit, const f_instr f) { |
38 |
|
19922 |
const Instr instr = mp_calloc(emit->gwion->mp, Instr); |
39 |
✓✓ |
19922 |
if((m_uint)f < 255) |
40 |
|
19672 |
instr->opcode = (m_uint)f; |
41 |
|
|
else { |
42 |
|
250 |
instr->opcode = eOP_MAX; |
43 |
|
250 |
instr->execute = f; |
44 |
|
|
} |
45 |
|
19922 |
vector_add(&emit->code->instr, (vtype)instr); |
46 |
|
19922 |
return instr; |
47 |
|
|
} |