| 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 "traverse.h" | ||
| 7 | |||
| 8 | 4 | ANN2(1,2) static Exp base_args(const MemPool p, const Arg_List args, Exp next, const uint32_t min) { | |
| 9 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 4 times.
|
9 | for(uint32_t i = min; i--;) { |
| 10 | 5 | Arg *arg = mp_vector_at(args, Arg, i); | |
| 11 | 5 | const Exp exp = new_prim_id(p, arg->var_decl.xid, arg->var_decl.pos); | |
| 12 | 5 | exp->next = next; | |
| 13 | 5 | next = exp; | |
| 14 | } | ||
| 15 | 4 | return next; | |
| 16 | } | ||
| 17 | |||
| 18 | 4 | ANN static Exp additional_args(const MemPool p, const Arg_List args, const uint32_t max) { | |
| 19 | 4 | Exp next = NULL; | |
| 20 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 4 times.
|
9 | for(uint32_t i = max; i-- > args->len;) { |
| 21 | 5 | Arg *arg = mp_vector_at(args, Arg, i); | |
| 22 | 5 | const Exp exp = cpy_exp(p, arg->exp); | |
| 23 | 5 | exp->next = next; | |
| 24 | 5 | next = exp; | |
| 25 | } | ||
| 26 | 4 | return next; | |
| 27 | } | ||
| 28 | |||
| 29 | 4 | ANN static Exp mk_args(const MemPool p, const Arg_List args, const uint32_t max) { | |
| 30 | 4 | const Exp next = additional_args(p, args, max); | |
| 31 | 4 | return base_args(p, args, next, args->len); | |
| 32 | } | ||
| 33 | |||
| 34 | 4 | ANN static Stmt_List code(const MemPool p, const Exp func, const Arg_List lst, | |
| 35 | const uint32_t max, const ae_stmt_t type) { | ||
| 36 | 4 | const Exp arg = mk_args(p, lst, max); | |
| 37 | 4 | const Exp call = new_exp_call(p, func, arg, func->pos); | |
| 38 | 4 | Stmt_List code = new_mp_vector(p, struct Stmt_, 1); | |
| 39 | 4 | mp_vector_set(code, struct Stmt_, 0, | |
| 40 | ((struct Stmt_) { | ||
| 41 | .stmt_type = type, .d = { .stmt_exp = { .val = call }}, | ||
| 42 | .pos = func->pos | ||
| 43 | })); | ||
| 44 | 4 | return code; | |
| 45 | } | ||
| 46 | |||
| 47 | 4 | ANN static Stmt_List std_code(const Env env, Func_Base *base, const uint32_t max) { | |
| 48 | 4 | const MemPool p = env->gwion->mp; | |
| 49 | 4 | const Exp func = new_prim_id(p, base->xid, base->pos); | |
| 50 | 4 | return code(p, func, base->args, max, ae_stmt_return); | |
| 51 | } | ||
| 52 | |||
| 53 | ✗ | ANN static Stmt_List new_code(const Env env, Func_Base *base, const uint32_t max) { | |
| 54 | ✗ | const MemPool p = env->gwion->mp; | |
| 55 | ✗ | SymTable *st = env->gwion->st; | |
| 56 | ✗ | const Exp dbase = new_prim_id(p, insert_symbol(st, "this"), base->pos); | |
| 57 | ✗ | const Symbol sym = insert_symbol(st, "new"); | |
| 58 | ✗ | const Exp func = new_exp_dot(p, dbase, sym, base->pos); | |
| 59 | ✗ | return code(p, func, base->args, max, ae_stmt_exp); | |
| 60 | } | ||
| 61 | |||
| 62 | |||
| 63 | 4 | ANN Func_Def default_args(const Env env, Func_Base *fb, Ast *acc, uint32_t max) { | |
| 64 | 4 | Func_Base *const base = cpy_func_base(env->gwion->mp, fb); | |
| 65 | 8 | Stmt_List code = strcmp(s_name(base->xid), "new") | |
| 66 | 4 | ? std_code(env, fb, max) | |
| 67 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | : new_code(env, fb, max); |
| 68 | 4 | const Func_Def fdef = new_func_def(env->gwion->mp, base, code); | |
| 69 | 4 | Section section = MK_SECTION(func, func_def, fdef); | |
| 70 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | mp_vector_add(env->gwion->mp, acc, Section, section); |
| 71 | 4 | return fdef; | |
| 72 | } | ||
| 73 |