2009-05-02 05:04:19 -04:00
|
|
|
#include "master.hpp"
|
|
|
|
|
2009-05-04 02:46:13 -04:00
|
|
|
factor::CELL userenv[USER_ENV];
|
|
|
|
|
|
|
|
namespace factor
|
|
|
|
{
|
|
|
|
|
2009-05-02 05:04:19 -04:00
|
|
|
CELL T;
|
|
|
|
|
2009-05-04 02:00:30 -04:00
|
|
|
PRIMITIVE(getenv)
|
2009-05-02 05:04:19 -04:00
|
|
|
{
|
2009-05-02 21:47:29 -04:00
|
|
|
F_FIXNUM e = untag_fixnum(dpeek());
|
2009-05-02 05:04:19 -04:00
|
|
|
drepl(userenv[e]);
|
|
|
|
}
|
|
|
|
|
2009-05-04 02:00:30 -04:00
|
|
|
PRIMITIVE(setenv)
|
2009-05-02 05:04:19 -04:00
|
|
|
{
|
2009-05-02 21:47:29 -04:00
|
|
|
F_FIXNUM e = untag_fixnum(dpop());
|
2009-05-02 05:04:19 -04:00
|
|
|
CELL value = dpop();
|
|
|
|
userenv[e] = value;
|
|
|
|
}
|
|
|
|
|
2009-05-04 02:00:30 -04:00
|
|
|
PRIMITIVE(exit)
|
2009-05-02 05:04:19 -04:00
|
|
|
{
|
|
|
|
exit(to_fixnum(dpop()));
|
|
|
|
}
|
|
|
|
|
2009-05-04 02:00:30 -04:00
|
|
|
PRIMITIVE(micros)
|
2009-05-02 05:04:19 -04:00
|
|
|
{
|
|
|
|
box_unsigned_8(current_micros());
|
|
|
|
}
|
|
|
|
|
2009-05-04 02:00:30 -04:00
|
|
|
PRIMITIVE(sleep)
|
2009-05-02 05:04:19 -04:00
|
|
|
{
|
|
|
|
sleep_micros(to_cell(dpop()));
|
|
|
|
}
|
|
|
|
|
2009-05-04 02:00:30 -04:00
|
|
|
PRIMITIVE(set_slot)
|
2009-05-02 05:04:19 -04:00
|
|
|
{
|
2009-05-02 21:47:29 -04:00
|
|
|
F_FIXNUM slot = untag_fixnum(dpop());
|
2009-05-04 02:00:30 -04:00
|
|
|
F_OBJECT *object = untag<F_OBJECT>(dpop());
|
2009-05-02 05:04:19 -04:00
|
|
|
CELL value = dpop();
|
2009-05-04 02:00:30 -04:00
|
|
|
|
|
|
|
object->slots()[slot] = value;
|
|
|
|
write_barrier(object);
|
2009-05-02 05:04:19 -04:00
|
|
|
}
|
|
|
|
|
2009-05-04 02:00:30 -04:00
|
|
|
PRIMITIVE(load_locals)
|
2009-05-02 05:04:19 -04:00
|
|
|
{
|
2009-05-02 21:47:29 -04:00
|
|
|
F_FIXNUM count = untag_fixnum(dpop());
|
2009-05-02 05:04:19 -04:00
|
|
|
memcpy((CELL *)(rs + CELLS),(CELL *)(ds - CELLS * (count - 1)),CELLS * count);
|
|
|
|
ds -= CELLS * count;
|
|
|
|
rs += CELLS * count;
|
|
|
|
}
|
|
|
|
|
2009-05-02 10:19:09 -04:00
|
|
|
static CELL clone_object(CELL object_)
|
2009-05-02 05:04:19 -04:00
|
|
|
{
|
2009-05-02 10:19:09 -04:00
|
|
|
gc_root<F_OBJECT> object(object_);
|
|
|
|
|
2009-05-04 02:00:30 -04:00
|
|
|
if(immediate_p(object.value()))
|
2009-05-02 10:19:09 -04:00
|
|
|
return object.value();
|
2009-05-02 05:04:19 -04:00
|
|
|
else
|
|
|
|
{
|
2009-05-04 02:00:30 -04:00
|
|
|
CELL size = object_size(object.value());
|
|
|
|
F_OBJECT *new_obj = allot_object(object.type(),size);
|
2009-05-02 10:19:09 -04:00
|
|
|
memcpy(new_obj,object.untagged(),size);
|
2009-05-04 02:00:30 -04:00
|
|
|
return tag_dynamic(new_obj);
|
2009-05-02 05:04:19 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-04 02:00:30 -04:00
|
|
|
PRIMITIVE(clone)
|
2009-05-02 05:04:19 -04:00
|
|
|
{
|
|
|
|
drepl(clone_object(dpeek()));
|
|
|
|
}
|
2009-05-04 02:46:13 -04:00
|
|
|
|
|
|
|
}
|