]> gitweb.factorcode.org Git - factor.git/blob - vm/jit.hpp
Merge branch 'master' of git://factorcode.org/git/factor
[factor.git] / vm / jit.hpp
1 namespace factor
2 {
3
4 struct jit {
5         cell 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
14         jit(cell jit_type, cell owner);
15         void compute_position(cell offset);
16
17         void emit_relocation(cell code_template);
18         void emit(cell code_template);
19
20         void literal(cell literal) { literals.add(literal); }
21         void emit_with(cell code_template_, cell literal_);
22
23         void push(cell literal) {
24                 emit_with(userenv[JIT_PUSH_IMMEDIATE],literal);
25         }
26
27         void word_jump(cell word) {
28                 literal(tag_fixnum(xt_tail_pic_offset));
29                 literal(word);
30                 emit(userenv[JIT_WORD_JUMP]);
31         }
32
33         void word_call(cell word) {
34                 emit_with(userenv[JIT_WORD_CALL],word);
35         }
36
37         void word_special(cell word) {
38                 emit_with(userenv[JIT_WORD_SPECIAL],word);
39         }
40
41         void emit_subprimitive(cell word_) {
42                 gc_root<word> word(word_);
43                 gc_root<array> code_template(word->subprimitive);
44                 if(array_capacity(code_template.untagged()) > 1) literal(T);
45                 emit(code_template.value());
46         }
47
48         void emit_class_lookup(fixnum index, cell type);
49
50         fixnum get_position() {
51                 if(computing_offset_p)
52                 {
53                         /* If this is still on, emit() didn't clear it,
54                            so the offset was out of bounds */
55                         return -1;
56                 }
57                 else
58                         return position;
59         }
60
61         void set_position(fixnum position_) {
62                 if(computing_offset_p)
63                         position = position_;
64         }
65
66         
67         code_block *to_code_block();
68 };
69
70 }