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->userenv[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 parent->store_address_in_code_block(rel_class,
30 (cell)(stub + 1) + offset,
31 (cell)(stub->compiled + 1));
33 flush_icache((cell)stub,stub->size);
36 callback *callback_heap::add(code_block *compiled)
38 tagged<array> code_template(parent->userenv[CALLBACK_STUB]);
39 tagged<byte_array> insns(array_nth(code_template.untagged(),0));
40 cell size = array_capacity(insns.untagged());
42 cell bump = align(size,sizeof(cell)) + sizeof(callback);
43 if(here + bump > seg->end) fatal_error("Out of callback space",0);
45 callback *stub = (callback *)here;
46 stub->compiled = compiled;
47 memcpy(stub + 1,insns->data<void>(),size);
49 stub->size = align(size,sizeof(cell));
57 void factor_vm::primitive_callback()
59 tagged<word> w(dpop());
62 callback *stub = callbacks->add(w->code);