6 callback_heap::callback_heap(cell size, factor_vm *parent_) :
7 seg(new segment(size,true)),
11 callback_heap::~callback_heap()
17 void factor_vm::init_callbacks(cell size)
19 callbacks = new callback_heap(size,this);
22 void callback_heap::update(callback *stub)
24 tagged<array> code_template(parent->special_objects[CALLBACK_STUB]);
26 cell rel_class = untag_fixnum(array_nth(code_template.untagged(),1));
27 cell offset = untag_fixnum(array_nth(code_template.untagged(),3));
29 embedded_pointer ptr(rel_class,offset + (cell)(stub + 1));
30 ptr.store_address((cell)(stub->compiled + 1));
32 flush_icache((cell)stub,stub->size);
35 callback *callback_heap::add(code_block *compiled)
37 tagged<array> code_template(parent->special_objects[CALLBACK_STUB]);
38 tagged<byte_array> insns(array_nth(code_template.untagged(),0));
39 cell size = array_capacity(insns.untagged());
41 cell bump = align(size,sizeof(cell)) + sizeof(callback);
42 if(here + bump > seg->end) fatal_error("Out of callback space",0);
44 callback *stub = (callback *)here;
45 stub->compiled = compiled;
46 memcpy(stub + 1,insns->data<void>(),size);
48 stub->size = align(size,sizeof(cell));
56 void factor_vm::primitive_callback()
58 tagged<word> w(dpop());
61 callback *stub = callbacks->add(w->code);