-
Notifications
You must be signed in to change notification settings - Fork 0
/
gfxboot_context.c
132 lines (102 loc) · 3.41 KB
/
gfxboot_context.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#include <gfxboot/gfxboot.h>
#include <gfxboot/vocabulary.h>
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// context
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
obj_id_t gfx_obj_context_new(uint8_t sub_type)
{
obj_id_t id = gfx_obj_alloc(OTYPE_CONTEXT, OBJ_CONTEXT_SIZE());
obj_t *ptr = gfx_obj_ptr(id);
if(ptr) {
ptr->sub_type = sub_type;
((context_t *) ptr->data.ptr)->type = sub_type;
}
return id;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
context_t *gfx_obj_context_ptr(obj_id_t id)
{
obj_t *ptr = gfx_obj_ptr(id);
if(!ptr || ptr->base_type != OTYPE_CONTEXT) return 0;
return (context_t *) ptr->data.ptr;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
int gfx_obj_context_dump(obj_t *ptr, dump_style_t style)
{
if(!ptr) return 1;
context_t *context = ptr->data.ptr;
unsigned len = ptr->data.size;
if(len != OBJ_CONTEXT_SIZE()) {
if(style.ref) {
gfxboot_log(" <invalid data>\n");
}
else {
gfxboot_log("<invalid data>");
}
return 1;
}
if(!style.ref) {
if(!style.inspect) return 0;
gfxboot_log("code %s, ip 0x%x (0x%x)", gfx_obj_id2str(context->code_id), context->ip, context->current_ip);
if(context->type == t_ctx_repeat) {
gfxboot_log(", index %lld", (long long) context->index);
}
else if(context->type == t_ctx_for) {
gfxboot_log(
", index %lld, inc %lld, max %lld",
(long long) context->index,
(long long) context->inc,
(long long) context->max
);
}
else if(context->type == t_ctx_forall) {
gfxboot_log(
", index %lld, iterate %s",
(long long) context->index,
gfx_obj_id2str(context->iterate_id)
);
}
if(context->dict_id) gfxboot_log(", dict %s", gfx_obj_id2str(context->dict_id));
return 1;
}
if(style.dump) {
gfxboot_log(" type %u, ip 0x%x (0x%x)\n", context->type, context->ip, context->current_ip);
gfxboot_log(" code %s\n", gfx_obj_id2str(context->code_id));
gfxboot_log(" parent %s\n", gfx_obj_id2str(context->parent_id));
gfxboot_log(" dict %s\n", gfx_obj_id2str(context->dict_id));
gfxboot_log(" iterate %s\n", gfx_obj_id2str(context->iterate_id));
}
return 1;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
unsigned gfx_obj_context_gc(obj_t *ptr)
{
if(!ptr) return 0;
context_t *context = ptr->data.ptr;
unsigned data_size = ptr->data.size;
unsigned more_gc = 0;
if(context && data_size == OBJ_CONTEXT_SIZE()) {
more_gc += gfx_obj_ref_dec_delay_gc(context->parent_id);
more_gc += gfx_obj_ref_dec_delay_gc(context->code_id);
more_gc += gfx_obj_ref_dec_delay_gc(context->dict_id);
more_gc += gfx_obj_ref_dec_delay_gc(context->iterate_id);
}
return more_gc;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
int gfx_obj_context_contains(obj_t *ptr, obj_id_t id)
{
if(!ptr || !id) return 0;
context_t *context = ptr->data.ptr;
unsigned data_size = ptr->data.size;
if(context && data_size == OBJ_CONTEXT_SIZE()) {
if(
id == context->parent_id ||
id == context->code_id ||
id == context->dict_id ||
id == context->iterate_id
) return 1;
}
return 0;
}