| 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 "traverse.h" | ||
| 6 | #include "instr.h" | ||
| 7 | #include "gwion.h" | ||
| 8 | #include "object.h" | ||
| 9 | #include "operator.h" | ||
| 10 | #include "import.h" | ||
| 11 | #include "gwi.h" | ||
| 12 | |||
| 13 | 13398 | void gwi_body(const Gwi gwi, const Section *section) { | |
| 14 | 13398 | const Class_Def cdef = gwi->gwion->env->class_def->info->cdef; | |
| 15 |
2/2✓ Branch 0 taken 1914 times.
✓ Branch 1 taken 11484 times.
|
13398 | if (!cdef->body) { |
| 16 | 1914 | cdef->body = new_mp_vector(gwi->gwion->mp, Section, 1); | |
| 17 | 1914 | mp_vector_set(cdef->body, Section, 0, *section); | |
| 18 | } else { | ||
| 19 |
2/2✓ Branch 0 taken 3828 times.
✓ Branch 1 taken 7656 times.
|
11484 | mp_vector_add(gwi->gwion->mp, &cdef->body, Section, (*section)); |
| 20 | } | ||
| 21 | 13398 | } | |
| 22 | |||
| 23 | 42 | ANN void gwi_reset(const Gwi gwi) { | |
| 24 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 34 times.
|
42 | if (gwi->ck) { |
| 25 | 8 | ck_clean(gwi); | |
| 26 | 8 | mp_free2(gwi->gwion->mp, sizeof(ImportCK), gwi->ck); | |
| 27 | 8 | gwi->ck = NULL; | |
| 28 | } | ||
| 29 | 42 | env_reset(gwi->gwion->env); | |
| 30 | 42 | } | |
| 31 | |||
| 32 | ✗ | ANN static m_bool run_with_doc(const Gwi gwi, m_bool (*f)(const Gwi)) { | |
| 33 | ✗ | struct GwfmtState ls = {.builtin = true, .nindent = 4}; | |
| 34 | ✗ | text_init(&ls.text, gwi->gwion->mp); | |
| 35 | ✗ | Gwfmt gwfmter = {.mp = gwi->gwion->mp, .ls = &ls }; | |
| 36 | ✗ | gwfmt_indent(&gwfmter); | |
| 37 | ✗ | gwfmt_util(&gwfmter, "{-}#!+ %s{0}\n", gwi->gwion->env->name); | |
| 38 | ✗ | gwi->gwfmt = &gwfmter; | |
| 39 | ✗ | const m_bool ret = f(gwi); | |
| 40 | ✗ | fprintf(stdout, "%s", ls.text.str); | |
| 41 | ✗ | return ret; | |
| 42 | } | ||
| 43 | |||
| 44 | 680 | ANN m_bool gwi_run(const Gwion gwion, m_bool (*f)(const Gwi)) { | |
| 45 | 680 | const m_str name = gwion->env->name; | |
| 46 | // const Context ctx = gwion->env->context; | ||
| 47 | // gwion->env->context = NULL; | ||
| 48 | 680 | OperCK oper = {}; | |
| 49 | 680 | struct Gwi_ gwi = {.gwion = gwion, .oper = &oper}; | |
| 50 |
1/2✓ Branch 0 taken 680 times.
✗ Branch 1 not taken.
|
680 | const m_bool ret = !gwion->data->cdoc ? f(&gwi) : run_with_doc(&gwi, f); |
| 51 |
2/2✓ Branch 0 taken 42 times.
✓ Branch 1 taken 638 times.
|
680 | if (ret < 0) gwi_reset(&gwi); |
| 52 | 680 | gwion->env->name = name; | |
| 53 | // gwion->env->context = ctx; | ||
| 54 | 680 | return ret; | |
| 55 | } | ||
| 56 | |||
| 57 |