factor/vm/jit.hpp

72 lines
1.5 KiB
C++
Raw Normal View History

2009-05-04 02:46:13 -04:00
namespace factor
{
2009-05-02 10:19:09 -04:00
struct jit {
2009-05-04 05:50:24 -04:00
cell type;
gc_root<object> owner;
2009-05-02 10:19:09 -04:00
growable_byte_array code;
growable_byte_array relocation;
growable_array literals;
2009-05-02 05:04:19 -04:00
bool computing_offset_p;
2009-05-04 05:50:24 -04:00
fixnum position;
cell offset;
2009-08-17 16:37:09 -04:00
factorvm *myvm;
2009-05-02 05:04:19 -04:00
2009-08-17 16:37:09 -04:00
jit(cell jit_type, cell owner, factorvm *vm);
2009-05-04 05:50:24 -04:00
void compute_position(cell offset);
2009-05-02 05:04:19 -04:00
void emit_relocation(cell code_template);
2009-05-04 05:50:24 -04:00
void emit(cell code_template);
2009-05-02 05:04:19 -04:00
2009-05-04 05:50:24 -04:00
void literal(cell literal) { literals.add(literal); }
void emit_with(cell code_template_, cell literal_);
2009-05-02 05:04:19 -04:00
2009-05-04 05:50:24 -04:00
void push(cell literal) {
emit_with(myvm->userenv[JIT_PUSH_IMMEDIATE],literal);
2009-05-02 10:19:09 -04:00
}
2009-05-02 05:04:19 -04:00
2009-05-04 05:50:24 -04:00
void word_jump(cell word) {
literal(tag_fixnum(xt_tail_pic_offset));
literal(word);
emit(myvm->userenv[JIT_WORD_JUMP]);
2009-05-02 10:19:09 -04:00
}
2009-05-02 05:04:19 -04:00
2009-05-04 05:50:24 -04:00
void word_call(cell word) {
emit_with(myvm->userenv[JIT_WORD_CALL],word);
2009-05-02 10:19:09 -04:00
}
2009-05-02 05:04:19 -04:00
void word_special(cell word) {
emit_with(myvm->userenv[JIT_WORD_SPECIAL],word);
}
2009-05-04 05:50:24 -04:00
void emit_subprimitive(cell word_) {
gc_root<word> word(word_,myvm);
gc_root<array> code_template(word->subprimitive,myvm);
if(array_capacity(code_template.untagged()) > 1) literal(myvm->T);
2009-05-02 10:19:09 -04:00
emit(code_template.value());
}
2009-05-02 05:04:19 -04:00
2009-05-04 05:50:24 -04:00
void emit_class_lookup(fixnum index, cell type);
2009-05-02 10:19:09 -04:00
2009-05-04 05:50:24 -04:00
fixnum get_position() {
2009-05-02 10:19:09 -04:00
if(computing_offset_p)
{
/* If this is still on, emit() didn't clear it,
so the offset was out of bounds */
return -1;
}
else
return position;
}
2009-05-02 05:04:19 -04:00
2009-05-04 05:50:24 -04:00
void set_position(fixnum position_) {
2009-05-02 10:19:09 -04:00
if(computing_offset_p)
position = position_;
2009-05-02 05:04:19 -04:00
}
2009-05-02 10:19:09 -04:00
2009-05-04 05:50:24 -04:00
code_block *to_code_block();
2009-05-02 10:19:09 -04:00
};
2009-05-04 02:46:13 -04:00
}