Line | Branch | Exec | Source |
---|---|---|---|
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 | 641 | ANN void free_context(const Context a, Gwion gwion) { | |
9 | 641 | const Nspc global = a->nspc->parent; | |
10 |
2/2✓ Branch 0 taken 344 times.
✓ Branch 1 taken 297 times.
|
641 | if(!a->error) // this is quite a hack |
11 | 344 | nspc_remref(a->nspc, gwion); | |
12 | // if(a->error) // this is quite a hack | ||
13 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 631 times.
|
641 | if(a->global) // this is quite a hack |
14 | 10 | nspc_remref(global, gwion); | |
15 | 641 | free_mstr(gwion->mp, a->name); | |
16 | 641 | ast_cleaner(gwion, a->tree); | |
17 | 641 | mp_free(gwion->mp, Context, a); | |
18 | 641 | } | |
19 | |||
20 | 641 | ANN2(1,3) Context new_context(MemPool p, const Ast ast, const m_str str) { | |
21 | 641 | const Context context = mp_calloc(p, Context); | |
22 | 641 | context->name = mstrdup(p, str); | |
23 | 641 | context->nspc = new_nspc(p, context->name); | |
24 | 641 | context->tree = ast; | |
25 | 641 | context->ref = 1; | |
26 | 641 | return context; | |
27 | } | ||
28 | |||
29 | 641 | ANN void load_context(const Context context, const Env env) { | |
30 | 641 | const Nspc global = new_nspc(env->gwion->mp, context->name); | |
31 | 641 | global->parent = env->global_nspc; | |
32 | 641 | env->global_nspc = global; | |
33 | 641 | context_addref((env->context = context)); | |
34 | 641 | vector_add(&env->scope->nspc_stack, (vtype)env->curr); | |
35 | 641 | env->name = context->name; | |
36 | 641 | context->nspc->parent = global; | |
37 | 641 | env->curr = context->nspc; | |
38 | 641 | } | |
39 | |||
40 | 636 | ANN static void clean(const Nspc nspc, const Env env) { | |
41 | 636 | env->global_nspc = nspc->parent; | |
42 | // nspc_remref(nspc, env->gwion); | ||
43 | 636 | } | |
44 | |||
45 | 641 | ANN void unload_context(const Context ctx, const Env env) { | |
46 | 641 | const Nspc global = ctx->nspc->parent; | |
47 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 641 times.
|
641 | if(global != env->global_nspc) exit(3); |
48 | 641 | context_remref(ctx, env->gwion); | |
49 | 641 | env->curr = (Nspc)vector_pop(&env->scope->nspc_stack); | |
50 | 641 | const Nspc user = (Nspc)vector_at(&env->scope->nspc_stack, 1); | |
51 | 641 | user->parent = (Nspc)vector_at(&env->scope->nspc_stack, 0); | |
52 |
2/2✓ Branch 0 taken 297 times.
✓ Branch 1 taken 344 times.
|
641 | if(ctx->error) clean(global, env); |
53 |
2/2✓ Branch 0 taken 339 times.
✓ Branch 1 taken 5 times.
|
344 | else if(!ctx->global) { |
54 | 339 | ctx->nspc->parent = global->parent; | |
55 | 339 | clean(global, env); | |
56 | 339 | nspc_remref(global, env->gwion); | |
57 | 5 | } else vector_set(&env->scope->nspc_stack, 2, (m_uint)global); | |
58 | 641 | } | |
59 |