]> gitweb.factorcode.org Git - factor.git/blob - vm/jit.hpp
Merge Phil Dawes' VM work
[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         factorvm *myvm;
14
15         jit(cell jit_type, cell owner, factorvm *vm);
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(myvm->userenv[JIT_PUSH_IMMEDIATE],literal);
26         }
27
28         void word_jump(cell word) {
29                 literal(tag_fixnum(xt_tail_pic_offset));
30                 literal(word);
31                 emit(myvm->userenv[JIT_WORD_JUMP]);
32         }
33
34         void word_call(cell word) {
35                 emit_with(myvm->userenv[JIT_WORD_CALL],word);
36         }
37
38         void word_special(cell word) {
39                 emit_with(myvm->userenv[JIT_WORD_SPECIAL],word);
40         }
41
42         void emit_subprimitive(cell word_) {
43                 gc_root<word> word(word_,myvm);
44                 gc_root<array> code_template(word->subprimitive,myvm);
45                 if(array_capacity(code_template.untagged()) > 1) literal(myvm->T);
46                 emit(code_template.value());
47         }
48
49         void emit_class_lookup(fixnum index, cell type);
50
51         fixnum get_position() {
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                 if(computing_offset_p)
64                         position = position_;
65         }
66
67         
68         code_block *to_code_block();
69 };
70
71 }