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