1 |
|
|
#include <stdlib.h> |
2 |
|
|
#include <string.h> |
3 |
|
|
#include <ctype.h> |
4 |
|
|
#include "gwion_util.h" |
5 |
|
|
#include "gwion_ast.h" |
6 |
|
|
#include "gwion_env.h" |
7 |
|
|
#include "vm.h" |
8 |
|
|
#include "traverse.h" |
9 |
|
|
#include "instr.h" |
10 |
|
|
#include "object.h" |
11 |
|
|
#include "emit.h" |
12 |
|
|
#include "gwion.h" |
13 |
|
|
#include "operator.h" |
14 |
|
|
#include "import.h" |
15 |
|
|
#include "gwi.h" |
16 |
|
|
|
17 |
|
12091 |
ANN2(1) static Type get_parent(const Gwi gwi, const m_str parent_name) { |
18 |
✓✓ |
12091 |
Type_Decl* td = parent_name ? str2decl(gwi, parent_name) : NULL; |
19 |
✓✓ |
12091 |
if(td) { |
20 |
✓✓✗✓
|
3556 |
if(td->array || td->types) { |
21 |
✓✗ |
1 |
const m_str str = td->array ? "array" : "template"; |
22 |
|
1 |
free_type_decl(gwi->gwion->mp, td); |
23 |
|
1 |
GWI_ERR_O(_("can't use gwi_mk_type to extend %s types"), str) |
24 |
|
|
} |
25 |
|
|
} |
26 |
✓✓ |
12090 |
const Type parent = td ? known_type(gwi->gwion->env, td) : NULL; |
27 |
✓✓ |
12090 |
if(td) |
28 |
|
3555 |
free_type_decl(gwi->gwion->mp, td); |
29 |
|
12090 |
return parent; |
30 |
|
|
} |
31 |
|
|
|
32 |
|
12094 |
ANN2(1,2) Type gwi_mk_type(const Gwi gwi, const m_str name, const m_uint size, const m_str parent_name) { |
33 |
✓✓ |
12094 |
CHECK_OO(str2sym(gwi, name)) |
34 |
|
12091 |
const Type parent = get_parent(gwi, parent_name); |
35 |
|
12091 |
const Type t = new_type(gwi->gwion->mp, 0, name, parent); |
36 |
|
12091 |
t->size = size; |
37 |
|
12091 |
return t; |
38 |
|
|
} |
39 |
|
|
|
40 |
|
27040 |
ANN m_int gwi_add_type(const Gwi gwi, const Type type) { |
41 |
|
27040 |
env_add_type(gwi->gwion->env, type); |
42 |
|
27040 |
return (m_int)type->xid; |
43 |
|
|
} |
44 |
|
|
|
45 |
|
11376 |
ANN m_int gwi_set_global_type(const Gwi gwi, const Type type, const type_enum te) { |
46 |
|
11376 |
gwi->gwion->type[te] = type; |
47 |
|
11376 |
return gwi_add_type(gwi, type); |
48 |
|
|
} |