-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsfclass.c
97 lines (77 loc) · 1.63 KB
/
sfclass.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include "sfclass.h"
#include "sfmod.h"
class_t **CLASS_STACK;
size_t classstack_count;
size_t classstack_capacity;
int CLASS_CACHE[SF_CLASSCACHE_SIZE];
int cch_count;
SF_API void
sf_class_init (void)
{
classstack_count = 0;
classstack_capacity = SF_CLASSSTACK_CAPACITY;
CLASS_STACK = sfmalloc (classstack_capacity * sizeof (*CLASS_STACK));
cch_count = 0;
}
void
_clstack_resz (void)
{
classstack_capacity += SF_CLASSSTACK_CAPACITY;
CLASS_STACK
= sfrealloc (CLASS_STACK, classstack_capacity * sizeof (*CLASS_STACK));
}
SF_API class_t *
sf_class_new (const char *_Name, int _Type)
{
class_t *t = sfmalloc (sizeof (*t));
t->il_c = 0;
t->inh_list = NULL;
t->meta.hasid = 0;
t->meta.id = -1;
t->mod = NULL;
t->name = sfstrdup ((char *)_Name);
t->type = _Type;
t->meta.iscobj = 0;
t->meta.clref = NULL;
t->meta.kill_fun_called = 0;
return t;
}
SF_API class_t *
sf_class_add (class_t *t)
{
if (cch_count)
{
int p = CLASS_CACHE[--cch_count];
t->meta.hasid = 1;
t->meta.id = p;
CLASS_STACK[p] = t;
}
else
{
if (classstack_count == classstack_capacity)
_clstack_resz ();
t->meta.hasid = 1;
t->meta.id = classstack_count;
CLASS_STACK[classstack_count++] = t;
}
return t;
}
SF_API void
sf_class_free (class_t *c)
{
if (c->meta.hasid && cch_count < SF_CLASSCACHE_SIZE)
{
CLASS_CACHE[cch_count++] = c->meta.id;
}
// if (c->meta.iscobj)
// {
// // ? Call destructor
// // TODO
// }
sffree (c->name);
sffree (c->inh_list);
// TODO Clear inh_list
if (c->mod)
sf_mod_free (c->mod);
sffree (c);
}