]> gitweb.factorcode.org Git - factor.git/blob - native/handle.c
first cut at floats
[factor.git] / native / handle.c
1 #include "factor.h"
2
3 HANDLE* untag_handle(CELL type, CELL tagged)
4 {
5         HANDLE* h;
6         type_check(HANDLE_TYPE,tagged);
7         h = (HANDLE*)UNTAG(tagged);
8         /* after image load & save, handles are no longer valid */
9         if(h->object == -1)
10                 general_error(ERROR_HANDLE_EXPIRED,tagged);
11         if(h->type != type)
12                 general_error(ERROR_HANDLE_INCOMPAT,tagged);
13         return h;
14 }
15
16 CELL handle(CELL type, CELL object)
17 {
18         HANDLE* handle = allot_object(HANDLE_TYPE,sizeof(HANDLE));
19         handle->type = type;
20         handle->object = object;
21         handle->buffer = F;
22         handle->buf_mode = B_NONE;
23         handle->buf_fill = 0;
24         handle->buf_pos = 0;
25         return tag_object(handle);
26 }
27
28 void primitive_handlep(void)
29 {
30         check_non_empty(env.dt);
31         env.dt = tag_boolean(typep(HANDLE_TYPE,env.dt));
32 }
33
34 void fixup_handle(HANDLE* handle)
35 {
36         handle->object = -1;
37         fixup(&handle->buffer);
38 }
39
40 void collect_handle(HANDLE* handle)
41 {
42         copy_object(&handle->buffer);
43 }