]> 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         code_block_type type;
6         data_root<object> owner;
7         growable_byte_array code;
8         growable_byte_array relocation;
9         growable_array parameters;
10         growable_array literals;
11         bool computing_offset_p;
12         fixnum position;
13         cell offset;
14         factor_vm *parent;
15
16         explicit jit(code_block_type type, cell owner, factor_vm *parent);
17         void compute_position(cell offset);
18
19         void emit_relocation(cell code_template);
20         void emit(cell code_template);
21
22         void parameter(cell parameter) { parameters.add(parameter); }
23         void emit_with_parameter(cell code_template_, cell parameter_);
24
25         void literal(cell literal) { literals.add(literal); }
26         void emit_with_literal(cell code_template_, cell literal_);
27
28         void push(cell literal)
29         {
30                 emit_with_literal(parent->special_objects[JIT_PUSH_IMMEDIATE],literal);
31         }
32
33         void word_jump(cell word_)
34         {
35                 data_root<word> word(word_,parent);
36                 literal(tag_fixnum(xt_tail_pic_offset));
37                 literal(word.value());
38                 emit(parent->special_objects[JIT_WORD_JUMP]);
39         }
40
41         void word_call(cell word)
42         {
43                 emit_with_literal(parent->special_objects[JIT_WORD_CALL],word);
44         }
45
46         bool emit_subprimitive(cell word_, bool tail_call_p, bool stack_frame_p);
47
48         void emit_class_lookup(fixnum index, cell type);
49
50         fixnum get_position()
51         {
52                 if(computing_offset_p)
53                 {
54                         /* If this is still on, emit() didn't clear it,
55                            so the offset was out of bounds */
56                         return -1;
57                 }
58                 else
59                         return position;
60         }
61
62         void set_position(fixnum position_)
63         {
64                 if(computing_offset_p)
65                         position = position_;
66         }
67
68         
69         code_block *to_code_block();
70 };
71
72 }