2009-05-02 05:04:19 -04:00
|
|
|
#include "master.hpp"
|
|
|
|
|
2009-05-04 02:46:13 -04:00
|
|
|
namespace factor
|
|
|
|
{
|
|
|
|
|
2009-09-27 14:42:18 -04:00
|
|
|
void factor_vm::primitive_getenv()
|
2009-05-02 05:04:19 -04:00
|
|
|
{
|
2009-05-04 05:50:24 -04:00
|
|
|
fixnum e = untag_fixnum(dpeek());
|
2009-05-02 05:04:19 -04:00
|
|
|
drepl(userenv[e]);
|
|
|
|
}
|
|
|
|
|
2009-09-27 14:42:18 -04:00
|
|
|
void factor_vm::primitive_setenv()
|
2009-05-02 05:04:19 -04:00
|
|
|
{
|
2009-05-04 05:50:24 -04:00
|
|
|
fixnum e = untag_fixnum(dpop());
|
|
|
|
cell value = dpop();
|
2009-05-02 05:04:19 -04:00
|
|
|
userenv[e] = value;
|
|
|
|
}
|
|
|
|
|
2009-09-27 14:42:18 -04:00
|
|
|
void factor_vm::primitive_exit()
|
2009-05-02 05:04:19 -04:00
|
|
|
{
|
|
|
|
exit(to_fixnum(dpop()));
|
|
|
|
}
|
|
|
|
|
2009-09-27 14:42:18 -04:00
|
|
|
void factor_vm::primitive_micros()
|
2009-05-02 05:04:19 -04:00
|
|
|
{
|
|
|
|
box_unsigned_8(current_micros());
|
|
|
|
}
|
|
|
|
|
2009-09-27 14:42:18 -04:00
|
|
|
void factor_vm::primitive_sleep()
|
2009-05-02 05:04:19 -04:00
|
|
|
{
|
|
|
|
sleep_micros(to_cell(dpop()));
|
|
|
|
}
|
|
|
|
|
2009-09-27 14:42:18 -04:00
|
|
|
void factor_vm::primitive_set_slot()
|
2009-05-02 05:04:19 -04:00
|
|
|
{
|
2009-05-04 05:50:24 -04:00
|
|
|
fixnum slot = untag_fixnum(dpop());
|
|
|
|
object *obj = untag<object>(dpop());
|
|
|
|
cell value = dpop();
|
2009-05-04 02:00:30 -04:00
|
|
|
|
2009-10-13 22:16:04 -04:00
|
|
|
cell *slot_ptr = &obj->slots()[slot];
|
|
|
|
*slot_ptr = value;
|
|
|
|
write_barrier(slot_ptr);
|
2009-05-02 05:04:19 -04:00
|
|
|
}
|
|
|
|
|
2009-09-27 14:42:18 -04:00
|
|
|
void factor_vm::primitive_load_locals()
|
2009-05-02 05:04:19 -04:00
|
|
|
{
|
2009-05-04 05:50:24 -04:00
|
|
|
fixnum count = untag_fixnum(dpop());
|
|
|
|
memcpy((cell *)(rs + sizeof(cell)),(cell *)(ds - sizeof(cell) * (count - 1)),sizeof(cell) * count);
|
|
|
|
ds -= sizeof(cell) * count;
|
|
|
|
rs += sizeof(cell) * count;
|
2009-05-02 05:04:19 -04:00
|
|
|
}
|
|
|
|
|
2009-09-23 14:05:46 -04:00
|
|
|
cell factor_vm::clone_object(cell obj_)
|
2009-05-02 05:04:19 -04:00
|
|
|
{
|
2009-08-17 16:37:09 -04:00
|
|
|
gc_root<object> obj(obj_,this);
|
2009-05-02 10:19:09 -04:00
|
|
|
|
2009-05-04 05:50:24 -04:00
|
|
|
if(immediate_p(obj.value()))
|
|
|
|
return obj.value();
|
2009-05-02 05:04:19 -04:00
|
|
|
else
|
|
|
|
{
|
2009-05-04 05:50:24 -04:00
|
|
|
cell size = object_size(obj.value());
|
2009-10-03 09:47:05 -04:00
|
|
|
object *new_obj = allot_object(header(obj.type()),size);
|
2009-05-04 05:50:24 -04:00
|
|
|
memcpy(new_obj,obj.untagged(),size);
|
2009-05-04 02:00:30 -04:00
|
|
|
return tag_dynamic(new_obj);
|
2009-05-02 05:04:19 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-27 14:42:18 -04:00
|
|
|
void factor_vm::primitive_clone()
|
2009-05-02 05:04:19 -04:00
|
|
|
{
|
|
|
|
drepl(clone_object(dpeek()));
|
|
|
|
}
|
2009-05-04 02:46:13 -04:00
|
|
|
|
|
|
|
}
|