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 "lang_private.h" | ||
13 | #include "specialid.h" | ||
14 | #include "gack.h" | ||
15 | #include "traverse.h" | ||
16 | |||
17 | 6 | static GACK(gack_class) { | |
18 |
1/2✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
|
6 | const Type type = actual_type(shred->info->vm->gwion, t) ?: t; |
19 | 6 | INTERP_PRINTF("%s", type->name) | |
20 | 6 | } | |
21 | |||
22 | 14 | static GACK(gack_void) { INTERP_PRINTF("void"); } | |
23 | |||
24 | 465 | static GACK(gack_int) { INTERP_PRINTF("%" INT_F, *(m_uint *)VALUE); } | |
25 | |||
26 | 4 | static GACK(gack_char) { INTERP_PRINTF("%c", *(char *)VALUE); } | |
27 | |||
28 | 139 | static GACK(gack_float) { INTERP_PRINTF("%.4f", *(m_float *)VALUE); } | |
29 | |||
30 | 96 | static GACK(gack_compound) { INTERP_PRINTF("%p", *(void **)VALUE); } | |
31 | |||
32 | OP_CHECK(opck_object_dot); | ||
33 | OP_EMIT(opem_object_dot); | ||
34 | |||
35 | 3 | static ID_CHECK(idck_predicate) { | |
36 | 3 | return exp_self(prim)->type; | |
37 | } | ||
38 | |||
39 | 2 | static INSTR(PredicateCheck) { | |
40 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 | if (!*(m_uint *)REG(-SZ_INT)) handle(shred, "PredicateFail"); |
41 | 2 | } | |
42 | |||
43 | 24 | static FREEARG(freearg_release) { | |
44 | 24 | struct Vector_ v = { .ptr = (m_uint*)instr->m_val }; | |
45 | 24 | vector_release(&v); | |
46 | 24 | } | |
47 | |||
48 | 638 | ANN static m_bool import_core_libs(const Gwi gwi) { | |
49 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 638 times.
|
638 | gwidoc(gwi, "one type to rule them all."); |
50 | 638 | const Type t_class = gwi_mk_type(gwi, "Class", SZ_INT, NULL); | |
51 | 638 | set_tflag(t_class, tflag_infer); | |
52 | 638 | GWI_BB(gwi_set_global_type(gwi, t_class, et_class)) | |
53 | 638 | GWI_BB(gwi_gack(gwi, t_class, gack_class)) | |
54 | |||
55 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 638 times.
|
638 | gwidoc(gwi, "this type is infered."); |
56 | 638 | const Type t_auto = gwi_mk_type(gwi, "auto", SZ_INT, NULL); | |
57 | 638 | set_tflag(t_auto, tflag_infer); | |
58 | 638 | GWI_BB(gwi_set_global_type(gwi, t_auto, et_auto)) | |
59 | |||
60 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 638 times.
|
638 | gwidoc(gwi, "a void type."); |
61 | 638 | const Type t_void = gwi_mk_type(gwi, "void", 0, NULL); | |
62 | 638 | GWI_BB(gwi_gack(gwi, t_void, gack_void)) | |
63 | 638 | GWI_BB(gwi_set_global_type(gwi, t_void, et_void)) | |
64 | |||
65 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 638 times.
|
638 | gwidoc(gwi, "integer type."); |
66 | 638 | const Type t_int = gwi_mk_type(gwi, "int", SZ_INT, NULL); | |
67 | 638 | GWI_BB(gwi_gack(gwi, t_int, gack_int)) | |
68 | 638 | GWI_BB(gwi_set_global_type(gwi, t_int, et_int)) | |
69 | |||
70 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 638 times.
|
638 | gwidoc(gwi, "character type."); |
71 | 638 | const Type t_char = gwi_mk_type(gwi, "char", SZ_INT, "int"); | |
72 | 638 | GWI_BB(gwi_gack(gwi, t_char, gack_char)) | |
73 | 638 | GWI_BB(gwi_set_global_type(gwi, t_char, et_char)) | |
74 | |||
75 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 638 times.
|
638 | gwidoc(gwi, "float type."); |
76 | 638 | const Type t_float = gwi_mk_type(gwi, "float", SZ_FLOAT, NULL); | |
77 | 638 | GWI_BB(gwi_gack(gwi, t_float, gack_float)) | |
78 | 638 | GWI_BB(gwi_set_global_type(gwi, t_float, et_float)) | |
79 | 638 | set_tflag(t_float, tflag_float); | |
80 | |||
81 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 638 times.
|
638 | gwidoc(gwi, "represent duration."); |
82 | 638 | const Type t_dur = gwi_mk_type(gwi, "dur", SZ_FLOAT, NULL); | |
83 | 638 | GWI_BB(gwi_gack(gwi, t_dur, gack_float)) | |
84 | 638 | GWI_BB(gwi_add_type(gwi, t_dur)) | |
85 | 638 | set_tflag(t_dur, tflag_float); | |
86 | |||
87 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 638 times.
|
638 | gwidoc(gwi, "represent time."); |
88 | 638 | const Type t_time = gwi_mk_type(gwi, "time", SZ_FLOAT, NULL); | |
89 | 638 | GWI_BB(gwi_gack(gwi, t_time, gack_float)) | |
90 | 638 | GWI_BB(gwi_add_type(gwi, t_time)) | |
91 | 638 | set_tflag(t_time, tflag_float); | |
92 | |||
93 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 638 times.
|
638 | gwidoc(gwi, "internal time for `{/}now{0}{-}`."); |
94 | 638 | const Type t_now = gwi_mk_type(gwi, "@now", SZ_FLOAT, "time"); | |
95 | 638 | GWI_BB(gwi_add_type(gwi, t_now)) | |
96 | 638 | struct SpecialId_ spid = {.type = t_now, .exec = RegPushNow, .is_const = 1}; | |
97 | 638 | gwi_specialid(gwi, "now", &spid); | |
98 | |||
99 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 638 times.
|
638 | gwidoc(gwi, "internal predicate representation."); |
100 | 638 | struct SpecialId_ predicate = {.type = t_void, | |
101 | .ck = idck_predicate, | ||
102 | .exec = PredicateCheck, | ||
103 | .is_const = 1}; | ||
104 | 638 | gwi_specialid(gwi, "@predicate", &predicate); | |
105 | |||
106 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 638 times.
|
638 | gwidoc(gwi, "internal base of all objects and structures."); |
107 | |||
108 | 638 | GWI_BB(gwimport_enum(gwi)); | |
109 | |||
110 | 638 | const Type t_compound = gwi_mk_type(gwi, "@Compound", SZ_INT, NULL); | |
111 | 638 | GWI_BB(gwi_gack(gwi, t_compound, gack_compound)) | |
112 | 638 | GWI_BB(gwi_set_global_type(gwi, t_compound, et_compound)) | |
113 | |||
114 | 638 | GWI_BB(gwimport_object(gwi)) | |
115 | |||
116 | 638 | GWI_BB(gwimport_prim(gwi)) | |
117 | 638 | GWI_BB(gwimport_func(gwi)) | |
118 | 638 | GWI_BB(gwimport_object_op(gwi)) | |
119 | 638 | GWI_BB(gwimport_values(gwi)) | |
120 | 638 | GWI_BB(gwimport_union(gwi)) | |
121 | |||
122 | 638 | GWI_BB(gwimport_array(gwi)) | |
123 | 638 | GWI_BB(gwimport_event(gwi)) | |
124 | 638 | GWI_BB(gwimport_ugen(gwi)) | |
125 | 638 | GWI_BB(gwimport_xork(gwi)) | |
126 | 638 | GWI_BB(gwi_oper_ini(gwi, NULL, (m_str)OP_ANY_TYPE, NULL)) | |
127 | 638 | GWI_BB(gwi_oper_add(gwi, opck_new)) | |
128 | 638 | GWI_BB(gwi_oper_emi(gwi, opem_new)) | |
129 | 638 | GWI_BB(gwi_oper_end(gwi, "new", NULL)) | |
130 | 638 | GWI_BB(gwimport_ref(gwi)) | |
131 | 638 | GWI_BB(gwimport_string(gwi)) | |
132 | 638 | GWI_BB(gwimport_shred(gwi)) | |
133 | 638 | GWI_BB(gwimport_modules(gwi)) | |
134 | |||
135 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 638 times.
|
638 | gwidoc(gwi, "allow member access."); |
136 | 638 | GWI_BB(gwi_oper_ini(gwi, "@Compound", (m_str)OP_ANY_TYPE, NULL)) | |
137 | 638 | GWI_BB(gwi_oper_add(gwi, opck_object_dot)) | |
138 | 638 | GWI_BB(gwi_oper_emi(gwi, opem_object_dot)) | |
139 | 638 | GWI_BB(gwi_oper_end(gwi, ".", NULL)) | |
140 | |||
141 | 638 | GWI_BB(gwimport_class(gwi)) | |
142 | |||
143 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 638 times.
|
638 | gwidoc(gwi, "allow static access."); |
144 | 638 | GWI_BB(gwi_oper_ini(gwi, "Class", (m_str)OP_ANY_TYPE, NULL)) | |
145 | 638 | GWI_BB(gwi_oper_add(gwi, opck_object_dot)) | |
146 | 638 | GWI_BB(gwi_oper_emi(gwi, opem_object_dot)) | |
147 | 638 | GWI_BB(gwi_oper_end(gwi, ".", NULL)) | |
148 | 638 | GWI_BB(gwimport_deep_equal(gwi)); | |
149 | |||
150 | 638 | GWI_BB(gwimport_dict(gwi)); | |
151 | 638 | GWI_BB(gwimport_gack(gwi)); | |
152 | 638 | GWI_BB(gwimport_sift(gwi)); | |
153 | 638 | GWI_BB(gwimport_locale(gwi)); | |
154 | |||
155 | |||
156 | // seemed need at a point to ease liking | ||
157 | 638 | gwi_enum_ini(gwi, "@hidden_enum"); | |
158 | 638 | gwi_enum_add(gwi, "@hidden_enum", 0); | |
159 | 638 | gwi_enum_end(gwi); | |
160 | |||
161 | 638 | gwi_register_freearg(gwi, ObjectRelease2, freearg_release); | |
162 | |||
163 | 638 | return GW_OK; | |
164 | } | ||
165 | |||
166 | 638 | ANN m_bool type_engine_init(const Gwion gwion) { | |
167 | 638 | gwion->env->name = "[builtin]"; | |
168 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 638 times.
|
638 | CHECK_BB(gwi_run(gwion, import_core_libs)); |
169 | 638 | gwion->data->cdoc = false; | |
170 | 638 | push_global(gwion, "[user]"); | |
171 | 638 | return GW_OK; | |
172 | } | ||
173 |