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 "template.h" |
7 |
|
|
|
8 |
|
276 |
ANN static void check(struct EnvSet *es, const Type t) { |
9 |
|
276 |
const Vector v = &es->env->scope->class_stack; |
10 |
|
276 |
Type owner = t->e->owner_class; |
11 |
✓✓✓✗
|
552 |
for(vtype i = vector_size(v) + 1; owner && --i;) { |
12 |
✓✗ |
4 |
if(owner != (Type)vector_at(v, i - 1)) { |
13 |
|
4 |
es->run = 1; |
14 |
|
4 |
return; |
15 |
|
|
} |
16 |
|
|
owner = owner->e->owner_class; |
17 |
|
|
} |
18 |
|
|
} |
19 |
|
|
|
20 |
|
4 |
ANN static m_bool push(struct EnvSet *es, const Type t) { |
21 |
✗✓ |
4 |
if(t->e->owner_class) |
22 |
|
|
CHECK_BB(push(es, t->e->owner_class)) |
23 |
|
|
else |
24 |
|
4 |
env_push(es->env, NULL, t->e->ctx->nspc); |
25 |
✓✗✗✓
|
4 |
if(es->func && !(t->flag & es->flag)) |
26 |
|
|
CHECK_BB(es->func((void*)es->data, t->e->def)) |
27 |
✓✗ |
4 |
if(GET_FLAG(t, template)) |
28 |
✗✓ |
4 |
CHECK_BB(template_push_types(es->env, t->e->def->base.tmpl)) |
29 |
|
4 |
env_push_type((void*)es->env, t); |
30 |
|
4 |
return GW_OK; |
31 |
|
|
} |
32 |
|
|
|
33 |
|
260 |
ANN2(1,3) m_bool envset_push(struct EnvSet *es, const Type t, const Nspc nspc) { |
34 |
✓✓ |
260 |
if(t) { |
35 |
|
150 |
check(es, t); |
36 |
✗✓ |
150 |
return es->run ? push(es, t) : GW_OK; |
37 |
|
|
} |
38 |
✓✓ |
110 |
if(nspc != es->env->curr) { |
39 |
|
29 |
env_push(es->env, NULL, nspc); |
40 |
|
29 |
es->run = 1; |
41 |
|
|
} |
42 |
|
110 |
return GW_OK; |
43 |
|
|
} |
44 |
|
|
|
45 |
|
33 |
ANN2(1) void envset_pop(struct EnvSet *es, const Type t) { |
46 |
|
33 |
env_pop(es->env, es->scope); |
47 |
✓✓ |
33 |
if(!t) |
48 |
|
29 |
return; |
49 |
✓✗ |
4 |
if(GET_FLAG(t, template)) |
50 |
|
4 |
nspc_pop_type(es->env->gwion->mp, es->env->curr); |
51 |
✗✓ |
4 |
if(t->e->owner_class) |
52 |
|
|
envset_pop(es, t->e->owner_class); |
53 |
|
|
else |
54 |
|
4 |
env_pop(es->env, es->scope); |
55 |
|
|
} |
56 |
|
|
|
57 |
|
126 |
ANN m_bool envset_run(struct EnvSet *es, const Type t) { |
58 |
|
126 |
check(es, t); |
59 |
✓✓ |
126 |
if(es->run) |
60 |
✗✓ |
4 |
CHECK_BB(push(es, t->e->owner_class)) |
61 |
|
252 |
const m_bool ret = !(t->flag & es->flag) ? |
62 |
✓✗ |
126 |
es->func(es->data, t->e->def) : GW_OK; |
63 |
✓✓ |
126 |
if(es->run) |
64 |
|
4 |
envset_pop(es, t->e->owner_class); |
65 |
|
126 |
return ret; |
66 |
|
|
} |