1 |
|
|
#include <string.h> |
2 |
|
|
#include "gwion_util.h" |
3 |
|
|
#include "gwion_ast.h" |
4 |
|
|
#include "gwion_env.h" |
5 |
|
|
#include "vm.h" |
6 |
|
|
#include "instr.h" |
7 |
|
|
#include "object.h" |
8 |
|
|
#include "emit.h" |
9 |
|
|
#include "vm.h" |
10 |
|
|
#include "gwion.h" |
11 |
|
|
#include "operator.h" |
12 |
|
|
#include "import.h" |
13 |
|
|
#include "gwi.h" |
14 |
|
|
#include "engine.h" |
15 |
|
|
#include "parser.h" |
16 |
|
|
#include "lang_private.h" |
17 |
|
|
#include "specialid.h" |
18 |
|
|
#include "gack.h" |
19 |
|
|
|
20 |
|
|
#undef insert_symbol |
21 |
|
5 |
static GACK(gack_class) { |
22 |
✓✗ |
5 |
const Type type = actual_type(shred->info->vm->gwion, t) ?: t; |
23 |
|
5 |
INTERP_PRINTF("class(%s)", type->name) |
24 |
|
5 |
} |
25 |
|
|
|
26 |
|
17 |
static GACK(gack_function) { |
27 |
|
17 |
INTERP_PRINTF("%s", t->name) |
28 |
|
17 |
} |
29 |
|
|
|
30 |
|
|
static GACK(gack_gack) { |
31 |
|
|
INTERP_PRINTF("%s", *(m_str*)VALUE) |
32 |
|
|
} |
33 |
|
|
|
34 |
|
25 |
static GACK(gack_fptr) { |
35 |
|
25 |
const VM_Code code = *(VM_Code*)VALUE; |
36 |
✓✓ |
25 |
if(code) |
37 |
|
19 |
INTERP_PRINTF("%s", code->name) |
38 |
|
|
else |
39 |
|
6 |
INTERP_PRINTF("%s", t->name) |
40 |
|
25 |
} |
41 |
|
|
|
42 |
|
31 |
static GACK(gack_void) { |
43 |
|
31 |
INTERP_PRINTF("void"); |
44 |
|
31 |
} |
45 |
|
|
|
46 |
|
553 |
static GACK(gack_int) { |
47 |
|
553 |
INTERP_PRINTF("%"INT_F, *(m_uint*)VALUE); |
48 |
|
553 |
} |
49 |
|
|
|
50 |
|
3 |
static GACK(gack_char) { |
51 |
|
3 |
INTERP_PRINTF("%c", *(char*)VALUE); |
52 |
|
3 |
} |
53 |
|
|
|
54 |
|
158 |
static GACK(gack_float) { |
55 |
|
158 |
INTERP_PRINTF("%.4f", *(m_float*)VALUE); |
56 |
|
158 |
} |
57 |
|
|
|
58 |
|
191 |
static GACK(gack_compound) { |
59 |
|
191 |
INTERP_PRINTF("%p", *(void**)VALUE); |
60 |
|
191 |
} |
61 |
|
|
#define mk_class_instr(op, arg0, arg1, ...) \ |
62 |
|
|
static INSTR(instr_class_##op) { \ |
63 |
|
|
POP_REG(shred, SZ_INT); \ |
64 |
|
|
const Type l = *(Type*)(shred->reg - SZ_INT); \ |
65 |
|
|
const Type r = *(Type*)(shred->reg); \ |
66 |
|
|
*(m_uint*)(shred->reg - SZ_INT) = isa(arg0, arg1) > 0 __VA_ARGS__; \ |
67 |
|
|
} |
68 |
|
2 |
mk_class_instr(ge, l, r) |
69 |
✓✓✗✓
|
4 |
mk_class_instr(gt, l, r, && l != r) |
70 |
|
1 |
mk_class_instr(le, r, l) |
71 |
✓✗✓✓
|
3 |
mk_class_instr(lt, r, l, && l != r) |
72 |
|
|
|
73 |
|
|
OP_CHECK(opck_object_dot); |
74 |
|
|
OP_EMIT(opem_object_dot); |
75 |
|
713 |
ANN static m_bool import_core_libs(const Gwi gwi) { |
76 |
|
713 |
const Type t_class = gwi_mk_type(gwi, "@Class", SZ_INT, NULL); |
77 |
|
713 |
GWI_BB(gwi_set_global_type(gwi, t_class, et_class)) |
78 |
|
713 |
GWI_BB(gwi_gack(gwi, t_class, gack_class)) // not working yet |
79 |
|
713 |
GWI_BB(gwi_add_type(gwi, t_class)) |
80 |
|
713 |
GWI_BB(gwi_oper_ini(gwi, (m_str)OP_ANY_TYPE, (m_str)OP_ANY_TYPE, NULL)) |
81 |
|
713 |
GWI_BB(gwi_oper_add(gwi, opck_object_dot)) |
82 |
|
713 |
GWI_BB(gwi_oper_emi(gwi, opem_object_dot)) |
83 |
|
713 |
GWI_BB(gwi_oper_end(gwi, "@dot", NULL)) |
84 |
|
713 |
const Type t_undefined = gwi_mk_type(gwi, "@Undefined", SZ_INT, NULL); |
85 |
|
713 |
GWI_BB(gwi_set_global_type(gwi, t_undefined, et_undefined)) |
86 |
|
713 |
const Type t_auto = gwi_mk_type(gwi, "auto", SZ_INT, NULL); |
87 |
|
713 |
SET_FLAG(t_auto, infer); |
88 |
|
713 |
GWI_BB(gwi_set_global_type(gwi, t_auto, et_auto)) |
89 |
|
713 |
SET_FLAG(t_class, infer); |
90 |
|
713 |
const Type t_void = gwi_mk_type(gwi, "void", 0, NULL); |
91 |
|
713 |
GWI_BB(gwi_gack(gwi, t_void, gack_void)) |
92 |
|
713 |
GWI_BB(gwi_set_global_type(gwi, t_void, et_void)) |
93 |
|
713 |
const Type t_gack = gwi_mk_type(gwi, "@Gack", SZ_INT, NULL); |
94 |
|
713 |
GWI_BB(gwi_gack(gwi, t_gack, gack_gack)) |
95 |
|
713 |
GWI_BB(gwi_set_global_type(gwi, t_gack, et_gack)) |
96 |
|
713 |
const Type t_int = gwi_mk_type(gwi, "int", SZ_INT, NULL); |
97 |
|
713 |
GWI_BB(gwi_gack(gwi, t_int, gack_int)) |
98 |
|
713 |
GWI_BB(gwi_set_global_type(gwi, t_int, et_int)) |
99 |
|
713 |
const Type t_char = gwi_mk_type(gwi, "char", SZ_INT, "int"); |
100 |
|
713 |
GWI_BB(gwi_gack(gwi, t_char, gack_char)) |
101 |
|
713 |
GWI_BB(gwi_set_global_type(gwi, t_char, et_char)) |
102 |
|
713 |
const Type t_float = gwi_mk_type(gwi, "float", SZ_FLOAT, NULL); |
103 |
|
713 |
GWI_BB(gwi_gack(gwi, t_float, gack_float)) |
104 |
|
713 |
GWI_BB(gwi_set_global_type(gwi, t_float, et_float)) |
105 |
|
713 |
const Type t_dur = gwi_mk_type(gwi, "dur", SZ_FLOAT, NULL); |
106 |
|
713 |
GWI_BB(gwi_gack(gwi, t_dur, gack_float)) |
107 |
|
713 |
GWI_BB(gwi_add_type(gwi, t_dur)) |
108 |
|
713 |
const Type t_time = gwi_mk_type(gwi, "time", SZ_FLOAT, NULL); |
109 |
|
713 |
GWI_BB(gwi_gack(gwi, t_time, gack_float)) |
110 |
|
713 |
GWI_BB(gwi_add_type(gwi, t_time)) |
111 |
|
713 |
const Type t_now = gwi_mk_type(gwi, "@now", SZ_FLOAT, "time"); |
112 |
|
713 |
GWI_BB(gwi_add_type(gwi, t_now)) |
113 |
|
713 |
struct SpecialId_ spid = { .type=t_now, .exec=RegPushNow, .is_const=1 }; |
114 |
|
713 |
gwi_specialid(gwi, "now", &spid); |
115 |
|
|
|
116 |
|
713 |
const Type t_compound = gwi_mk_type(gwi, "@Compound", 0, NULL); |
117 |
|
713 |
GWI_BB(gwi_gack(gwi, t_compound, gack_compound)) |
118 |
|
713 |
GWI_BB(gwi_set_global_type(gwi, t_compound, et_compound)) |
119 |
|
713 |
GWI_BB(import_object(gwi)) |
120 |
|
713 |
GWI_BB(import_prim(gwi)) |
121 |
|
713 |
const Type t_function = gwi_mk_type(gwi, "@function", SZ_INT, NULL); |
122 |
|
713 |
GWI_BB(gwi_gack(gwi, t_function, gack_function)) |
123 |
|
713 |
GWI_BB(gwi_set_global_type(gwi, t_function, et_function)) |
124 |
|
713 |
const Type t_fptr = gwi_mk_type(gwi, "@func_ptr", SZ_INT, "@function"); |
125 |
|
713 |
GWI_BB(gwi_gack(gwi, t_fptr, gack_fptr)) |
126 |
|
713 |
GWI_BB(gwi_set_global_type(gwi, t_fptr, et_fptr)) |
127 |
|
713 |
const Type t_lambda = gwi_mk_type(gwi, "@lambda", SZ_INT, "@function"); |
128 |
|
713 |
SET_FLAG(t_lambda, infer); |
129 |
|
713 |
GWI_BB(gwi_set_global_type(gwi, t_lambda, et_lambda)) |
130 |
|
|
|
131 |
|
713 |
GWI_BB(gwi_typedef_ini(gwi, "int", "@internal")) |
132 |
|
713 |
GWI_BB(gwi_typedef_end(gwi, ae_flag_none)) |
133 |
|
|
|
134 |
|
713 |
GWI_BB(import_object_op(gwi)) |
135 |
|
713 |
GWI_BB(import_values(gwi)) |
136 |
|
|
|
137 |
|
|
// TODO: check me |
138 |
|
713 |
const Type t_union = gwi_class_ini(gwi, "@Union", NULL); |
139 |
|
713 |
gwi->gwion->type[et_union] = t_union; |
140 |
|
713 |
GWI_BB(gwi_class_end(gwi)) |
141 |
|
|
|
142 |
|
713 |
GWI_BB(import_array(gwi)) |
143 |
|
713 |
GWI_BB(import_event(gwi)) |
144 |
|
713 |
GWI_BB(import_ugen(gwi)) |
145 |
|
713 |
GWI_BB(import_ptr(gwi)) |
146 |
|
713 |
GWI_BB(import_func(gwi)) |
147 |
|
713 |
GWI_BB(gwi_oper_ini(gwi, NULL, (m_str)OP_ANY_TYPE, NULL)) |
148 |
|
713 |
GWI_BB(gwi_oper_add(gwi, opck_new)) |
149 |
|
713 |
GWI_BB(gwi_oper_emi(gwi, opem_new)) |
150 |
|
713 |
GWI_BB(gwi_oper_end(gwi, "new", NULL)) |
151 |
|
|
// GWI_BB(import_prim(gwi)) |
152 |
|
713 |
GWI_BB(import_vararg(gwi)) |
153 |
|
713 |
GWI_BB(import_string(gwi)) |
154 |
|
713 |
GWI_BB(import_shred(gwi)) |
155 |
|
713 |
GWI_BB(import_modules(gwi)) |
156 |
|
|
|
157 |
|
713 |
GWI_BB(gwi_oper_ini(gwi, "@Class", "@Class", "int")) |
158 |
|
713 |
GWI_BB(gwi_oper_end(gwi, "==", int_eq)) |
159 |
|
713 |
GWI_BB(gwi_oper_end(gwi, "!=", int_neq)) |
160 |
|
713 |
GWI_BB(gwi_oper_end(gwi, ">=", instr_class_ge)) |
161 |
|
713 |
GWI_BB(gwi_oper_end(gwi, ">", instr_class_gt)) |
162 |
|
713 |
GWI_BB(gwi_oper_end(gwi, "<=", instr_class_le)) |
163 |
|
713 |
GWI_BB(gwi_oper_end(gwi, "<", instr_class_lt)) |
164 |
|
713 |
return GW_OK; |
165 |
|
|
} |
166 |
|
|
|
167 |
|
713 |
ANN m_bool type_engine_init(const Gwion gwion, const Vector plug_dirs) { |
168 |
|
713 |
gwion->env->name = "[builtin]"; |
169 |
|
713 |
struct loc_t_ loc = {}; |
170 |
|
713 |
OperCK oper = {}; |
171 |
|
713 |
struct Gwi_ gwi = { .gwion=gwion, .loc=&loc, .oper=&oper }; |
172 |
✗✓ |
713 |
CHECK_BB(import_core_libs(&gwi)) |
173 |
|
713 |
push_global(gwion, "[plugins]"); |
174 |
|
713 |
gwion->env->name = "[imported]"; |
175 |
✓✓ |
783 |
for(m_uint i = 0; i < vector_size(plug_dirs); ++i) { |
176 |
|
70 |
m_bool (*import)(Gwi) = (m_bool(*)(Gwi))vector_at(plug_dirs, i); |
177 |
✓✗✓✓
|
70 |
if(import && import(&gwi) < 0) |
178 |
|
37 |
gwi_reset(&gwi); |
179 |
|
|
} |
180 |
|
713 |
push_global(gwion, "[user]"); |
181 |
|
713 |
return GW_OK; |
182 |
|
|
} |