]> gitweb.factorcode.org Git - factor.git/blob - vm/jit.hpp
vm: use iostreams instead of printf for debug messages, clean up a few things
[factor.git] / vm / jit.hpp
1 namespace factor
2 {
3
4 struct jit {
5         code_block_type type;
6         gc_root<object> owner;
7         growable_byte_array code;
8         growable_byte_array relocation;
9         growable_array literals;
10         bool computing_offset_p;
11         fixnum position;
12         cell offset;
13         factor_vm *parent;
14
15         explicit jit(code_block_type type, cell owner, factor_vm *parent);
16         void compute_position(cell offset);
17
18         void emit_relocation(cell code_template);
19         void emit(cell code_template);
20
21         void literal(cell literal) { literals.add(literal); }
22         void emit_with(cell code_template_, cell literal_);
23
24         void push(cell literal) {
25                 emit_with(parent->userenv[JIT_PUSH_IMMEDIATE],literal);
26         }
27
28         void word_jump(cell word_) {
29                 gc_root<word> word(word_,parent);
30                 literal(tag_fixnum(xt_tail_pic_offset));
31                 literal(word.value());
32                 emit(parent->userenv[JIT_WORD_JUMP]);
33         }
34
35         void word_call(cell word) {
36                 emit_with(parent->userenv[JIT_WORD_CALL],word);
37         }
38
39         void word_special(cell word) {
40                 emit_with(parent->userenv[JIT_WORD_SPECIAL],word);
41         }
42
43         void emit_subprimitive(cell word_) {
44                 gc_root<word> word(word_,parent);
45                 gc_root<array> code_pair(word->subprimitive,parent);
46                 literals.append(untag<array>(array_nth(code_pair.untagged(),0)));
47                 emit(array_nth(code_pair.untagged(),1));
48         }
49
50         void emit_class_lookup(fixnum index, cell type);
51
52         fixnum get_position() {
53                 if(computing_offset_p)
54                 {
55                         /* If this is still on, emit() didn't clear it,
56                            so the offset was out of bounds */
57                         return -1;
58                 }
59                 else
60                         return position;
61         }
62
63         void set_position(fixnum position_) {
64                 if(computing_offset_p)
65                         position = position_;
66         }
67
68         
69         code_block *to_code_block();
70 };
71
72 }