]> gitweb.factorcode.org Git - factor.git/blob - vm/jit.hpp
Merge branch 'master' into new_gc
[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 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         {
26                 emit_with(parent->special_objects[JIT_PUSH_IMMEDIATE],literal);
27         }
28
29         void word_jump(cell word_)
30         {
31                 data_root<word> word(word_,parent);
32                 literal(tag_fixnum(xt_tail_pic_offset));
33                 literal(word.value());
34                 emit(parent->special_objects[JIT_WORD_JUMP]);
35         }
36
37         void word_call(cell word)
38         {
39                 emit_with(parent->special_objects[JIT_WORD_CALL],word);
40         }
41
42         void word_special(cell word)
43         {
44                 emit_with(parent->special_objects[JIT_WORD_SPECIAL],word);
45         }
46
47         void emit_subprimitive(cell word_)
48         {
49                 data_root<word> word(word_,parent);
50                 data_root<array> code_pair(word->subprimitive,parent);
51                 literals.append(untag<array>(array_nth(code_pair.untagged(),0)));
52                 emit(array_nth(code_pair.untagged(),1));
53         }
54
55         void emit_class_lookup(fixnum index, cell type);
56
57         fixnum get_position()
58         {
59                 if(computing_offset_p)
60                 {
61                         /* If this is still on, emit() didn't clear it,
62                            so the offset was out of bounds */
63                         return -1;
64                 }
65                 else
66                         return position;
67         }
68
69         void set_position(fixnum position_)
70         {
71                 if(computing_offset_p)
72                         position = position_;
73         }
74
75         
76         code_block *to_code_block();
77 };
78
79 }