2004-09-18 18:15:01 -04:00
|
|
|
#include "factor.h"
|
|
|
|
|
|
2004-12-25 05:49:30 -05:00
|
|
|
void primitive_dlopen(void)
|
|
|
|
|
{
|
2004-12-25 18:08:20 -05:00
|
|
|
DLL* dll;
|
|
|
|
|
F_STRING* path;
|
|
|
|
|
|
2004-12-25 05:49:30 -05:00
|
|
|
maybe_garbage_collection();
|
2004-12-25 18:08:20 -05:00
|
|
|
|
|
|
|
|
path = untag_string(dpop());
|
|
|
|
|
dll = allot_object(DLL_TYPE,sizeof(DLL));
|
|
|
|
|
dll->path = tag_object(path);
|
|
|
|
|
ffi_dlopen(dll);
|
|
|
|
|
|
|
|
|
|
dpush(tag_object(dll));
|
2004-12-25 05:49:30 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void primitive_dlsym(void)
|
|
|
|
|
{
|
2004-12-25 18:08:20 -05:00
|
|
|
CELL dll;
|
|
|
|
|
F_STRING* sym;
|
2004-12-25 05:49:30 -05:00
|
|
|
|
|
|
|
|
maybe_garbage_collection();
|
|
|
|
|
|
2004-12-25 18:08:20 -05:00
|
|
|
dll = dpop();
|
2004-12-25 05:49:30 -05:00
|
|
|
sym = untag_string(dpop());
|
2004-12-25 18:08:20 -05:00
|
|
|
|
|
|
|
|
dpush(tag_cell((CELL)ffi_dlsym(
|
|
|
|
|
dll == F ? NULL : untag_dll(dll),
|
|
|
|
|
sym)));
|
2004-12-25 05:49:30 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void primitive_dlclose(void)
|
|
|
|
|
{
|
|
|
|
|
maybe_garbage_collection();
|
|
|
|
|
ffi_dlclose(untag_dll(dpop()));
|
|
|
|
|
}
|
|
|
|
|
|
2004-09-21 22:58:54 -04:00
|
|
|
DLL* untag_dll(CELL tagged)
|
|
|
|
|
{
|
|
|
|
|
DLL* dll = (DLL*)UNTAG(tagged);
|
|
|
|
|
type_check(DLL_TYPE,tagged);
|
|
|
|
|
if(dll->dll == NULL)
|
|
|
|
|
general_error(ERROR_EXPIRED,tagged);
|
|
|
|
|
return (DLL*)UNTAG(tagged);
|
|
|
|
|
}
|
|
|
|
|
|
2005-03-14 11:25:41 -05:00
|
|
|
void* unbox_alien(void)
|
2004-10-16 21:55:13 -04:00
|
|
|
{
|
|
|
|
|
return untag_alien(dpop())->ptr;
|
|
|
|
|
}
|
|
|
|
|
|
2005-03-14 11:25:41 -05:00
|
|
|
void box_alien(void* ptr)
|
2004-10-16 21:55:13 -04:00
|
|
|
{
|
|
|
|
|
ALIEN* alien = allot_object(ALIEN_TYPE,sizeof(ALIEN));
|
|
|
|
|
alien->ptr = ptr;
|
|
|
|
|
alien->local = false;
|
|
|
|
|
dpush(tag_object(alien));
|
|
|
|
|
}
|
|
|
|
|
|
2005-03-14 11:25:41 -05:00
|
|
|
INLINE void* alien_pointer(void)
|
2004-10-16 21:55:13 -04:00
|
|
|
{
|
2004-12-10 21:46:42 -05:00
|
|
|
F_FIXNUM offset = unbox_integer();
|
2004-10-16 21:55:13 -04:00
|
|
|
ALIEN* alien = untag_alien(dpop());
|
2005-03-14 11:25:41 -05:00
|
|
|
void* ptr = alien->ptr;
|
2004-10-16 21:55:13 -04:00
|
|
|
|
|
|
|
|
if(ptr == NULL)
|
|
|
|
|
general_error(ERROR_EXPIRED,tag_object(alien));
|
|
|
|
|
|
|
|
|
|
return ptr + offset;
|
|
|
|
|
}
|
|
|
|
|
|
2004-09-19 17:39:28 -04:00
|
|
|
void primitive_alien(void)
|
|
|
|
|
{
|
2005-03-14 11:25:41 -05:00
|
|
|
void* ptr = (void*)unbox_integer();
|
2004-10-12 23:49:43 -04:00
|
|
|
maybe_garbage_collection();
|
2004-10-16 21:55:13 -04:00
|
|
|
box_alien(ptr);
|
2004-09-19 17:39:28 -04:00
|
|
|
}
|
|
|
|
|
|
2004-09-21 22:58:54 -04:00
|
|
|
void primitive_local_alien(void)
|
|
|
|
|
{
|
2004-12-25 02:55:03 -05:00
|
|
|
F_FIXNUM length = unbox_integer();
|
2004-10-12 23:49:43 -04:00
|
|
|
ALIEN* alien;
|
2004-12-10 21:46:42 -05:00
|
|
|
F_STRING* local;
|
2004-12-25 02:55:03 -05:00
|
|
|
if(length < 0)
|
|
|
|
|
general_error(ERROR_NEGATIVE_ARRAY_SIZE,tag_fixnum(length));
|
2004-10-12 23:49:43 -04:00
|
|
|
maybe_garbage_collection();
|
|
|
|
|
alien = allot_object(ALIEN_TYPE,sizeof(ALIEN));
|
|
|
|
|
local = string(length / CHARS,'\0');
|
2005-03-14 11:25:41 -05:00
|
|
|
alien->ptr = (void*)(local + 1);
|
2004-09-21 22:58:54 -04:00
|
|
|
alien->local = true;
|
|
|
|
|
dpush(tag_object(alien));
|
2004-12-23 01:14:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void primitive_local_alienp(void)
|
|
|
|
|
{
|
|
|
|
|
box_boolean(untag_alien(dpop())->local);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void primitive_alien_address(void)
|
|
|
|
|
{
|
2005-03-14 11:25:41 -05:00
|
|
|
box_cell((CELL)untag_alien(dpop())->ptr);
|
2004-09-21 22:58:54 -04:00
|
|
|
}
|
|
|
|
|
|
2004-09-19 17:39:28 -04:00
|
|
|
void primitive_alien_cell(void)
|
|
|
|
|
{
|
2005-03-14 11:25:41 -05:00
|
|
|
box_integer(*(int*)alien_pointer());
|
2004-09-19 17:39:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void primitive_set_alien_cell(void)
|
|
|
|
|
{
|
2005-03-14 11:25:41 -05:00
|
|
|
CELL* ptr = alien_pointer();
|
2004-09-19 17:39:28 -04:00
|
|
|
CELL value = unbox_integer();
|
2005-03-14 11:25:41 -05:00
|
|
|
*ptr = value;
|
2004-09-19 17:39:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void primitive_alien_4(void)
|
|
|
|
|
{
|
2005-03-14 11:25:41 -05:00
|
|
|
int* ptr = alien_pointer();
|
|
|
|
|
box_integer(*ptr);
|
2004-09-19 17:39:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void primitive_set_alien_4(void)
|
|
|
|
|
{
|
2005-03-14 11:25:41 -05:00
|
|
|
int* ptr = alien_pointer();
|
|
|
|
|
int value = unbox_integer();
|
|
|
|
|
*ptr = value;
|
2004-09-19 17:39:28 -04:00
|
|
|
}
|
|
|
|
|
|
2004-09-20 21:02:48 -04:00
|
|
|
void primitive_alien_2(void)
|
|
|
|
|
{
|
2005-03-21 20:59:30 -05:00
|
|
|
u16* ptr = alien_pointer();
|
2005-03-14 11:25:41 -05:00
|
|
|
box_signed_2(*ptr);
|
2004-09-20 21:02:48 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void primitive_set_alien_2(void)
|
|
|
|
|
{
|
2005-03-21 20:59:30 -05:00
|
|
|
u16* ptr = alien_pointer();
|
2004-10-23 01:15:06 -04:00
|
|
|
CELL value = unbox_signed_2();
|
2005-03-14 11:25:41 -05:00
|
|
|
*ptr = value;
|
2004-09-20 21:02:48 -04:00
|
|
|
}
|
|
|
|
|
|
2004-09-19 17:39:28 -04:00
|
|
|
void primitive_alien_1(void)
|
|
|
|
|
{
|
2005-03-14 11:25:41 -05:00
|
|
|
box_signed_1(*(BYTE*)alien_pointer());
|
2004-09-19 17:39:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void primitive_set_alien_1(void)
|
|
|
|
|
{
|
2005-03-14 11:25:41 -05:00
|
|
|
BYTE* ptr = alien_pointer();
|
2004-10-23 01:15:06 -04:00
|
|
|
BYTE value = value = unbox_signed_1();
|
2005-03-14 11:25:41 -05:00
|
|
|
*ptr = value;
|
2004-09-19 17:39:28 -04:00
|
|
|
}
|
2004-09-21 22:58:54 -04:00
|
|
|
|
|
|
|
|
void fixup_dll(DLL* dll)
|
|
|
|
|
{
|
2004-12-25 18:08:20 -05:00
|
|
|
data_fixup(&dll->path);
|
|
|
|
|
ffi_dlopen(dll);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void collect_dll(DLL* dll)
|
|
|
|
|
{
|
2005-02-19 23:25:21 -05:00
|
|
|
COPY_OBJECT(dll->path);
|
2004-09-21 22:58:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void fixup_alien(ALIEN* alien)
|
|
|
|
|
{
|
|
|
|
|
alien->ptr = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void collect_alien(ALIEN* alien)
|
|
|
|
|
{
|
|
|
|
|
if(alien->local && alien->ptr != NULL)
|
|
|
|
|
{
|
2004-12-10 21:46:42 -05:00
|
|
|
F_STRING* ptr = (F_STRING*)(alien->ptr - sizeof(F_STRING));
|
2004-09-21 22:58:54 -04:00
|
|
|
ptr = copy_untagged_object(ptr,SSIZE(ptr));
|
2005-03-14 11:25:41 -05:00
|
|
|
alien->ptr = (void*)(ptr + 1);
|
2004-09-21 22:58:54 -04:00
|
|
|
}
|
|
|
|
|
}
|