factor/native/handle.c

44 lines
898 B
C
Raw Normal View History

2004-07-16 02:26:21 -04:00
#include "factor.h"
HANDLE* untag_handle(CELL type, CELL tagged)
2004-07-16 02:26:21 -04:00
{
HANDLE* h;
type_check(HANDLE_TYPE,tagged);
h = (HANDLE*)UNTAG(tagged);
/* after image load & save, handles are no longer valid */
if(h->object == -1)
2004-07-16 02:26:21 -04:00
general_error(ERROR_HANDLE_EXPIRED,tagged);
if(h->type != type)
general_error(ERROR_HANDLE_INCOMPAT,tagged);
2004-07-16 02:26:21 -04:00
return h;
}
CELL handle(CELL type, CELL object)
2004-07-16 02:26:21 -04:00
{
HANDLE* handle = (HANDLE*)allot_object(HANDLE_TYPE,sizeof(HANDLE));
handle->type = type;
2004-07-16 02:26:21 -04:00
handle->object = object;
2004-07-24 00:54:57 -04:00
handle->buffer = F;
handle->buf_mode = B_NONE;
2004-07-24 00:54:57 -04:00
handle->buf_fill = 0;
handle->buf_pos = 0;
2004-07-16 02:26:21 -04:00
return tag_object(handle);
}
void primitive_handlep(void)
{
check_non_empty(env.dt);
env.dt = tag_boolean(typep(HANDLE_TYPE,env.dt));
}
2004-07-24 00:54:57 -04:00
void fixup_handle(HANDLE* handle)
{
handle->object = -1;
fixup(&handle->buffer);
}
void collect_handle(HANDLE* handle)
{
copy_object(&handle->buffer);
}