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 |
|
161 |
static GACK(gack_float) { |
55 |
|
161 |
INTERP_PRINTF("%.4f", *(m_float*)VALUE); |
56 |
|
161 |
} |
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 |
|
712 |
ANN static m_bool import_core_libs(const Gwi gwi) { |
76 |
|
712 |
const Type t_class = gwi_mk_type(gwi, "@Class", SZ_INT, NULL); |
77 |
|
712 |
GWI_BB(gwi_set_global_type(gwi, t_class, et_class)) |
78 |
|
712 |
GWI_BB(gwi_gack(gwi, t_class, gack_class)) // not working yet |
79 |
|
712 |
GWI_BB(gwi_add_type(gwi, t_class)) |
80 |
|
712 |
GWI_BB(gwi_oper_ini(gwi, (m_str)OP_ANY_TYPE, (m_str)OP_ANY_TYPE, NULL)) |
81 |
|
712 |
GWI_BB(gwi_oper_add(gwi, opck_object_dot)) |
82 |
|
712 |
GWI_BB(gwi_oper_emi(gwi, opem_object_dot)) |
83 |
|
712 |
GWI_BB(gwi_oper_end(gwi, "@dot", NULL)) |
84 |
|
712 |
const Type t_undefined = gwi_mk_type(gwi, "@Undefined", SZ_INT, NULL); |
85 |
|
712 |
GWI_BB(gwi_set_global_type(gwi, t_undefined, et_undefined)) |
86 |
|
712 |
const Type t_auto = gwi_mk_type(gwi, "auto", SZ_INT, NULL); |
87 |
|
712 |
SET_FLAG(t_auto, infer); |
88 |
|
712 |
GWI_BB(gwi_set_global_type(gwi, t_auto, et_auto)) |
89 |
|
712 |
SET_FLAG(t_class, infer); |
90 |
|
712 |
const Type t_void = gwi_mk_type(gwi, "void", 0, NULL); |
91 |
|
712 |
GWI_BB(gwi_gack(gwi, t_void, gack_void)) |
92 |
|
712 |
GWI_BB(gwi_set_global_type(gwi, t_void, et_void)) |
93 |
|
712 |
const Type t_gack = gwi_mk_type(gwi, "@Gack", SZ_INT, NULL); |
94 |
|
712 |
GWI_BB(gwi_gack(gwi, t_gack, gack_gack)) |
95 |
|
712 |
GWI_BB(gwi_set_global_type(gwi, t_gack, et_gack)) |
96 |
|
712 |
const Type t_int = gwi_mk_type(gwi, "int", SZ_INT, NULL); |
97 |
|
712 |
GWI_BB(gwi_gack(gwi, t_int, gack_int)) |
98 |
|
712 |
GWI_BB(gwi_set_global_type(gwi, t_int, et_int)) |
99 |
|
712 |
const Type t_char = gwi_mk_type(gwi, "char", SZ_INT, "int"); |
100 |
|
712 |
GWI_BB(gwi_gack(gwi, t_char, gack_char)) |
101 |
|
712 |
GWI_BB(gwi_set_global_type(gwi, t_char, et_char)) |
102 |
|
712 |
const Type t_float = gwi_mk_type(gwi, "float", SZ_FLOAT, NULL); |
103 |
|
712 |
GWI_BB(gwi_gack(gwi, t_float, gack_float)) |
104 |
|
712 |
GWI_BB(gwi_set_global_type(gwi, t_float, et_float)) |
105 |
|
712 |
const Type t_dur = gwi_mk_type(gwi, "dur", SZ_FLOAT, NULL); |
106 |
|
712 |
GWI_BB(gwi_gack(gwi, t_dur, gack_float)) |
107 |
|
712 |
GWI_BB(gwi_add_type(gwi, t_dur)) |
108 |
|
712 |
const Type t_time = gwi_mk_type(gwi, "time", SZ_FLOAT, NULL); |
109 |
|
712 |
GWI_BB(gwi_gack(gwi, t_time, gack_float)) |
110 |
|
712 |
GWI_BB(gwi_add_type(gwi, t_time)) |
111 |
|
712 |
const Type t_now = gwi_mk_type(gwi, "@now", SZ_FLOAT, "time"); |
112 |
|
712 |
GWI_BB(gwi_add_type(gwi, t_now)) |
113 |
|
712 |
struct SpecialId_ spid = { .type=t_now, .exec=RegPushNow, .is_const=1 }; |
114 |
|
712 |
gwi_specialid(gwi, "now", &spid); |
115 |
|
|
|
116 |
|
712 |
const Type t_compound = gwi_mk_type(gwi, "@Compound", 0, NULL); |
117 |
|
712 |
GWI_BB(gwi_gack(gwi, t_compound, gack_compound)) |
118 |
|
712 |
GWI_BB(gwi_set_global_type(gwi, t_compound, et_compound)) |
119 |
|
712 |
GWI_BB(import_object(gwi)) |
120 |
|
712 |
GWI_BB(import_prim(gwi)) |
121 |
|
712 |
const Type t_function = gwi_mk_type(gwi, "@function", SZ_INT, NULL); |
122 |
|
712 |
GWI_BB(gwi_gack(gwi, t_function, gack_function)) |
123 |
|
712 |
GWI_BB(gwi_set_global_type(gwi, t_function, et_function)) |
124 |
|
712 |
const Type t_fptr = gwi_mk_type(gwi, "@func_ptr", SZ_INT, "@function"); |
125 |
|
712 |
GWI_BB(gwi_gack(gwi, t_fptr, gack_fptr)) |
126 |
|
712 |
GWI_BB(gwi_set_global_type(gwi, t_fptr, et_fptr)) |
127 |
|
712 |
const Type t_lambda = gwi_mk_type(gwi, "@lambda", SZ_INT, "@function"); |
128 |
|
712 |
SET_FLAG(t_lambda, infer); |
129 |
|
712 |
GWI_BB(gwi_set_global_type(gwi, t_lambda, et_lambda)) |
130 |
|
|
|
131 |
|
712 |
GWI_BB(gwi_typedef_ini(gwi, "int", "@internal")) |
132 |
|
712 |
GWI_BB(gwi_typedef_end(gwi, ae_flag_none)) |
133 |
|
|
|
134 |
|
712 |
GWI_BB(import_object_op(gwi)) |
135 |
|
712 |
GWI_BB(import_values(gwi)) |
136 |
|
|
|
137 |
|
|
// TODO: check me |
138 |
|
712 |
const Type t_union = gwi_class_ini(gwi, "@Union", NULL); |
139 |
|
712 |
gwi->gwion->type[et_union] = t_union; |
140 |
|
712 |
GWI_BB(gwi_class_end(gwi)) |
141 |
|
|
|
142 |
|
712 |
GWI_BB(import_array(gwi)) |
143 |
|
712 |
GWI_BB(import_event(gwi)) |
144 |
|
712 |
GWI_BB(import_ugen(gwi)) |
145 |
|
712 |
GWI_BB(import_ptr(gwi)) |
146 |
|
712 |
GWI_BB(import_func(gwi)) |
147 |
|
712 |
GWI_BB(gwi_oper_ini(gwi, NULL, (m_str)OP_ANY_TYPE, NULL)) |
148 |
|
712 |
GWI_BB(gwi_oper_add(gwi, opck_new)) |
149 |
|
712 |
GWI_BB(gwi_oper_emi(gwi, opem_new)) |
150 |
|
712 |
GWI_BB(gwi_oper_end(gwi, "new", NULL)) |
151 |
|
|
// GWI_BB(import_prim(gwi)) |
152 |
|
712 |
GWI_BB(import_vararg(gwi)) |
153 |
|
712 |
GWI_BB(import_string(gwi)) |
154 |
|
712 |
GWI_BB(import_shred(gwi)) |
155 |
|
712 |
GWI_BB(import_modules(gwi)) |
156 |
|
|
|
157 |
|
712 |
GWI_BB(gwi_oper_ini(gwi, "@Class", "@Class", "int")) |
158 |
|
712 |
GWI_BB(gwi_oper_end(gwi, "==", int_eq)) |
159 |
|
712 |
GWI_BB(gwi_oper_end(gwi, "!=", int_neq)) |
160 |
|
712 |
GWI_BB(gwi_oper_end(gwi, ">=", instr_class_ge)) |
161 |
|
712 |
GWI_BB(gwi_oper_end(gwi, ">", instr_class_gt)) |
162 |
|
712 |
GWI_BB(gwi_oper_end(gwi, "<=", instr_class_le)) |
163 |
|
712 |
GWI_BB(gwi_oper_end(gwi, "<", instr_class_lt)) |
164 |
|
712 |
return GW_OK; |
165 |
|
|
} |
166 |
|
|
|
167 |
|
712 |
ANN m_bool type_engine_init(const Gwion gwion, const Vector plug_dirs) { |
168 |
|
712 |
gwion->env->name = "[builtin]"; |
169 |
|
712 |
struct loc_t_ loc = {}; |
170 |
|
712 |
OperCK oper = {}; |
171 |
|
712 |
struct Gwi_ gwi = { .gwion=gwion, .loc=&loc, .oper=&oper }; |
172 |
✗✓ |
712 |
CHECK_BB(import_core_libs(&gwi)) |
173 |
|
712 |
push_global(gwion, "[plugins]"); |
174 |
|
712 |
gwion->env->name = "[imported]"; |
175 |
✓✓ |
781 |
for(m_uint i = 0; i < vector_size(plug_dirs); ++i) { |
176 |
|
69 |
m_bool (*import)(Gwi) = (m_bool(*)(Gwi))vector_at(plug_dirs, i); |
177 |
✓✗✓✓
|
69 |
if(import && import(&gwi) < 0) |
178 |
|
36 |
gwi_reset(&gwi); |
179 |
|
|
} |
180 |
|
712 |
push_global(gwion, "[user]"); |
181 |
|
712 |
return GW_OK; |
182 |
|
|
} |