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(code_block *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 rel_type = untag_fixnum(array_nth(code_template.untagged(),2));
28 cell offset = untag_fixnum(array_nth(code_template.untagged(),3));
31 (relocation_type)rel_type,
32 (relocation_class)rel_class,
35 instruction_operand op(rel,stub,0);
36 op.store_value((cell)callback_xt(stub));
41 code_block *callback_heap::add(cell owner)
43 tagged<array> code_template(parent->special_objects[CALLBACK_STUB]);
44 tagged<byte_array> insns(array_nth(code_template.untagged(),0));
45 cell size = array_capacity(insns.untagged());
47 cell bump = align(size + sizeof(code_block),data_alignment);
48 if(here + bump > seg->end) fatal_error("Out of callback space",0);
50 free_heap_block *free_block = (free_heap_block *)here;
51 free_block->make_free(bump);
54 code_block *stub = (code_block *)free_block;
56 stub->parameters = false_object;
57 stub->relocation = false_object;
59 memcpy(stub->xt(),insns->data<void>(),size);
65 struct callback_updater {
66 callback_heap *callbacks;
68 explicit callback_updater(callback_heap *callbacks_) : callbacks(callbacks_) {}
70 void operator()(code_block *stub)
72 callbacks->update(stub);
76 void callback_heap::update()
78 callback_updater updater(this);
79 each_callback(updater);
82 void factor_vm::primitive_callback()
84 tagged<word> w(ctx->pop());
86 ctx->push(allot_alien(callbacks->add(w.value())->xt()));