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 "clean.h" |
7 |
|
|
|
8 |
|
43354 |
ANN static void free_func(Func a, Gwion gwion) { |
9 |
✓✓ |
43354 |
if(GET_FLAG(a, template)) |
10 |
|
35 |
func_def_cleaner(gwion, a->def); |
11 |
✓✓ |
43354 |
if(a->code) |
12 |
|
43251 |
REM_REF(a->code, gwion); |
13 |
|
43354 |
mp_free(gwion->mp, Func, a); |
14 |
|
43354 |
} |
15 |
|
|
|
16 |
|
43513 |
ANN Func new_func(MemPool p, const m_str name, const Func_Def def) { |
17 |
|
43513 |
Func func = mp_calloc(p, Func); |
18 |
|
43513 |
func->name = name; |
19 |
|
43513 |
func->def = def; |
20 |
|
43513 |
func->ref = new_refcount(p, free_func); |
21 |
|
43513 |
return func; |
22 |
|
|
} |
23 |
|
|
|
24 |
|
43786 |
ANN2(1,2) Symbol func_symbol(const Env env, const m_str nspc, const m_str base, |
25 |
|
43786 |
const m_str tmpl, const m_uint i) { |
26 |
|
43786 |
const size_t base_len = strlen(base); |
27 |
✓✓ |
43786 |
const size_t tmpl_len = !tmpl ? 0 : strlen(tmpl) + 4; |
28 |
|
43786 |
const size_t nspc_len = strlen(nspc); |
29 |
|
43786 |
const size_t idx_len = num_digit(i); |
30 |
|
43786 |
const size_t len = base_len + tmpl_len + nspc_len + idx_len + 2; |
31 |
|
43786 |
char name[len + 1]; |
32 |
✓✓✓✓ ✓✓✗✓
|
43786 |
CHECK_BO(sprintf(name, "%s%s%s%s@%" UINT_F "@%s", |
33 |
|
|
base, !tmpl ? "" : "<~", !tmpl ? "" : tmpl, !tmpl ? "" : "~>", |
34 |
|
|
i, nspc)) |
35 |
|
43786 |
return insert_symbol(env->gwion->st, name); |
36 |
|
|
} |