| 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 "instr.h" | ||
| 6 | #include "emit.h" | ||
| 7 | #include "gwion.h" | ||
| 8 | #include "object.h" | ||
| 9 | #include "operator.h" | ||
| 10 | #include "import.h" | ||
| 11 | #include "gwi.h" | ||
| 12 | #include "gack.h" | ||
| 13 | #include "traverse.h" | ||
| 14 | |||
| 15 | #define mk_class_instr(op, arg0, arg1, ...) \ | ||
| 16 | static INSTR(instr_class_##op) { \ | ||
| 17 | POP_REG(shred, SZ_INT); \ | ||
| 18 | const Type l = *(Type *)(shred->reg - SZ_INT); \ | ||
| 19 | const Type r = *(Type *)(shred->reg); \ | ||
| 20 | *(m_uint *)(shred->reg - SZ_INT) = isa(arg0, arg1) > 0 __VA_ARGS__; \ | ||
| 21 | } | ||
| 22 | ✗ | mk_class_instr(ge, l, r) mk_class_instr(gt, l, r, &&l != r) | |
| 23 | ✗ | mk_class_instr(le, r, l) mk_class_instr(lt, r, l, &&l != r) | |
| 24 | |||
| 25 | |||
| 26 | ✗ | static OP_CHECK(opck_class_call) { | |
| 27 | ✗ | const Exp_Binary *bin = (Exp_Binary *)data; | |
| 28 | ✗ | Exp_Call call = {.func = bin->rhs, .args = bin->lhs}; | |
| 29 | ✗ | Exp e = exp_self(bin); | |
| 30 | ✗ | e->exp_type = ae_exp_call; | |
| 31 | ✗ | memcpy(&e->d.exp_call, &call, sizeof(Exp_Call)); | |
| 32 | ✗ | return check_exp_call1(env, &e->d.exp_call) ?: env->gwion->type[et_error]; | |
| 33 | } | ||
| 34 | |||
| 35 | 2 | static OP_CHECK(opck_basic_ctor) { | |
| 36 | 2 | const Exp_Call *call = (Exp_Call *)data; | |
| 37 | // change to *no know constructor for {+G}%s{0}*? | ||
| 38 | 2 | ERR_N(call->func->pos, _("can't call a non-callable value")); | |
| 39 | } | ||
| 40 | /* | ||
| 41 | static OP_EMIT(opem_implicit_class) { | ||
| 42 | struct Implicit *imp = (struct Implicit*)data; | ||
| 43 | const Type t = actual_type(emit->gwion, imp->e->type); | ||
| 44 | emit_pushimm(emit, map_size(&t->nspc->info->value->map)); | ||
| 45 | return GW_OK; | ||
| 46 | } | ||
| 47 | |||
| 48 | static OP_CHECK(opck_implicit_class) { | ||
| 49 | struct Implicit *imp = (struct Implicit*)data; | ||
| 50 | const Type t = actual_type(env->gwion, imp->e->type); | ||
| 51 | if(isa(t, env->gwion->type[et_enum]) > 0) return imp->e->type; | ||
| 52 | return env->gwion->type[et_error]; | ||
| 53 | } | ||
| 54 | */ | ||
| 55 | 638 | GWION_IMPORT(class) { | |
| 56 | |||
| 57 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 638 times.
|
638 | gwidoc(gwi, "Operators class types."); |
| 58 | 638 | GWI_BB(gwi_oper_ini(gwi, "Class", "Class", "bool")) | |
| 59 | 638 | GWI_BB(gwi_oper_end(gwi, "==", int_eq)) | |
| 60 | 638 | GWI_BB(gwi_oper_end(gwi, "!=", int_neq)) | |
| 61 | 638 | GWI_BB(gwi_oper_end(gwi, ">=", instr_class_ge)) | |
| 62 | 638 | GWI_BB(gwi_oper_end(gwi, ">", instr_class_gt)) | |
| 63 | 638 | GWI_BB(gwi_oper_end(gwi, "<=", instr_class_le)) | |
| 64 | 638 | GWI_BB(gwi_oper_end(gwi, "<", instr_class_lt)) | |
| 65 | |||
| 66 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 638 times.
|
638 | gwidoc(gwi, "Allow binary call to constructors."); |
| 67 | 638 | GWI_BB(gwi_oper_ini(gwi, (m_str)OP_ANY_TYPE, "Class", NULL)) | |
| 68 | 638 | GWI_BB(gwi_oper_add(gwi, opck_class_call)) | |
| 69 | 638 | GWI_BB(gwi_oper_end(gwi, "=>", NULL)) | |
| 70 | |||
| 71 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 638 times.
|
638 | gwidoc(gwi, "internal constructor operator."); |
| 72 | 638 | GWI_BB(gwi_oper_ini(gwi, NULL, (m_str)OP_ANY_TYPE, NULL)) | |
| 73 | 638 | GWI_BB(gwi_oper_add(gwi, opck_basic_ctor)) | |
| 74 | 638 | GWI_BB(gwi_oper_end(gwi, "call_type", NULL)) | |
| 75 | /* | ||
| 76 | gwidoc(gwi, "Allow enum for array size"); | ||
| 77 | GWI_BB(gwi_oper_ini(gwi, "Class", "int", NULL)) | ||
| 78 | GWI_BB(gwi_oper_add(gwi, opck_implicit_class)) | ||
| 79 | GWI_BB(gwi_oper_emi(gwi, opem_implicit_class)) | ||
| 80 | GWI_BB(gwi_oper_end(gwi, "@implicit", NULL)) | ||
| 81 | */ | ||
| 82 | 638 | return GW_OK; | |
| 83 | } | ||
| 84 |